setenv problems
Jeff Johnston
jjohnstn@redhat.com
Thu Sep 25 15:57:00 GMT 2008
Pawel Veselov wrote:
> Hi,
>
> [ skipped ]
>
>
>>> http://www.opengroup.org/onlinepubs/000095399/functions/setenv.html
>>> says that setenv() should fail with EINVAL if name contains an equal
>>> sign.
>>>
>> Ok, also considering the linux man pages state the same and the function
>> isn't specified by ANSI. Would you like to try your hand at a patch?
>>
>
> [ skipped ]
>
> Here is the patch, attached. Let me know if there are any questions/comments.
> Tested with this:
>
>
Thanks Pawel. Patch checked in.
-- Jeff J.
> #include <stdio.h>
> #include <stdlib.h>
> #include <errno.h>
>
> static char * _getenv(char *);
>
> char * _getenv(char * var) {
> char * aux = getenv(var);
> if (aux) { return aux; }
> return "(NULL)";
> }
>
> int main(int argc, char ** argv) {
> printf("getenv('nada' = %s\n", getenv("nada"));
> printf("getenv('TMP') = %s\n", getenv("TMP"));
> printf("getenv('TMP=XA') = %s\n", getenv("TMP=XA"));
> printf("setenv('PAWEL','DATA') = %d\n", setenv("PAWEL", "DATA", 1));
> printf("getenv('PAWEL') = %s\n", getenv("PAWEL"));
> errno = 0;
> printf("setenv('PAWE=L', 'DATA') = %d\n", setenv("PAWE=L", "DATA", 1));
> fflush(stdout);
> perror("setenv()");
> printf("setenv('LOOK','=FEEL') = %d\n", setenv("LOOK", "=FEEL", 1));
> printf("unsetenv('PAWEL') = %d\n", unsetenv("PAWEL"));
> printf("getenv('LOOK') = %s\n", getenv("LOOK"));
> printf("getenv('PAWEL') = %s\n", getenv("PAWEL"));
> printf("setenv('LOOK', 'JAM', nod) = %d\n", setenv("LOOK", "JAM", 0));
> printf("getenv('LOOK') = %s\n", getenv("LOOK"));
> printf("setenv('LOOK', 'MONKEY', od) = %d\n", setenv("LOOK", "MONKEY", 1));
> printf("getenv('LOOK') = %s\n", getenv("LOOK"));
>
> errno = 0;
> printf("unsetenv('=') = %d\n", unsetenv("="));
> perror("unsetenv()");
>
> errno = 0;
> printf("unsetenv('KARA') = %d\n", unsetenv("KARA"));
> perror("unsetenv()");
> return 0;
> }
>
>
>
More information about the Newlib
mailing list