Annotation of 43BSDReno/contrib/isode-beta/compat/putenv.c, revision 1.1.1.1

1.1       root        1: /* putenv.c - generic putenv() */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/compat/RCS/putenv.c,v 7.0 89/11/23 21:23:21 mrose Rel $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/compat/RCS/putenv.c,v 7.0 89/11/23 21:23:21 mrose Rel $
                      9:  *
                     10:  *
                     11:  * $Log:       putenv.c,v $
                     12:  * Revision 7.0  89/11/23  21:23:21  mrose
                     13:  * Release 6.0
                     14:  * 
                     15:  */
                     16: 
                     17: /*
                     18:  *                               NOTICE
                     19:  *
                     20:  *    Acquisition, use, and distribution of this module and related
                     21:  *    materials are subject to the restrictions of a license agreement.
                     22:  *    Consult the Preface in the User's Manual for the full terms of
                     23:  *    this agreement.
                     24:  *
                     25:  */
                     26: 
                     27: 
                     28: /* LINTLIBRARY */
                     29: 
                     30: #include <stdio.h>
                     31: #include "general.h"
                     32: #include "manifest.h"
                     33: 
                     34: /*  */
                     35: 
                     36: extern  char **environ;
                     37: 
                     38: /*  */
                     39: 
                     40: int     setenv (name, value)
                     41: register char  *name,
                     42:                *value;
                     43: {
                     44:     register int    i;
                     45:     register char **ep,
                     46:                   **nep,
                     47:                    *cp;
                     48: 
                     49:     if ((cp = malloc ((unsigned) (strlen (name) + strlen (value) + 2)))
                     50:            == NULL)
                     51:        return 1;
                     52:     (void) sprintf (cp, "%s=%s", name, value);
                     53: 
                     54:     for (ep = environ, i = 0; *ep; ep++, i++)
                     55:        if (nvmatch (name, *ep)) {
                     56:            *ep = cp;
                     57:            return 0;
                     58:        }
                     59: 
                     60:     if ((nep = (char **) malloc ((unsigned) ((i + 2) * sizeof *nep)))
                     61:            == NULL) {
                     62:        free (cp);
                     63:        return 1;
                     64:     }
                     65:     for (ep = environ, i = 0; *ep; nep[i++] = *ep++)
                     66:        continue;
                     67:     nep[i++] = cp;
                     68:     nep[i] = NULL;
                     69:     environ = nep;
                     70:     return 0;
                     71: }
                     72: 
                     73: /*  */
                     74: 
                     75: int    unsetenv (name)
                     76: char   *name;
                     77: {
                     78:     char  **ep,
                     79:           **nep;
                     80: 
                     81:     for (ep = environ; *ep; ep++)
                     82:        if (nvmatch (name, *ep))
                     83:            break;
                     84:     if (*ep == NULL)
                     85:        return 1;
                     86: 
                     87:     for (nep = ep + 1; *nep; nep++)
                     88:        continue;
                     89:     *ep = *--nep;
                     90:     *nep = NULL;
                     91:     return 0;
                     92: }
                     93: 
                     94: /*  */
                     95: 
                     96: static nvmatch (s1, s2)
                     97: register char  *s1,
                     98:                *s2;
                     99: {
                    100:     while (*s1 == *s2++)
                    101:        if (*s1++ == '=')
                    102:            return 1;
                    103: 
                    104:     return (*s1 == '\0' && *--s2 == '=');
                    105: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.