home *** CD-ROM | disk | FTP | other *** search
- /*
- * GETENV.C
- *
- * Lattice's screws up. Only part of lib when not compiled under DICE
- * which implements getenv() properly (even better) then this.
- *
- * (C) Copyright 1989-1990 by Matthew Dillon, All Rights Reserved.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "config.h"
-
- Prototype char *gettmpenv (const char *);
- Prototype char *getenv (const char *);
-
- #ifndef _DCC
-
- char *
- gettmpenv (const char *id)
- {
- static char
- *buf,
- *res = NULL;
- BPTR
- fh;
- int
- len;
-
- buf = malloc (strlen (id) + 8);
- sprintf (buf, "ENV:%s", id);
- fh = Open ((UBYTE *) buf, MODE_OLDFILE);
- free (buf);
- if (fh) {
- Seek (fh, 0L, OFFSET_END);
- len = Seek (fh, 0L, OFFSET_BEGINNING);
- if (len < 0) {
- Close (fh);
- return NULL;
- }
-
- if (res)
- free (res);
- res = malloc (len + 1);
- Read (fh, res, len);
- Close (fh);
- if (len > 0 && res [len - 1] == '\n')
- --len;
- res [len] = 0;
- return res;
- }
-
- return NULL;
- }
-
- char *
- getenv (const char *id)
- {
- char
- *res = gettmpenv (id),
- *perm = NULL;
-
- if (res)
- perm = strdup (res);
-
- return perm;
- }
-
- #endif
-