zsh-workers
 help / color / mirror / code / Atom feed
From: "Andrej Borsenkow" <Andrej.Borsenkow@mow.siemens.ru>
To: "ZSH workers mailing list" <zsh-workers@sunsite.auc.dk>
Subject: RE: PATCH: environment handling rewrite
Date: Thu, 3 Aug 2000 16:53:17 +0400	[thread overview]
Message-ID: <000b01bffd49$cb321440$21c9ca95@mow.siemens.ru> (raw)
In-Reply-To: <1000728163027.ZM9436@candle.brasslantern.com>

> 
> I would have preferred that putenv/getenv not have been defined as
> functions using those names, but rather that there was a new function
> named zputenv and that the body of the new getenv had been left in
> zgetenv; that is, put #ifdefs inside the bodies of zputenv/zgetenv.
> It's probably not a real issue because the #ifdef'd putenv/getenv are
> declared static, but in general it's best to avoid redeclaring symbols
> that some other library might also decide to redeclare.
> 
> Also, minor nit-pick, but I dislike the coding style of putting a space
> between a function's name and the opening paren of the parameter list.
> I won't repeat "hate" three times, but it's not consistent with the rest
> of the zsh style.
> 

O.K.

-andrej

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.24
diff -u -r1.24 params.c
--- Src/params.c        2000/07/28 09:10:37     1.24
+++ Src/params.c        2000/08/03 12:49:36
@@ -509,7 +509,7 @@
      * memory, so we can do mallocs and frees on it.               */
     envsize = sizeof(char *)*(1 + arrlen(environ));
     new_environ = (char **) zalloc(envsize);
-    memcpy (new_environ, environ, envsize);
+    memcpy(new_environ, environ, envsize);
     environ = new_environ;
 #endif
 
@@ -2849,18 +2849,20 @@
        pm->env = addenv(s, u, pm->flags);
 }
 
-#ifndef HAVE_PUTENV
 
 static int
-putenv(char *str)
+zputenv(char *str)
 {
+#ifdef HAVE_PUTENV
+    return putenv(str);
+#else
     char **ep;
     int num_env;
 
 
     /* First check if there is already an environment *
      * variable matching string `name'.               */
-    if (findenv (str, &num_env)) {
+    if (findenv(str, &num_env)) {
        environ[num_env] = str;
     } else {
     /* Else we have to make room and add it */
@@ -2873,35 +2875,19 @@
        *(ep + 1) = NULL;
     }
     return 0;
-}
 #endif
-
-#ifndef HAVE_GETENV
-
-static char *
-getenv(char *name)
-{
-    char **ep, *s, *t;
- 
-    for (ep = environ; *ep; ep++) {
-       for (s = *ep, t = name; *s && *s == *t; s++, t++);
-       if (*s == '=' && !*t)
-           return s + 1;
-    }
-    return NULL;
 }
-#endif
 
 /**/
 static int
-findenv (char *name, int *pos)
+findenv(char *name, int *pos)
 {
     char **ep, *eq;
     int  nlen;
 
 
-    eq = strchr (name, '=');
-    nlen = eq ? eq - name : strlen (name);
+    eq = strchr(name, '=');
+    nlen = eq ? eq - name : strlen(name);
     for (ep = environ; *ep; ep++) 
        if (!strncmp (*ep, name, nlen) && *((*ep)+nlen) == '=') {
            if (pos)
@@ -2919,7 +2905,18 @@
 mod_export char *
 zgetenv(char *name)
 {
+#ifdef HAVE_GETENV
     return getenv(name);
+#else
+    char **ep, *s, *t;
+ 
+    for (ep = environ; *ep; ep++) {
+       for (s = *ep, t = name; *s && *s == *t; s++, t++);
+       if (*s == '=' && !*t)
+           return s + 1;
+    }
+    return NULL;
+#endif
 }
 
 /**/
@@ -2945,14 +2942,14 @@
     /* First check if there is already an environment *
      * variable matching string `name'. If not, and   *
      * we are not requested to add new, return        */
-    if (findenv (name, &pos))
+    if (findenv(name, &pos))
        oldenv = environ[pos];
     else if (!add)
        return NULL;
 
-    newenv = mkenvstr (name, value, flags);
-    if (putenv (newenv)) {
-       zsfree (newenv);
+    newenv = mkenvstr(name, value, flags);
+    if (zputenv(newenv)) {
+       zsfree(newenv);
        return NULL;
     }
     /*
@@ -2961,12 +2958,12 @@
      * silently reuse exisiting environment string. This tries to
      * check for both cases
      */
-    if (findenv (name, &pos)) {
+    if (findenv(name, &pos)) {
        env = environ[pos];
        if (env != oldenv)
-           zsfree (oldenv);
+           zsfree(oldenv);
        if (env != newenv)
-           zsfree (newenv);
+           zsfree(newenv);
        return env;
     }
 
@@ -2980,7 +2977,7 @@
 replenv(char *name, char *value, int flags)
 {
 
-    return addenv_internal (name, value, flags, 0);
+    return addenv_internal(name, value, flags, 0);
 }
 
 /* Given strings *name = "foo", *value = "bar", *
@@ -3013,7 +3010,7 @@
 char *
 addenv(char *name, char *value, int flags)
 {
-    return addenv_internal (name, value, flags, 1);
+    return addenv_internal(name, value, flags, 1);
 }
 
 /* Delete a pointer from the list of pointers to environment *
 


      reply	other threads:[~2000-08-03 12:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-28  8:50 Andrej Borsenkow
2000-07-28  9:13 ` Peter Stephenson
2000-07-28 16:30 ` Bart Schaefer
2000-08-03 12:53   ` Andrej Borsenkow [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000b01bffd49$cb321440$21c9ca95@mow.siemens.ru' \
    --to=andrej.borsenkow@mow.siemens.ru \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).