syscgen.inc 763 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // general purpose unix routines for syscall based *nix system unit.
  2. {$ifndef FPC_USE_LIBC}
  3. Function fpgetenv(name:pchar):pchar;[public, alias : 'FPC_SYSC_FPGETENVPCHAR'];
  4. var
  5. p : ppchar;
  6. found : boolean;
  7. np,cp : pchar;
  8. len,i : longint;
  9. Begin
  10. if (name=nil) or (envp=NIL) Then
  11. exit(NIL);
  12. np:=name;
  13. while (np^<>#0) and (np^<>'=') DO
  14. inc(np);
  15. len:=np-name;
  16. p:=envp;
  17. while (p^<>NIL) DO
  18. Begin
  19. cp:=p^;
  20. np:=name;
  21. i:=len;
  22. while (i<>0) and (cp^<>#0) DO
  23. Begin
  24. if cp^<>np^ Then
  25. Begin
  26. inc(cp); inc(np);
  27. break;
  28. End;
  29. inc(cp); inc(np);
  30. dec(i)
  31. End;
  32. if (i=0) and (cp^='=') Then
  33. exit(cp+1);
  34. inc(p);
  35. end;
  36. fpgetenv:=nil;
  37. End;
  38. {$ENDIF}