~ubuntu-branches/ubuntu/maverick/bind9/maverick

« back to all changes in this revision

Viewing changes to lib/bind/bsd/setenv.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones, LaMont Jones, Internet Software Consortium, Inc, localization folks
  • Date: 2008-08-02 14:20:20 UTC
  • mfrom: (1.2.1 upstream) (6.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080802142020-l1hon9jy8lbbjxmg
[LaMont Jones]

* default to using resolvconf if it is installed
* fix sonames and dependencies.  Closes: #149259, #492418
* Do not build-depend libcap2-dev on non-linux.  Closes: #493392
* drop unused query-loc manpage.  Closes: #492564
* lwresd: Deliver /etc/bind directory.  Closes: #490027
* fix query-source comment in default install

[Internet Software Consortium, Inc]

* 9.5.0-P2.  Closes: #492949

[localization folks]

* l10n: Spanish debconf translation.  Closes: #492425 (Ignacio Mondino)
* l10n: Swedish debconf templates.  Closes: #491369 (Martin Ågren)
* l10n: Japanese debconf translations.  Closes: #492048 (Hideki Yamane
  (Debian-JP))
* l10n: Finnish translation.  Closes: #490630 (Esko Arajärvi)
* l10n: Italian debconf translations.  Closes: #492587 (Alessandro Vietta)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#if defined(LIBC_SCCS) && !defined(lint)
2
2
static const char sccsid[] = "@(#)setenv.c      8.1 (Berkeley) 6/4/93";
3
 
static const char rcsid[] = "$Id: setenv.c,v 1.1 2001/03/29 06:30:35 marka Exp $";
 
3
static const char rcsid[] = "$Id: setenv.c,v 1.2 2005/04/27 04:56:11 sra Exp $";
4
4
#endif /* LIBC_SCCS and not lint */
5
5
 
6
6
/*
52
52
 
53
53
static char *findenv(const char *name, int *offset);
54
54
 
55
 
/*
 
55
/*%
56
56
 * setenv --
57
57
 *      Set the value of the environmental variable "name" to be
58
58
 *      "value".  If rewrite is set, replace any current value.
59
59
 */
60
60
setenv(const char *name, const char *value, int rewrite) {
61
61
        extern char **environ;
62
 
        static int alloced;                     /* if allocated space before */
 
62
        static int alloced;                     /*%< if allocated space before */
63
63
        char *c;
64
64
        int l_value, offset;
65
65
 
66
 
        if (*value == '=')                      /* no `=' in value */
 
66
        if (*value == '=')                      /*%< no `=' in value */
67
67
                ++value;
68
68
        l_value = strlen(value);
69
 
        if ((c = findenv(name, &offset))) {     /* find if already exists */
 
69
        if ((c = findenv(name, &offset))) {     /*%< find if already exists */
70
70
                if (!rewrite)
71
71
                        return (0);
72
 
                if (strlen(c) >= l_value) {     /* old larger; copy over */
 
72
                if (strlen(c) >= l_value) {     /*%< old larger; copy over */
73
73
                        while (*c++ = *value++);
74
74
                        return (0);
75
75
                }
76
 
        } else {                                        /* create new slot */
 
76
        } else {                                        /*%< create new slot */
77
77
                int cnt;
78
78
                char **p;
79
79
 
80
80
                for (p = environ, cnt = 0; *p; ++p, ++cnt);
81
 
                if (alloced) {                  /* just increase size */
 
81
                if (alloced) {                  /*%< just increase size */
82
82
                        environ = (char **)realloc((char *)environ,
83
83
                            (size_t)(sizeof(char *) * (cnt + 2)));
84
84
                        if (!environ)
85
85
                                return (-1);
86
86
                }
87
 
                else {                          /* get new space */
88
 
                        alloced = 1;            /* copy old entries into it */
 
87
                else {                          /*%< get new space */
 
88
                        alloced = 1;            /*%< copy old entries into it */
89
89
                        p = malloc((size_t)(sizeof(char *) * (cnt + 2)));
90
90
                        if (!p)
91
91
                                return (-1);
95
95
                environ[cnt + 1] = NULL;
96
96
                offset = cnt;
97
97
        }
98
 
        for (c = (char *)name; *c && *c != '='; ++c);   /* no `=' in name */
99
 
        if (!(environ[offset] =                 /* name + `=' + value */
 
98
        for (c = (char *)name; *c && *c != '='; ++c);   /*%< no `=' in name */
 
99
        if (!(environ[offset] =                 /*%< name + `=' + value */
100
100
            malloc((size_t)((int)(c - name) + l_value + 2))))
101
101
                return (-1);
102
102
        for (c = environ[offset]; (*c = *name++) && *c != '='; ++c);
104
104
        return (0);
105
105
}
106
106
 
107
 
/*
 
107
/*%
108
108
 * unsetenv(name) --
109
109
 *      Delete environmental variable "name".
110
110
 */
113
113
        char **p;
114
114
        int offset;
115
115
 
116
 
        while (findenv(name, &offset))  /* if set multiple times */
 
116
        while (findenv(name, &offset))  /*%< if set multiple times */
117
117
                for (p = &environ[offset];; ++p)
118
118
                        if (!(*p = *(p + 1)))
119
119
                                break;
120
120
}
121
121
 
122
 
/*
 
122
/*%
123
123
 * findenv --
124
124
 *      Returns pointer to value associated with name, if any, else NULL.
125
125
 *      Sets offset to be the offset of the name/value combination in the
147
147
        return (NULL);
148
148
}
149
149
#endif
 
150
 
 
151
/*! \file */