hotplug2: replace udevtrigger from the udev-106 source with a much smaller self-conta...
[openwrt/svn-archive/archive.git] / package / ppp / patches / 402-use_uclibc_utils.patch
1 --- a/pppd/utils.c
2 +++ b/pppd/utils.c
3 @@ -30,6 +30,7 @@
4
5 #define RCSID "$Id: utils.c,v 1.24 2004/11/04 10:02:26 paulus Exp $"
6
7 +#define _BSD_SOURCE
8 #include <stdio.h>
9 #include <ctype.h>
10 #include <stdlib.h>
11 @@ -67,15 +68,10 @@ extern char *strerror();
12
13 static void logit __P((int, char *, va_list));
14 static void log_write __P((int, char *));
15 -static void vslp_printer __P((void *, char *, ...));
16 static void format_packet __P((u_char *, int, void (*) (void *, char *, ...),
17 void *));
18
19 -struct buffer_info {
20 - char *ptr;
21 - int len;
22 -};
23 -
24 +#ifndef __UCLIBC__
25 /*
26 * strlcpy - like strcpy/strncpy, doesn't overflow destination buffer,
27 * always leaves destination null-terminated (for len > 0).
28 @@ -113,6 +109,7 @@ strlcat(dest, src, len)
29
30 return dlen + strlcpy(dest + dlen, src, (len > dlen? len - dlen: 0));
31 }
32 +#endif
33
34
35 /*
36 @@ -129,17 +126,7 @@ slprintf __V((char *buf, int buflen, cha
37 va_list args;
38 int n;
39
40 -#if defined(__STDC__)
41 va_start(args, fmt);
42 -#else
43 - char *buf;
44 - int buflen;
45 - char *fmt;
46 - va_start(args);
47 - buf = va_arg(args, char *);
48 - buflen = va_arg(args, int);
49 - fmt = va_arg(args, char *);
50 -#endif
51 n = vslprintf(buf, buflen, fmt, args);
52 va_end(args);
53 return n;
54 @@ -148,7 +135,6 @@ slprintf __V((char *buf, int buflen, cha
55 /*
56 * vslprintf - like slprintf, takes a va_list instead of a list of args.
57 */
58 -#define OUTCHAR(c) (buflen > 0? (--buflen, *buf++ = (c)): 0)
59
60 int
61 vslprintf(buf, buflen, fmt, args)
62 @@ -157,298 +143,14 @@ vslprintf(buf, buflen, fmt, args)
63 char *fmt;
64 va_list args;
65 {
66 - int c, i, n;
67 - int width, prec, fillch;
68 - int base, len, neg, quoted;
69 - unsigned long val = 0;
70 - char *str, *f, *buf0;
71 - unsigned char *p;
72 - char num[32];
73 - time_t t;
74 - u_int32_t ip;
75 - static char hexchars[] = "0123456789abcdef";
76 - struct buffer_info bufinfo;
77 -
78 - buf0 = buf;
79 - --buflen;
80 - while (buflen > 0) {
81 - for (f = fmt; *f != '%' && *f != 0; ++f)
82 - ;
83 - if (f > fmt) {
84 - len = f - fmt;
85 - if (len > buflen)
86 - len = buflen;
87 - memcpy(buf, fmt, len);
88 - buf += len;
89 - buflen -= len;
90 - fmt = f;
91 - }
92 - if (*fmt == 0)
93 - break;
94 - c = *++fmt;
95 - width = 0;
96 - prec = -1;
97 - fillch = ' ';
98 - if (c == '0') {
99 - fillch = '0';
100 - c = *++fmt;
101 - }
102 - if (c == '*') {
103 - width = va_arg(args, int);
104 - c = *++fmt;
105 - } else {
106 - while (isdigit(c)) {
107 - width = width * 10 + c - '0';
108 - c = *++fmt;
109 - }
110 - }
111 - if (c == '.') {
112 - c = *++fmt;
113 - if (c == '*') {
114 - prec = va_arg(args, int);
115 - c = *++fmt;
116 - } else {
117 - prec = 0;
118 - while (isdigit(c)) {
119 - prec = prec * 10 + c - '0';
120 - c = *++fmt;
121 - }
122 - }
123 - }
124 - str = 0;
125 - base = 0;
126 - neg = 0;
127 - ++fmt;
128 - switch (c) {
129 - case 'l':
130 - c = *fmt++;
131 - switch (c) {
132 - case 'd':
133 - val = va_arg(args, long);
134 - if (val < 0) {
135 - neg = 1;
136 - val = -val;
137 - }
138 - base = 10;
139 - break;
140 - case 'u':
141 - val = va_arg(args, unsigned long);
142 - base = 10;
143 - break;
144 - default:
145 - *buf++ = '%'; --buflen;
146 - *buf++ = 'l'; --buflen;
147 - --fmt; /* so %lz outputs %lz etc. */
148 - continue;
149 - }
150 - break;
151 - case 'd':
152 - i = va_arg(args, int);
153 - if (i < 0) {
154 - neg = 1;
155 - val = -i;
156 - } else
157 - val = i;
158 - base = 10;
159 - break;
160 - case 'u':
161 - val = va_arg(args, unsigned int);
162 - base = 10;
163 - break;
164 - case 'o':
165 - val = va_arg(args, unsigned int);
166 - base = 8;
167 - break;
168 - case 'x':
169 - case 'X':
170 - val = va_arg(args, unsigned int);
171 - base = 16;
172 - break;
173 - case 'p':
174 - val = (unsigned long) va_arg(args, void *);
175 - base = 16;
176 - neg = 2;
177 - break;
178 - case 's':
179 - str = va_arg(args, char *);
180 - break;
181 - case 'c':
182 - num[0] = va_arg(args, int);
183 - num[1] = 0;
184 - str = num;
185 - break;
186 - case 'm':
187 - str = strerror(errno);
188 - break;
189 - case 'I':
190 - ip = va_arg(args, u_int32_t);
191 - ip = ntohl(ip);
192 - slprintf(num, sizeof(num), "%d.%d.%d.%d", (ip >> 24) & 0xff,
193 - (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
194 - str = num;
195 - break;
196 -#if 0 /* not used, and breaks on S/390, apparently */
197 - case 'r':
198 - f = va_arg(args, char *);
199 -#ifndef __powerpc__
200 - n = vslprintf(buf, buflen + 1, f, va_arg(args, va_list));
201 -#else
202 - /* On the powerpc, a va_list is an array of 1 structure */
203 - n = vslprintf(buf, buflen + 1, f, va_arg(args, void *));
204 -#endif
205 - buf += n;
206 - buflen -= n;
207 - continue;
208 -#endif
209 - case 't':
210 - time(&t);
211 - str = ctime(&t);
212 - str += 4; /* chop off the day name */
213 - str[15] = 0; /* chop off year and newline */
214 - break;
215 - case 'v': /* "visible" string */
216 - case 'q': /* quoted string */
217 - quoted = c == 'q';
218 - p = va_arg(args, unsigned char *);
219 - if (fillch == '0' && prec >= 0) {
220 - n = prec;
221 - } else {
222 - n = strlen((char *)p);
223 - if (prec >= 0 && n > prec)
224 - n = prec;
225 - }
226 - while (n > 0 && buflen > 0) {
227 - c = *p++;
228 - --n;
229 - if (!quoted && c >= 0x80) {
230 - OUTCHAR('M');
231 - OUTCHAR('-');
232 - c -= 0x80;
233 - }
234 - if (quoted && (c == '"' || c == '\\'))
235 - OUTCHAR('\\');
236 - if (c < 0x20 || (0x7f <= c && c < 0xa0)) {
237 - if (quoted) {
238 - OUTCHAR('\\');
239 - switch (c) {
240 - case '\t': OUTCHAR('t'); break;
241 - case '\n': OUTCHAR('n'); break;
242 - case '\b': OUTCHAR('b'); break;
243 - case '\f': OUTCHAR('f'); break;
244 - default:
245 - OUTCHAR('x');
246 - OUTCHAR(hexchars[c >> 4]);
247 - OUTCHAR(hexchars[c & 0xf]);
248 - }
249 - } else {
250 - if (c == '\t')
251 - OUTCHAR(c);
252 - else {
253 - OUTCHAR('^');
254 - OUTCHAR(c ^ 0x40);
255 - }
256 - }
257 - } else
258 - OUTCHAR(c);
259 - }
260 - continue;
261 - case 'P': /* print PPP packet */
262 - bufinfo.ptr = buf;
263 - bufinfo.len = buflen + 1;
264 - p = va_arg(args, unsigned char *);
265 - n = va_arg(args, int);
266 - format_packet(p, n, vslp_printer, &bufinfo);
267 - buf = bufinfo.ptr;
268 - buflen = bufinfo.len - 1;
269 - continue;
270 - case 'B':
271 - p = va_arg(args, unsigned char *);
272 - for (n = prec; n > 0; --n) {
273 - c = *p++;
274 - if (fillch == ' ')
275 - OUTCHAR(' ');
276 - OUTCHAR(hexchars[(c >> 4) & 0xf]);
277 - OUTCHAR(hexchars[c & 0xf]);
278 - }
279 - continue;
280 - default:
281 - *buf++ = '%';
282 - if (c != '%')
283 - --fmt; /* so %z outputs %z etc. */
284 - --buflen;
285 - continue;
286 - }
287 - if (base != 0) {
288 - str = num + sizeof(num);
289 - *--str = 0;
290 - while (str > num + neg) {
291 - *--str = hexchars[val % base];
292 - val = val / base;
293 - if (--prec <= 0 && val == 0)
294 - break;
295 - }
296 - switch (neg) {
297 - case 1:
298 - *--str = '-';
299 - break;
300 - case 2:
301 - *--str = 'x';
302 - *--str = '0';
303 - break;
304 - }
305 - len = num + sizeof(num) - 1 - str;
306 - } else {
307 - len = strlen(str);
308 - if (prec >= 0 && len > prec)
309 - len = prec;
310 - }
311 - if (width > 0) {
312 - if (width > buflen)
313 - width = buflen;
314 - if ((n = width - len) > 0) {
315 - buflen -= n;
316 - for (; n > 0; --n)
317 - *buf++ = fillch;
318 - }
319 - }
320 - if (len > buflen)
321 - len = buflen;
322 - memcpy(buf, str, len);
323 - buf += len;
324 - buflen -= len;
325 - }
326 - *buf = 0;
327 - return buf - buf0;
328 -}
329 + int ret;
330
331 -/*
332 - * vslp_printer - used in processing a %P format
333 - */
334 -static void
335 -vslp_printer __V((void *arg, char *fmt, ...))
336 -{
337 - int n;
338 - va_list pvar;
339 - struct buffer_info *bi;
340 -
341 -#if defined(__STDC__)
342 - va_start(pvar, fmt);
343 -#else
344 - void *arg;
345 - char *fmt;
346 - va_start(pvar);
347 - arg = va_arg(pvar, void *);
348 - fmt = va_arg(pvar, char *);
349 -#endif
350 -
351 - bi = (struct buffer_info *) arg;
352 - n = vslprintf(bi->ptr, bi->len, fmt, pvar);
353 - va_end(pvar);
354 -
355 - bi->ptr += n;
356 - bi->len -= n;
357 + ret = vsnprintf(buf, buflen, fmt, args);
358 + buf[buflen - 1] = 0;
359 + return ret;
360 }
361
362 +
363 #ifdef unused
364 /*
365 * log_packet - format a packet and log it.