move the defines to the resource header and include that where necessary.
[AROS.git] / compiler / posixc / getenv.c
blobd20a6b2ec35536db3aa4fe132b23c72767f7b0e0
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function getenv().
6 */
8 #include <proto/exec.h>
9 #include <proto/dos.h>
11 #include "__env.h"
13 /*****************************************************************************
15 NAME */
16 #include <stdlib.h>
18 char *getenv (
20 /* SYNOPSIS */
21 const char *name)
23 /* FUNCTION
24 Get an environment variable.
26 INPUTS
27 name - Name of the environment variable.
29 RESULT
30 Pointer to the variable's value, or NULL on failure.
32 NOTES
33 The returned contents of the environment variable is cached per
34 PosixCBase and per variable name. So the returned value is valid
35 and does not change until a next call to getenv with the same
36 PosixCBase and the same name.
38 EXAMPLE
40 BUGS
42 SEE ALSO
44 INTERNALS
45 Based on libnix getenv
47 ******************************************************************************/
49 __env_item *var = NULL;
50 char c;
53 This will always return 0 if the var exists and EOF if it doesn't,
54 then we'll be able to retrieve the var length with IoErr()
56 if (!GetVar((char *)name, &c, 1, GVF_BINARY_VAR))
58 LONG len = IoErr();
60 var = __env_getvar(name, len+1); /* size == len + null-byte. */
62 if (var)
64 /* This should not fail, unless someone stole our variable */
65 /* FIXME: maybe this function should be atomic? */
66 GetVar((char *)name, var->value, len+1, GVF_BINARY_VAR);
70 return (var?var->value:NULL);
71 } /* getenv */