Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2008-09-25 05:23:08 +0400
committerJeff Johnston <jjohnstn@redhat.com>2008-09-25 05:23:08 +0400
commit37f996a2b22baba8cc6ee7df87f72df25de36737 (patch)
tree84c4a264075efe260eca78cae9950ca26f66c178 /newlib/libc/stdlib/setenv_r.c
parent62470d09ad879ff2516a520944d5c7349a2aa85f (diff)
2008-09-24 Pawel Veselov <pawel.veselov@gmail.com>
Fix setenv/getenv/unsetenv to be OpenGroup compliant: * libc/include/stdlib.h (unsetenv, _unsetenv_r): Redefine with integer return types. * libc/stdlib/getenv_r.c (_findenv_r): Do no special processing with names that contain equal chars. * libc/stdlib/setenv.c: Redefine _unsetenv_r as returning int. * libc/stdlib/setenv_r.c (_setenv_r): Return -1 and set errno to EINVAL if name contains an equal sign. Do not remove any equal signs from the value. (_unsetenv_r): Modified to return int. Return -1 and set EINVAL if name contains equal sign. Return -1 if no variable(s) were found and return 0 otherwise.
Diffstat (limited to 'newlib/libc/stdlib/setenv_r.c')
-rw-r--r--newlib/libc/stdlib/setenv_r.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/newlib/libc/stdlib/setenv_r.c b/newlib/libc/stdlib/setenv_r.c
index 694bd14a9..e9ae76ef5 100644
--- a/newlib/libc/stdlib/setenv_r.c
+++ b/newlib/libc/stdlib/setenv_r.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <errno.h>
#include "envlock.h"
extern char **environ;
@@ -43,6 +44,8 @@ extern char *_findenv_r _PARAMS ((struct _reent *, const char *, int *));
* _setenv_r --
* Set the value of the environmental variable "name" to be
* "value". If rewrite is set, replace any current value.
+ * If "name" contains equal sign, -1 is returned, and errno is
+ * set to EINVAL;
*/
int
@@ -56,10 +59,14 @@ _DEFUN (_setenv_r, (reent_ptr, name, value, rewrite),
register char *C;
int l_value, offset;
+ if (strchr(name, '='))
+ {
+ errno = EINVAL;
+ return -1;
+ }
+
ENV_LOCK;
- if (*value == '=') /* no `=' in value */
- ++value;
l_value = strlen (value);
if ((C = _findenv_r (reent_ptr, name, &offset)))
{ /* find if already exists */
@@ -132,20 +139,33 @@ _DEFUN (_setenv_r, (reent_ptr, name, value, rewrite),
* _unsetenv_r(name) --
* Delete environmental variable "name".
*/
-void
+int
_DEFUN (_unsetenv_r, (reent_ptr, name),
struct _reent *reent_ptr _AND
_CONST char *name)
{
register char **P;
int offset;
+ int rc;
+
+ if (strchr(name, '='))
+ {
+ errno = EINVAL;
+ return -1;
+ }
ENV_LOCK;
+ rc = -1;
+
while (_findenv_r (reent_ptr, name, &offset)) /* if set multiple times */
- for (P = &(*p_environ)[offset];; ++P)
- if (!(*P = *(P + 1)))
- break;
+ {
+ rc = 0;
+ for (P = &(*p_environ)[offset];; ++P)
+ if (!(*P = *(P + 1)))
+ break;
+ }
ENV_UNLOCK;
+ return (rc);
}