setenv problems
Pawel Veselov
pawel.veselov@gmail.com
Thu Sep 25 01:25:00 GMT 2008
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:
#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;
}
--
With best of best regards
Pawel S. Veselov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 8a.diff
Type: text/x-patch
Size: 5504 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20080925/7157c4ad/attachment.bin>
More information about the Newlib
mailing list