getenv.c 509 B

1234567891011121314151617181920212223242526
  1. /* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
  2. * This file is part of the Linux-8086 C library and is distributed
  3. * under the GNU Library General Public License.
  4. */
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <unistd.h>
  8. #include <malloc.h>
  9. char *getenv(var)
  10. const char *var;
  11. {
  12. char **p;
  13. int len;
  14. len = strlen(var);
  15. if (!__environ)
  16. return 0;
  17. for (p = __environ; *p; p++) {
  18. if (memcmp(var, *p, len) == 0 && (*p)[len] == '=')
  19. return *p + len + 1;
  20. }
  21. return 0;
  22. }