home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-1.LHA / CLISP960530-sr.lha / amiga / jchlib / misc / getenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-09  |  628 b   |  27 lines

  1. /* Tiny GCC Library
  2.  * Jörg Höhle, 12-Jun-96
  3.  */
  4.  
  5. #include <exec/types.h>
  6. #include <dos/dosextens.h>
  7. #include <dos/var.h>
  8.  
  9. #include <proto/dos.h>
  10.  
  11. #define GETENV_MAX_LENGTH 256    /* won't handle values longer than this */
  12.  
  13. static char getenv_static_buf[GETENV_MAX_LENGTH];
  14.  
  15. char *getenv(const char *name)
  16. {
  17.   LONG len;
  18.   extern struct DosLibrary * const DOSBase;
  19.  
  20. #ifdef SUPPORT_1_3
  21.   if (DOSBase->dl_lib.lib_Version < 36) return NULL; /* TODO add it for 1.3 */
  22. #endif
  23.   len =  GetVar(name, getenv_static_buf, GETENV_MAX_LENGTH, LV_VAR);
  24.   return (len >= 0 && len == IoErr() /* not truncated */)
  25.     ? getenv_static_buf : NULL;
  26. }
  27.