update mappings to reflect recent changes
[AROS.git] / compiler / clib / getenv.c
blob8fef5e0becce9e3dac68f2f7f47b2475fe66888b
1 /*
2 Copyright © 1995-2012, 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 This function must not be used in a shared library.
35 EXAMPLE
37 BUGS
39 SEE ALSO
41 INTERNALS
42 Based on libnix getenv
44 ******************************************************************************/
46 __env_item *var = NULL;
47 char c;
50 This will always return 0 if the var exists and EOF if it doesn't,
51 then we'll be able to retrieve the var lenght with IoErr()
53 if (!GetVar((char *)name, &c, 1, GVF_BINARY_VAR))
55 LONG len = IoErr();
57 var = __env_getvar(name, len+1); /* size == len + null-byte. */
59 if (var)
61 /*This should not fail, unless someone stealt our variable*/
62 /* FIXME: maybe this function should be atomic? */
63 GetVar((char *)name, var->value, len+1, GVF_BINARY_VAR);
67 return (var?var->value:NULL);
68 } /* getenv */