getenv.c 531 B

12345678910111213141516171819202122232425
  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(const char *var)
  10. {
  11. char **p;
  12. int len;
  13. len = strlen(var);
  14. if (!__environ)
  15. return NULL;
  16. for (p = __environ; *p; p++) {
  17. if (memcmp(var, *p, len) == 0 && (*p)[len] == '=')
  18. return *p + len + 1;
  19. }
  20. return NULL;
  21. }