home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / gcc / libnixV0_8.lha / gnu / libnix-sources.lha / sources / nix / stdlib / getenv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  581 b   |  26 lines

  1. #include <stdlib.h>
  2. #include <dos/dos.h>
  3. #include <dos/var.h>
  4. #ifdef __GNUC__
  5. #include <inline/dos.h>
  6. #endif
  7.  
  8. char *getenv(const char *name)
  9. { static char *var=NULL;
  10.   size_t len,i=0;
  11.   do
  12.   { i+=256;
  13.     if(var!=NULL) /* free old buffer */
  14.       free(var);
  15.     var=malloc(i); /* and get a new one */
  16.     if(var==NULL) /* Oh, dear */
  17.       return NULL;
  18.     len=GetVar((char *)name,var,i,GVF_BINARY_VAR)+1;
  19.   }while(len>=i); /* just to be sure we got everything, we _require_ 1 unused byte */
  20.   if(len==0) /* Variable doesn't exist */
  21.     return NULL;
  22.   else
  23.     return var;
  24. }
  25.     
  26.