home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / mkid_448.lzh / Mkid / src / amiga_getenv.c next >
C/C++ Source or Header  |  1991-02-01  |  877b  |  51 lines

  1. /*
  2.  * Written by Randell Jesup, Commodore-Amiga Inc.
  3.  * This routine is in the public domain.
  4.  * It should be rewritten to use GetVar() when running under 2.0.
  5.  *
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <libraries/dos.h>
  10. #include <dos.h>
  11. #ifdef LATTICE
  12. #include <proto/exec.h>
  13. #include <proto/dos.h>
  14. #endif
  15.  
  16. char *
  17. getenv(str)
  18.     char *str;
  19. {
  20.     register char *dest = NULL;
  21.     register LONG len,newlen;
  22.     register BPTR envfh;
  23.     BPTR lock;
  24.  
  25.     lock = Lock("ENV:",SHARED_LOCK);
  26.     if (!lock)
  27.         return NULL;
  28.  
  29.     lock = CurrentDir(lock);
  30.     if (envfh = Open(str,MODE_OLDFILE))
  31.     {
  32.         /* find end of file */
  33.         Seek(envfh,0,OFFSET_END);
  34.         len = Seek(envfh,0,OFFSET_BEGINNING);
  35.  
  36.         if (len >= 0 && (dest = (char *) malloc(len+1)))
  37.         {
  38.             newlen = Read(envfh,dest,len);
  39.             if (newlen >= 0)
  40.             {
  41.                 dest[newlen] = '\0';
  42.             }
  43.         }
  44.         Close(envfh);
  45.     }
  46.     lock = CurrentDir(lock);
  47.     UnLock(lock);
  48.  
  49.     return dest;
  50. }
  51.