home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-18.59-src.tgz / emacs-18.59-src.tar / fsf / emacs18 / amiga / unix / src / getenv.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  621b  |  32 lines

  1. #include "amiga.h"
  2. #include <string.h>
  3.  
  4. /* This getenv removes trailing newlines & multiple calls don't
  5.    destroy results */
  6. char *getenv (const char *varname)
  7. {
  8.   char *return_string;
  9.   char buf[64];
  10.  
  11.   chkabort();
  12.   if (varname && varname[0])
  13.     {
  14.       int len, size;
  15.  
  16.       len = GetVar(varname, buf, 64, LV_VAR);
  17.       if (len >= 0)
  18.     {
  19.       size = IoErr();
  20.       return_string = malloc(size + 1);
  21.       if (!return_string) return 0;
  22.       if (size != len)
  23.         {
  24.           if (GetVar(varname, return_string, size + 1, LV_VAR) > 0)
  25.         return return_string;
  26.         }
  27.       else return strcpy(return_string, buf);
  28.     }
  29.     }
  30.   return 0;
  31. }
  32.