posixunx.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2002 by Marco van de Voort.
  5. A few general purpose routines. General purpose enough for *BSD
  6. and Linux at least.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. Function sys_getenv(const name:pchar):pchar;
  14. var
  15. p : ppchar;
  16. found : boolean;
  17. np,cp : pchar;
  18. len,i : longint;
  19. Begin
  20. if (name=nil) or (envp=NIL) Then
  21. exit(NIL);
  22. np:=name;
  23. while (np^<>#0) and (np^<>'=') DO
  24. inc(np);
  25. len:=np-name;
  26. p:=envp;
  27. while (p^<>NIL) DO
  28. Begin
  29. cp:=p^;
  30. np:=name;
  31. i:=len;
  32. while (i<>0) and (cp^<>#0) DO
  33. Begin
  34. if cp^<>np^ Then
  35. Begin
  36. inc(cp); inc(np);
  37. break;
  38. End;
  39. inc(cp); inc(np);
  40. dec(i)
  41. End;
  42. if (i=0) and (cp^='=') Then
  43. exit(cp+1);
  44. inc(p);
  45. end;
  46. End;
  47. Function sys_getenv(name:string):Pchar;
  48. {
  49. Searches the environment for a string with name p and
  50. returns a pchar to it's value.
  51. A pchar is used to accomodate for strings of length > 255
  52. }
  53. Begin
  54. name:=name+'='; {Else HOST will also find HOSTNAME, etc}
  55. sys_getenv:=sys_getenv(@name[1]);
  56. end;
  57. {
  58. $Log$
  59. Revision 1.1 2002-10-27 13:16:54 marco
  60. * Routines that certainly will be shared between Linux and *BSD
  61. }