diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 6 | ||||
-rw-r--r-- | lib/error.c | 207 | ||||
-rw-r--r-- | lib/error.h | 36 | ||||
-rw-r--r-- | lib/error.m4 | 19 | ||||
-rw-r--r-- | lib/exit.h | 32 | ||||
-rw-r--r-- | lib/exitfail.c | 27 | ||||
-rw-r--r-- | lib/exitfail.h | 20 | ||||
-rw-r--r-- | lib/fsusage.c | 57 | ||||
-rw-r--r-- | lib/fsusage.h | 14 | ||||
-rw-r--r-- | lib/fsusage.m4 | 53 | ||||
-rw-r--r-- | lib/full-read.h | 24 | ||||
-rw-r--r-- | lib/getloadavg.c | 166 | ||||
-rw-r--r-- | lib/getopt.c | 144 | ||||
-rw-r--r-- | lib/getopt.h | 52 | ||||
-rw-r--r-- | lib/getopt1.c | 61 | ||||
-rw-r--r-- | lib/gettext.h | 17 | ||||
-rw-r--r-- | lib/ls-mntd-fs.m4 | 44 | ||||
-rw-r--r-- | lib/malloc.c | 6 | ||||
-rw-r--r-- | lib/mountlist.c | 213 | ||||
-rw-r--r-- | lib/mountlist.h | 33 | ||||
-rw-r--r-- | lib/onceonly.m4 | 63 | ||||
-rw-r--r-- | lib/realloc.c | 13 | ||||
-rw-r--r-- | lib/snprintf.c | 133 | ||||
-rw-r--r-- | lib/strtod.c | 21 | ||||
-rw-r--r-- | lib/unlocked-io.h | 66 | ||||
-rw-r--r-- | lib/unlocked-io.m4 | 22 | ||||
-rw-r--r-- | lib/xalloc.h | 88 | ||||
-rw-r--r-- | lib/xalloc.m4 | 32 | ||||
-rw-r--r-- | lib/xmalloc.c | 210 | ||||
-rw-r--r-- | lib/xstrdup.c | 33 |
30 files changed, 1121 insertions, 791 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 7b07f555..2e9aeee9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -2,7 +2,8 @@ | |||
2 | 2 | ||
3 | noinst_LIBRARIES = libnagiosplug.a | 3 | noinst_LIBRARIES = libnagiosplug.a |
4 | 4 | ||
5 | libnagiosplug_a_SOURCES = getopt.c getopt1.c snprintf.c fsusage.c mountlist.c xmalloc.c | 5 | libnagiosplug_a_SOURCES = getopt.c getopt1.c fsusage.c snprintf.c mountlist.c \ |
6 | xmalloc.c xstrdup.c exitfail.c | ||
6 | 7 | ||
7 | libnagiosplug_a_LIBADD = @LIBOBJS@ | 8 | libnagiosplug_a_LIBADD = @LIBOBJS@ |
8 | libnagiosplug_a_DEPENDENCIES = $(libnagiosplug_a_LIBADD) | 9 | libnagiosplug_a_DEPENDENCIES = $(libnagiosplug_a_LIBADD) |
@@ -12,6 +13,7 @@ EXTRA_DIST = ulonglong.m4 codeset.m4 getloadavg.m4 gettext.m4 glibc21.m4 iconv.m | |||
12 | inttypes.m4 inttypes_h.m4 inttypes-pri.m4 isc-posix.m4 lcmessage.m4 lib-ld.m4 \ | 13 | inttypes.m4 inttypes_h.m4 inttypes-pri.m4 isc-posix.m4 lcmessage.m4 lib-ld.m4 \ |
13 | lib-link.m4 lib-prefix.m4 progtest.m4 stdint_h.m4 uintmax_t.m4 afs.m4 \ | 14 | lib-link.m4 lib-prefix.m4 progtest.m4 stdint_h.m4 uintmax_t.m4 afs.m4 \ |
14 | fstypename.m4 fsusage.m4 ls-mntd-fs.m4 getopt.h gettext.h fsusage.h mountlist.h\ | 15 | fstypename.m4 fsusage.m4 ls-mntd-fs.m4 getopt.h gettext.h fsusage.h mountlist.h\ |
15 | error.m4 error.h error.c getloadavg.c xalloc.h unlocked-io.h malloc.c realloc.c strtod.c | 16 | error.m4 error.h error.c getloadavg.c xalloc.h unlocked-io.h unlocked-io.m4 malloc.c \ |
17 | onceonly.m4 realloc.c strtod.c exitfail.h full-read.h xstrdup.c xalloc.m4 exit.h | ||
16 | 18 | ||
17 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/intl | 19 | INCLUDES = -I$(srcdir) -I$(top_srcdir)/intl |
diff --git a/lib/error.c b/lib/error.c index 2296124a..1149235a 100644 --- a/lib/error.c +++ b/lib/error.c | |||
@@ -1,5 +1,7 @@ | |||
1 | /* Error handler for noninteractive utilities | 1 | /* Error handler for noninteractive utilities |
2 | Copyright (C) 1990-1998, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. | 2 | Copyright (C) 1990-1998, 2000-2002, 2003 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | ||
4 | |||
3 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; either version 2, or (at your option) | 7 | the Free Software Foundation; either version 2, or (at your option) |
@@ -20,7 +22,12 @@ | |||
20 | # include <config.h> | 22 | # include <config.h> |
21 | #endif | 23 | #endif |
22 | 24 | ||
25 | #include "error.h" | ||
26 | |||
27 | #include <stdarg.h> | ||
23 | #include <stdio.h> | 28 | #include <stdio.h> |
29 | #include <stdlib.h> | ||
30 | #include <string.h> | ||
24 | 31 | ||
25 | #ifdef _LIBC | 32 | #ifdef _LIBC |
26 | # include <libintl.h> | 33 | # include <libintl.h> |
@@ -33,28 +40,6 @@ | |||
33 | # define mbsrtowcs __mbsrtowcs | 40 | # define mbsrtowcs __mbsrtowcs |
34 | #endif | 41 | #endif |
35 | 42 | ||
36 | #if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC | ||
37 | # if __STDC__ | ||
38 | # include <stdarg.h> | ||
39 | # define VA_START(args, lastarg) va_start(args, lastarg) | ||
40 | # else | ||
41 | # include <varargs.h> | ||
42 | # define VA_START(args, lastarg) va_start(args) | ||
43 | # endif | ||
44 | #else | ||
45 | # define va_alist a1, a2, a3, a4, a5, a6, a7, a8 | ||
46 | # define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; | ||
47 | #endif | ||
48 | |||
49 | #if STDC_HEADERS || _LIBC | ||
50 | # include <stdlib.h> | ||
51 | # include <string.h> | ||
52 | #else | ||
53 | void exit (); | ||
54 | #endif | ||
55 | |||
56 | #include "error.h" | ||
57 | |||
58 | #if !_LIBC | 43 | #if !_LIBC |
59 | # include "unlocked-io.h" | 44 | # include "unlocked-io.h" |
60 | #endif | 45 | #endif |
@@ -66,11 +51,7 @@ void exit (); | |||
66 | /* If NULL, error will flush stdout, then print on stderr the program | 51 | /* If NULL, error will flush stdout, then print on stderr the program |
67 | name, a colon and a space. Otherwise, error will call this | 52 | name, a colon and a space. Otherwise, error will call this |
68 | function without parameters instead. */ | 53 | function without parameters instead. */ |
69 | void (*error_print_progname) ( | 54 | void (*error_print_progname) (void); |
70 | #if __STDC__ - 0 | ||
71 | void | ||
72 | #endif | ||
73 | ); | ||
74 | 55 | ||
75 | /* This variable is incremented each time `error' is called. */ | 56 | /* This variable is incremented each time `error' is called. */ |
76 | unsigned int error_message_count; | 57 | unsigned int error_message_count; |
@@ -98,6 +79,8 @@ extern void __error_at_line (int status, int errnum, const char *file_name, | |||
98 | # undef putc | 79 | # undef putc |
99 | # define putc(c, fp) INTUSE(_IO_putc) (c, fp) | 80 | # define putc(c, fp) INTUSE(_IO_putc) (c, fp) |
100 | 81 | ||
82 | # include <bits/libc-lock.h> | ||
83 | |||
101 | #else /* not _LIBC */ | 84 | #else /* not _LIBC */ |
102 | 85 | ||
103 | # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P | 86 | # if !HAVE_DECL_STRERROR_R && STRERROR_R_CHAR_P |
@@ -107,34 +90,17 @@ extern void __error_at_line (int status, int errnum, const char *file_name, | |||
107 | char *strerror_r (); | 90 | char *strerror_r (); |
108 | # endif | 91 | # endif |
109 | 92 | ||
93 | # ifndef SIZE_MAX | ||
94 | # define SIZE_MAX ((size_t) -1) | ||
95 | # endif | ||
96 | |||
110 | /* The calling program should define program_name and set it to the | 97 | /* The calling program should define program_name and set it to the |
111 | name of the executing program. */ | 98 | name of the executing program. */ |
112 | extern char *progname; | 99 | extern char *program_name; |
113 | 100 | ||
114 | # if HAVE_STRERROR_R || defined strerror_r | 101 | # if HAVE_STRERROR_R || defined strerror_r |
115 | # define __strerror_r strerror_r | 102 | # define __strerror_r strerror_r |
116 | # else | 103 | # endif |
117 | # if HAVE_STRERROR | ||
118 | # ifndef HAVE_DECL_STRERROR | ||
119 | "this configure-time declaration test was not run" | ||
120 | # endif | ||
121 | # if !HAVE_DECL_STRERROR | ||
122 | char *strerror (); | ||
123 | # endif | ||
124 | # else | ||
125 | static char * | ||
126 | private_strerror (int errnum) | ||
127 | { | ||
128 | extern char *sys_errlist[]; | ||
129 | extern int sys_nerr; | ||
130 | |||
131 | if (errnum > 0 && errnum <= sys_nerr) | ||
132 | return _(sys_errlist[errnum]); | ||
133 | return _("Unknown system error"); | ||
134 | } | ||
135 | # define strerror private_strerror | ||
136 | # endif /* HAVE_STRERROR */ | ||
137 | # endif /* HAVE_STRERROR_R || defined strerror_r */ | ||
138 | #endif /* not _LIBC */ | 104 | #endif /* not _LIBC */ |
139 | 105 | ||
140 | static void | 106 | static void |
@@ -172,93 +138,70 @@ print_errno_message (int errnum) | |||
172 | fprintf (stderr, ": %s", s); | 138 | fprintf (stderr, ": %s", s); |
173 | } | 139 | } |
174 | 140 | ||
175 | #ifdef VA_START | ||
176 | static void | 141 | static void |
177 | error_tail (int status, int errnum, const char *message, va_list args) | 142 | error_tail (int status, int errnum, const char *message, va_list args) |
178 | { | 143 | { |
179 | # if HAVE_VPRINTF || _LIBC | 144 | #if _LIBC |
180 | # if _LIBC | ||
181 | if (_IO_fwide (stderr, 0) > 0) | 145 | if (_IO_fwide (stderr, 0) > 0) |
182 | { | 146 | { |
183 | # define ALLOCA_LIMIT 2000 | 147 | # define ALLOCA_LIMIT 2000 |
184 | size_t len = strlen (message) + 1; | 148 | size_t len = strlen (message) + 1; |
185 | wchar_t *wmessage = NULL; | 149 | const wchar_t *wmessage = L"out of memory"; |
186 | mbstate_t st; | 150 | wchar_t *wbuf = (len < ALLOCA_LIMIT |
187 | size_t res; | 151 | ? alloca (len * sizeof *wbuf) |
188 | const char *tmp; | 152 | : len <= SIZE_MAX / sizeof *wbuf |
189 | 153 | ? malloc (len * sizeof *wbuf) | |
190 | do | 154 | : NULL); |
155 | |||
156 | if (wbuf) | ||
191 | { | 157 | { |
192 | if (len < ALLOCA_LIMIT) | 158 | size_t res; |
193 | wmessage = (wchar_t *) alloca (len * sizeof (wchar_t)); | 159 | mbstate_t st; |
194 | else | 160 | const char *tmp = message; |
195 | { | ||
196 | if (wmessage != NULL && len / 2 < ALLOCA_LIMIT) | ||
197 | wmessage = NULL; | ||
198 | |||
199 | wmessage = (wchar_t *) realloc (wmessage, | ||
200 | len * sizeof (wchar_t)); | ||
201 | |||
202 | if (wmessage == NULL) | ||
203 | { | ||
204 | fputws_unlocked (L"out of memory\n", stderr); | ||
205 | return; | ||
206 | } | ||
207 | } | ||
208 | |||
209 | memset (&st, '\0', sizeof (st)); | 161 | memset (&st, '\0', sizeof (st)); |
210 | tmp =message; | 162 | res = mbsrtowcs (wbuf, &tmp, len, &st); |
163 | wmessage = res == (size_t) -1 ? L"???" : wbuf; | ||
211 | } | 164 | } |
212 | while ((res = mbsrtowcs (wmessage, &tmp, len, &st)) == len); | ||
213 | |||
214 | if (res == (size_t) -1) | ||
215 | /* The string cannot be converted. */ | ||
216 | wmessage = (wchar_t *) L"???"; | ||
217 | 165 | ||
218 | __vfwprintf (stderr, wmessage, args); | 166 | __vfwprintf (stderr, wmessage, args); |
167 | if (! (len < ALLOCA_LIMIT)) | ||
168 | free (wbuf); | ||
219 | } | 169 | } |
220 | else | 170 | else |
221 | # endif | 171 | #endif |
222 | vfprintf (stderr, message, args); | 172 | vfprintf (stderr, message, args); |
223 | # else | ||
224 | _doprnt (message, args, stderr); | ||
225 | # endif | ||
226 | va_end (args); | 173 | va_end (args); |
227 | 174 | ||
228 | ++error_message_count; | 175 | ++error_message_count; |
229 | if (errnum) | 176 | if (errnum) |
230 | print_errno_message (errnum); | 177 | print_errno_message (errnum); |
231 | # if _LIBC | 178 | #if _LIBC |
232 | if (_IO_fwide (stderr, 0) > 0) | 179 | if (_IO_fwide (stderr, 0) > 0) |
233 | putwc (L'\n', stderr); | 180 | putwc (L'\n', stderr); |
234 | else | 181 | else |
235 | # endif | 182 | #endif |
236 | putc ('\n', stderr); | 183 | putc ('\n', stderr); |
237 | fflush (stderr); | 184 | fflush (stderr); |
238 | if (status) | 185 | if (status) |
239 | exit (status); | 186 | exit (status); |
240 | } | 187 | } |
241 | #endif | ||
242 | 188 | ||
243 | 189 | ||
244 | /* Print the program name and error message MESSAGE, which is a printf-style | 190 | /* Print the program name and error message MESSAGE, which is a printf-style |
245 | format string with optional args. | 191 | format string with optional args. |
246 | If ERRNUM is nonzero, print its corresponding system error message. | 192 | If ERRNUM is nonzero, print its corresponding system error message. |
247 | Exit with status STATUS if it is nonzero. */ | 193 | Exit with status STATUS if it is nonzero. */ |
248 | /* VARARGS */ | ||
249 | void | 194 | void |
250 | #if defined VA_START && __STDC__ | ||
251 | error (int status, int errnum, const char *message, ...) | 195 | error (int status, int errnum, const char *message, ...) |
252 | #else | ||
253 | error (status, errnum, message, va_alist) | ||
254 | int status; | ||
255 | int errnum; | ||
256 | char *message; | ||
257 | va_dcl | ||
258 | #endif | ||
259 | { | 196 | { |
260 | #ifdef VA_START | ||
261 | va_list args; | 197 | va_list args; |
198 | |||
199 | #if defined _LIBC && defined __libc_ptf_call | ||
200 | /* We do not want this call to be cut short by a thread | ||
201 | cancellation. Therefore disable cancellation for now. */ | ||
202 | int state = PTHREAD_CANCEL_ENABLE; | ||
203 | __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), | ||
204 | 0); | ||
262 | #endif | 205 | #endif |
263 | 206 | ||
264 | fflush (stdout); | 207 | fflush (stdout); |
@@ -271,29 +214,20 @@ error (status, errnum, message, va_alist) | |||
271 | { | 214 | { |
272 | #if _LIBC | 215 | #if _LIBC |
273 | if (_IO_fwide (stderr, 0) > 0) | 216 | if (_IO_fwide (stderr, 0) > 0) |
274 | __fwprintf (stderr, L"%s: ", progname); | 217 | __fwprintf (stderr, L"%s: ", program_name); |
275 | else | 218 | else |
276 | #endif | 219 | #endif |
277 | fprintf (stderr, "%s: ", progname); | 220 | fprintf (stderr, "%s: ", program_name); |
278 | } | 221 | } |
279 | 222 | ||
280 | #ifdef VA_START | 223 | va_start (args, message); |
281 | VA_START (args, message); | ||
282 | error_tail (status, errnum, message, args); | 224 | error_tail (status, errnum, message, args); |
283 | #else | ||
284 | fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); | ||
285 | |||
286 | ++error_message_count; | ||
287 | if (errnum) | ||
288 | print_errno_message (errnum); | ||
289 | putc ('\n', stderr); | ||
290 | fflush (stderr); | ||
291 | if (status) | ||
292 | exit (status); | ||
293 | #endif | ||
294 | 225 | ||
295 | #ifdef _LIBC | 226 | #ifdef _LIBC |
296 | _IO_funlockfile (stderr); | 227 | _IO_funlockfile (stderr); |
228 | # ifdef __libc_ptf_call | ||
229 | __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); | ||
230 | # endif | ||
297 | #endif | 231 | #endif |
298 | } | 232 | } |
299 | 233 | ||
@@ -302,22 +236,10 @@ error (status, errnum, message, va_alist) | |||
302 | int error_one_per_line; | 236 | int error_one_per_line; |
303 | 237 | ||
304 | void | 238 | void |
305 | #if defined VA_START && __STDC__ | ||
306 | error_at_line (int status, int errnum, const char *file_name, | 239 | error_at_line (int status, int errnum, const char *file_name, |
307 | unsigned int line_number, const char *message, ...) | 240 | unsigned int line_number, const char *message, ...) |
308 | #else | ||
309 | error_at_line (status, errnum, file_name, line_number, message, va_alist) | ||
310 | int status; | ||
311 | int errnum; | ||
312 | const char *file_name; | ||
313 | unsigned int line_number; | ||
314 | char *message; | ||
315 | va_dcl | ||
316 | #endif | ||
317 | { | 241 | { |
318 | #ifdef VA_START | ||
319 | va_list args; | 242 | va_list args; |
320 | #endif | ||
321 | 243 | ||
322 | if (error_one_per_line) | 244 | if (error_one_per_line) |
323 | { | 245 | { |
@@ -334,6 +256,14 @@ error_at_line (status, errnum, file_name, line_number, message, va_alist) | |||
334 | old_line_number = line_number; | 256 | old_line_number = line_number; |
335 | } | 257 | } |
336 | 258 | ||
259 | #if defined _LIBC && defined __libc_ptf_call | ||
260 | /* We do not want this call to be cut short by a thread | ||
261 | cancellation. Therefore disable cancellation for now. */ | ||
262 | int state = PTHREAD_CANCEL_ENABLE; | ||
263 | __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state), | ||
264 | 0); | ||
265 | #endif | ||
266 | |||
337 | fflush (stdout); | 267 | fflush (stdout); |
338 | #ifdef _LIBC | 268 | #ifdef _LIBC |
339 | _IO_flockfile (stderr); | 269 | _IO_flockfile (stderr); |
@@ -344,10 +274,10 @@ error_at_line (status, errnum, file_name, line_number, message, va_alist) | |||
344 | { | 274 | { |
345 | #if _LIBC | 275 | #if _LIBC |
346 | if (_IO_fwide (stderr, 0) > 0) | 276 | if (_IO_fwide (stderr, 0) > 0) |
347 | __fwprintf (stderr, L"%s: ", progname); | 277 | __fwprintf (stderr, L"%s: ", program_name); |
348 | else | 278 | else |
349 | #endif | 279 | #endif |
350 | fprintf (stderr, "%s:", progname); | 280 | fprintf (stderr, "%s:", program_name); |
351 | } | 281 | } |
352 | 282 | ||
353 | if (file_name != NULL) | 283 | if (file_name != NULL) |
@@ -360,23 +290,14 @@ error_at_line (status, errnum, file_name, line_number, message, va_alist) | |||
360 | fprintf (stderr, "%s:%d: ", file_name, line_number); | 290 | fprintf (stderr, "%s:%d: ", file_name, line_number); |
361 | } | 291 | } |
362 | 292 | ||
363 | #ifdef VA_START | 293 | va_start (args, message); |
364 | VA_START (args, message); | ||
365 | error_tail (status, errnum, message, args); | 294 | error_tail (status, errnum, message, args); |
366 | #else | ||
367 | fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8); | ||
368 | |||
369 | ++error_message_count; | ||
370 | if (errnum) | ||
371 | print_errno_message (errnum); | ||
372 | putc ('\n', stderr); | ||
373 | fflush (stderr); | ||
374 | if (status) | ||
375 | exit (status); | ||
376 | #endif | ||
377 | 295 | ||
378 | #ifdef _LIBC | 296 | #ifdef _LIBC |
379 | _IO_funlockfile (stderr); | 297 | _IO_funlockfile (stderr); |
298 | # ifdef __libc_ptf_call | ||
299 | __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0); | ||
300 | # endif | ||
380 | #endif | 301 | #endif |
381 | } | 302 | } |
382 | 303 | ||
diff --git a/lib/error.h b/lib/error.h index 177b2dcb..8ed63595 100644 --- a/lib/error.h +++ b/lib/error.h | |||
@@ -1,24 +1,20 @@ | |||
1 | /* Declaration for error-reporting function | 1 | /* Declaration for error-reporting function |
2 | Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. | 2 | Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. | ||
3 | 4 | ||
4 | 5 | This program is free software; you can redistribute it and/or modify | |
5 | NOTE: The canonical source of this file is maintained with the GNU C Library. | 6 | it under the terms of the GNU General Public License as published by |
6 | Bugs can be reported to bug-glibc@prep.ai.mit.edu. | 7 | the Free Software Foundation; either version 2, or (at your option) |
7 | 8 | any later version. | |
8 | This program is free software; you can redistribute it and/or modify it | ||
9 | under the terms of the GNU General Public License as published by the | ||
10 | Free Software Foundation; either version 2, or (at your option) any | ||
11 | later version. | ||
12 | 9 | ||
13 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
17 | 14 | ||
18 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License along |
19 | along with this program; if not, write to the Free Software | 16 | with this program; if not, write to the Free Software Foundation, |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | 17 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
21 | USA. */ | ||
22 | 18 | ||
23 | #ifndef _ERROR_H | 19 | #ifndef _ERROR_H |
24 | #define _ERROR_H 1 | 20 | #define _ERROR_H 1 |
@@ -40,17 +36,15 @@ | |||
40 | extern "C" { | 36 | extern "C" { |
41 | #endif | 37 | #endif |
42 | 38 | ||
43 | #if defined (__STDC__) && __STDC__ | ||
44 | |||
45 | /* Print a message with `fprintf (stderr, FORMAT, ...)'; | 39 | /* Print a message with `fprintf (stderr, FORMAT, ...)'; |
46 | if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). | 40 | if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). |
47 | If STATUS is nonzero, terminate the program with `exit (STATUS)'. */ | 41 | If STATUS is nonzero, terminate the program with `exit (STATUS)'. */ |
48 | 42 | ||
49 | extern void error (int status, int errnum, const char *format, ...) | 43 | extern void error (int __status, int __errnum, const char *__format, ...) |
50 | __attribute__ ((__format__ (__printf__, 3, 4))); | 44 | __attribute__ ((__format__ (__printf__, 3, 4))); |
51 | 45 | ||
52 | extern void error_at_line (int status, int errnum, const char *fname, | 46 | extern void error_at_line (int __status, int __errnum, const char *__fname, |
53 | unsigned int lineno, const char *format, ...) | 47 | unsigned int __lineno, const char *__format, ...) |
54 | __attribute__ ((__format__ (__printf__, 5, 6))); | 48 | __attribute__ ((__format__ (__printf__, 5, 6))); |
55 | 49 | ||
56 | /* If NULL, error will flush stdout, then print on stderr the program | 50 | /* If NULL, error will flush stdout, then print on stderr the program |
@@ -58,12 +52,6 @@ extern void error_at_line (int status, int errnum, const char *fname, | |||
58 | function without parameters instead. */ | 52 | function without parameters instead. */ |
59 | extern void (*error_print_progname) (void); | 53 | extern void (*error_print_progname) (void); |
60 | 54 | ||
61 | #else | ||
62 | void error (); | ||
63 | void error_at_line (); | ||
64 | extern void (*error_print_progname) (); | ||
65 | #endif | ||
66 | |||
67 | /* This variable is incremented each time `error' is called. */ | 55 | /* This variable is incremented each time `error' is called. */ |
68 | extern unsigned int error_message_count; | 56 | extern unsigned int error_message_count; |
69 | 57 | ||
diff --git a/lib/error.m4 b/lib/error.m4 index 717725d6..0bc2e689 100644 --- a/lib/error.m4 +++ b/lib/error.m4 | |||
@@ -1,14 +1,15 @@ | |||
1 | #serial 5 | 1 | #serial 9 |
2 | 2 | ||
3 | dnl FIXME: put these prerequisite-only *.m4 files in a separate | 3 | AC_DEFUN([gl_ERROR], |
4 | dnl directory -- otherwise, they'll conflict with existing files. | 4 | [ |
5 | AC_FUNC_ERROR_AT_LINE | ||
6 | dnl Note: AC_FUNC_ERROR_AT_LINE does AC_LIBSOURCES([error.h, error.c]). | ||
7 | jm_PREREQ_ERROR | ||
8 | ]) | ||
5 | 9 | ||
6 | dnl These are the prerequisite macros for GNU's error.c file. | 10 | # Prerequisites of lib/error.c. |
7 | AC_DEFUN([jm_PREREQ_ERROR], | 11 | AC_DEFUN([jm_PREREQ_ERROR], |
8 | [ | 12 | [ |
9 | AC_CHECK_FUNCS(strerror vprintf doprnt) | 13 | AC_REQUIRE([AC_FUNC_STRERROR_R]) |
10 | AC_CHECK_DECLS([strerror]) | 14 | : |
11 | AC_CHECK_HEADERS([libintl.h]) | ||
12 | AC_FUNC_STRERROR_R | ||
13 | AC_HEADER_STDC | ||
14 | ]) | 15 | ]) |
diff --git a/lib/exit.h b/lib/exit.h new file mode 100644 index 00000000..4e8d4651 --- /dev/null +++ b/lib/exit.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* exit() function. | ||
2 | Copyright (C) 1995, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
17 | |||
18 | #ifndef _EXIT_H | ||
19 | #define _EXIT_H | ||
20 | |||
21 | /* Get exit() declaration. */ | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* Some systems do not define EXIT_*, even with STDC_HEADERS. */ | ||
25 | #ifndef EXIT_SUCCESS | ||
26 | # define EXIT_SUCCESS 0 | ||
27 | #endif | ||
28 | #ifndef EXIT_FAILURE | ||
29 | # define EXIT_FAILURE 1 | ||
30 | #endif | ||
31 | |||
32 | #endif /* _EXIT_H */ | ||
diff --git a/lib/exitfail.c b/lib/exitfail.c new file mode 100644 index 00000000..2ae5f695 --- /dev/null +++ b/lib/exitfail.c | |||
@@ -0,0 +1,27 @@ | |||
1 | /* Failure exit status | ||
2 | |||
3 | Copyright (C) 2002, 2003 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; see the file COPYING. | ||
17 | If not, write to the Free Software Foundation, | ||
18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
19 | |||
20 | #if HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include "exitfail.h" | ||
25 | #include "exit.h" | ||
26 | |||
27 | int volatile exit_failure = EXIT_FAILURE; | ||
diff --git a/lib/exitfail.h b/lib/exitfail.h new file mode 100644 index 00000000..cf5ab719 --- /dev/null +++ b/lib/exitfail.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /* Failure exit status | ||
2 | |||
3 | Copyright (C) 2002 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; see the file COPYING. | ||
17 | If not, write to the Free Software Foundation, | ||
18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
19 | |||
20 | extern int volatile exit_failure; | ||
diff --git a/lib/fsusage.c b/lib/fsusage.c index 7339c805..d9260293 100644 --- a/lib/fsusage.c +++ b/lib/fsusage.c | |||
@@ -1,5 +1,7 @@ | |||
1 | /* fsusage.c -- return space usage of mounted filesystems | 1 | /* fsusage.c -- return space usage of mounted filesystems |
2 | Copyright (C) 1991, 1992, 1996, 1998, 1999 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003 Free | ||
4 | Software Foundation, Inc. | ||
3 | 5 | ||
4 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -15,23 +17,26 @@ | |||
15 | along with this program; if not, write to the Free Software Foundation, | 17 | along with this program; if not, write to the Free Software Foundation, |
16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | 18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 | 19 | ||
18 | #include "config.h" | 20 | #if HAVE_CONFIG_H |
21 | # include <config.h> | ||
22 | #endif | ||
19 | 23 | ||
20 | #if HAVE_INTTYPES_H | 24 | #if HAVE_INTTYPES_H |
21 | # include <inttypes.h> | 25 | # include <inttypes.h> |
26 | #else | ||
27 | # if HAVE_STDINT_H | ||
28 | # include <stdint.h> | ||
29 | # endif | ||
22 | #endif | 30 | #endif |
31 | #ifndef UINTMAX_MAX | ||
32 | # define UINTMAX_MAX ((uintmax_t) -1) | ||
33 | #endif | ||
34 | |||
23 | #include <sys/types.h> | 35 | #include <sys/types.h> |
24 | #include <sys/stat.h> | 36 | #include <sys/stat.h> |
25 | #include "fsusage.h" | 37 | #include "fsusage.h" |
26 | 38 | ||
27 | #if HAVE_LIMITS_H | 39 | #include <limits.h> |
28 | # include <limits.h> | ||
29 | #endif | ||
30 | #ifndef CHAR_BIT | ||
31 | # define CHAR_BIT 8 | ||
32 | #endif | ||
33 | |||
34 | int statfs (); | ||
35 | 40 | ||
36 | #if HAVE_SYS_PARAM_H | 41 | #if HAVE_SYS_PARAM_H |
37 | # include <sys/param.h> | 42 | # include <sys/param.h> |
@@ -49,7 +54,7 @@ int statfs (); | |||
49 | # include <sys/fs/s5param.h> | 54 | # include <sys/fs/s5param.h> |
50 | #endif | 55 | #endif |
51 | 56 | ||
52 | #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY) | 57 | #if defined HAVE_SYS_FILSYS_H && !defined _CRAY |
53 | # include <sys/filsys.h> /* SVR2 */ | 58 | # include <sys/filsys.h> /* SVR2 */ |
54 | #endif | 59 | #endif |
55 | 60 | ||
@@ -70,11 +75,18 @@ int statfs (); | |||
70 | int statvfs (); | 75 | int statvfs (); |
71 | #endif | 76 | #endif |
72 | 77 | ||
78 | #include "full-read.h" | ||
79 | |||
73 | /* Many space usage primitives use all 1 bits to denote a value that is | 80 | /* Many space usage primitives use all 1 bits to denote a value that is |
74 | not applicable or unknown. Propagate this information by returning | 81 | not applicable or unknown. Propagate this information by returning |
75 | a uintmax_t value that is all 1 bits if the argument is all 1 bits, | 82 | a uintmax_t value that is all 1 bits if X is all 1 bits, even if X |
76 | even if the argument is unsigned and smaller than uintmax_t. */ | 83 | is unsigned and narrower than uintmax_t. */ |
77 | #define PROPAGATE_ALL_ONES(x) ((x) == -1 ? (uintmax_t) -1 : (uintmax_t) (x)) | 84 | #define PROPAGATE_ALL_ONES(x) \ |
85 | ((sizeof (x) < sizeof (uintmax_t) \ | ||
86 | && (~ (x) == (sizeof (x) < sizeof (int) \ | ||
87 | ? - (1 << (sizeof (x) * CHAR_BIT)) \ | ||
88 | : 0))) \ | ||
89 | ? UINTMAX_MAX : (x)) | ||
78 | 90 | ||
79 | /* Extract the top bit of X as an uintmax_t value. */ | 91 | /* Extract the top bit of X as an uintmax_t value. */ |
80 | #define EXTRACT_TOP_BIT(x) ((x) \ | 92 | #define EXTRACT_TOP_BIT(x) ((x) \ |
@@ -89,8 +101,6 @@ int statvfs (); | |||
89 | otherwise, use PROPAGATE_ALL_ONES. */ | 101 | otherwise, use PROPAGATE_ALL_ONES. */ |
90 | #define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1)) | 102 | #define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1)) |
91 | 103 | ||
92 | int safe_read (); | ||
93 | |||
94 | /* Fill in the fields of FSP with information about space usage for | 104 | /* Fill in the fields of FSP with information about space usage for |
95 | the filesystem on which PATH resides. | 105 | the filesystem on which PATH resides. |
96 | DISK is the device on which PATH is mounted, for space-getting | 106 | DISK is the device on which PATH is mounted, for space-getting |
@@ -147,7 +157,7 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp) | |||
147 | if (fd < 0) | 157 | if (fd < 0) |
148 | return -1; | 158 | return -1; |
149 | lseek (fd, (off_t) SUPERBOFF, 0); | 159 | lseek (fd, (off_t) SUPERBOFF, 0); |
150 | if (safe_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd) | 160 | if (full_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd) |
151 | { | 161 | { |
152 | close (fd); | 162 | close (fd); |
153 | return -1; | 163 | return -1; |
@@ -160,7 +170,7 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp) | |||
160 | fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree); | 170 | fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree); |
161 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0; | 171 | fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0; |
162 | fsp->fsu_files = (fsd.s_isize == -1 | 172 | fsp->fsu_files = (fsd.s_isize == -1 |
163 | ? (uintmax_t) -1 | 173 | ? UINTMAX_MAX |
164 | : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); | 174 | : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); |
165 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); | 175 | fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); |
166 | 176 | ||
@@ -217,7 +227,7 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp) | |||
217 | /* Empirically, the block counts on most SVR3 and SVR3-derived | 227 | /* Empirically, the block counts on most SVR3 and SVR3-derived |
218 | systems seem to always be in terms of 512-byte blocks, | 228 | systems seem to always be in terms of 512-byte blocks, |
219 | no matter what value f_bsize has. */ | 229 | no matter what value f_bsize has. */ |
220 | # if _AIX || defined(_CRAY) | 230 | # if _AIX || defined _CRAY |
221 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize); | 231 | fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize); |
222 | # else | 232 | # else |
223 | fsp->fsu_blocksize = 512; | 233 | fsp->fsu_blocksize = 512; |
@@ -233,12 +243,13 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp) | |||
233 | return -1; | 243 | return -1; |
234 | 244 | ||
235 | /* f_frsize isn't guaranteed to be supported. */ | 245 | /* f_frsize isn't guaranteed to be supported. */ |
236 | fsp->fsu_blocksize = | 246 | fsp->fsu_blocksize = (fsd.f_frsize |
237 | PROPAGATE_ALL_ONES (fsd.f_frsize ? fsd.f_frsize : fsd.f_bsize); | 247 | ? PROPAGATE_ALL_ONES (fsd.f_frsize) |
248 | : PROPAGATE_ALL_ONES (fsd.f_bsize)); | ||
238 | 249 | ||
239 | #endif /* STAT_STATVFS */ | 250 | #endif /* STAT_STATVFS */ |
240 | 251 | ||
241 | #if !defined(STAT_STATFS2_FS_DATA) && !defined(STAT_READ_FILSYS) | 252 | #if !defined STAT_STATFS2_FS_DATA && !defined STAT_READ_FILSYS |
242 | /* !Ultrix && !SVR2 */ | 253 | /* !Ultrix && !SVR2 */ |
243 | 254 | ||
244 | fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks); | 255 | fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks); |
@@ -253,7 +264,7 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp) | |||
253 | return 0; | 264 | return 0; |
254 | } | 265 | } |
255 | 266 | ||
256 | #if defined(_AIX) && defined(_I386) | 267 | #if defined _AIX && defined _I386 |
257 | /* AIX PS/2 does not supply statfs. */ | 268 | /* AIX PS/2 does not supply statfs. */ |
258 | 269 | ||
259 | int | 270 | int |
diff --git a/lib/fsusage.h b/lib/fsusage.h index e0c0db58..e2cbbf12 100644 --- a/lib/fsusage.h +++ b/lib/fsusage.h | |||
@@ -1,5 +1,6 @@ | |||
1 | /* fsusage.h -- declarations for filesystem space usage info | 1 | /* fsusage.h -- declarations for filesystem space usage info |
2 | Copyright (C) 1991, 1992, 1997 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 1991, 1992, 1997, 2003 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
@@ -31,15 +32,6 @@ struct fs_usage | |||
31 | uintmax_t fsu_ffree; /* Free file nodes. */ | 32 | uintmax_t fsu_ffree; /* Free file nodes. */ |
32 | }; | 33 | }; |
33 | 34 | ||
34 | # ifndef PARAMS | 35 | int get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp); |
35 | # if defined PROTOTYPES || (defined __STDC__ && __STDC__) | ||
36 | # define PARAMS(Args) Args | ||
37 | # else | ||
38 | # define PARAMS(Args) () | ||
39 | # endif | ||
40 | # endif | ||
41 | |||
42 | int get_fs_usage PARAMS ((const char *path, const char *disk, | ||
43 | struct fs_usage *fsp)); | ||
44 | 36 | ||
45 | #endif | 37 | #endif |
diff --git a/lib/fsusage.m4 b/lib/fsusage.m4 index 85d0fc8f..a0ab1e15 100644 --- a/lib/fsusage.m4 +++ b/lib/fsusage.m4 | |||
@@ -1,7 +1,18 @@ | |||
1 | #serial 9 | 1 | #serial 11 |
2 | 2 | ||
3 | # From fileutils/configure.in | 3 | # From fileutils/configure.in |
4 | 4 | ||
5 | AC_DEFUN([gl_FSUSAGE], | ||
6 | [ | ||
7 | AC_CHECK_HEADERS_ONCE(sys/param.h) | ||
8 | AC_CHECK_HEADERS(sys/mount.h sys/vfs.h sys/fs_types.h) | ||
9 | jm_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no]) | ||
10 | if test $gl_cv_fs_space = yes; then | ||
11 | AC_LIBOBJ(fsusage) | ||
12 | gl_PREREQ_FSUSAGE_EXTRA | ||
13 | fi | ||
14 | ]) | ||
15 | |||
5 | # Try to determine how a program can obtain filesystem usage information. | 16 | # Try to determine how a program can obtain filesystem usage information. |
6 | # If successful, define the appropriate symbol (see fsusage.c) and | 17 | # If successful, define the appropriate symbol (see fsusage.c) and |
7 | # execute ACTION-IF-FOUND. Otherwise, execute ACTION-IF-NOT-FOUND. | 18 | # execute ACTION-IF-FOUND. Otherwise, execute ACTION-IF-NOT-FOUND. |
@@ -193,7 +204,43 @@ if test $ac_fsusage_space = no; then | |||
193 | ac_fsusage_space=yes) | 204 | ac_fsusage_space=yes) |
194 | fi | 205 | fi |
195 | 206 | ||
196 | dnl AS_IF([test $ac_fsusage_space = yes], [$1], [$2]) | 207 | AS_IF([test $ac_fsusage_space = yes], [$1], [$2]) |
197 | if test $ac_fsusage_space = yes ; then [$1] ; else [$2] ; fi | ||
198 | 208 | ||
199 | ]) | 209 | ]) |
210 | |||
211 | |||
212 | # Check for SunOS statfs brokenness wrt partitions 2GB and larger. | ||
213 | # If <sys/vfs.h> exists and struct statfs has a member named f_spare, | ||
214 | # enable the work-around code in fsusage.c. | ||
215 | AC_DEFUN([jm_STATFS_TRUNCATES], | ||
216 | [ | ||
217 | AC_MSG_CHECKING([for statfs that truncates block counts]) | ||
218 | AC_CACHE_VAL(fu_cv_sys_truncating_statfs, | ||
219 | [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | ||
220 | #if !defined(sun) && !defined(__sun) | ||
221 | choke -- this is a workaround for a Sun-specific problem | ||
222 | #endif | ||
223 | #include <sys/types.h> | ||
224 | #include <sys/vfs.h>]], | ||
225 | [[struct statfs t; long c = *(t.f_spare);]])], | ||
226 | [fu_cv_sys_truncating_statfs=yes], | ||
227 | [fu_cv_sys_truncating_statfs=no])]) | ||
228 | if test $fu_cv_sys_truncating_statfs = yes; then | ||
229 | AC_DEFINE(STATFS_TRUNCATES_BLOCK_COUNTS, 1, | ||
230 | [Define if the block counts reported by statfs may be truncated to 2GB | ||
231 | and the correct values may be stored in the f_spare array. | ||
232 | (SunOS 4.1.2, 4.1.3, and 4.1.3_U1 are reported to have this problem. | ||
233 | SunOS 4.1.1 seems not to be affected.)]) | ||
234 | fi | ||
235 | AC_MSG_RESULT($fu_cv_sys_truncating_statfs) | ||
236 | ]) | ||
237 | |||
238 | |||
239 | # Prerequisites of lib/fsusage.c not done by jm_FILE_SYSTEM_USAGE. | ||
240 | AC_DEFUN([gl_PREREQ_FSUSAGE_EXTRA], | ||
241 | [ | ||
242 | AC_REQUIRE([jm_AC_TYPE_UINTMAX_T]) | ||
243 | AC_CHECK_HEADERS_ONCE(fcntl.h) | ||
244 | AC_CHECK_HEADERS(dustat.h sys/fs/s5param.h sys/filsys.h sys/statfs.h sys/statvfs.h) | ||
245 | jm_STATFS_TRUNCATES | ||
246 | ]) | ||
diff --git a/lib/full-read.h b/lib/full-read.h new file mode 100644 index 00000000..71f19a3b --- /dev/null +++ b/lib/full-read.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* An interface to read() that reads all it is asked to read. | ||
2 | |||
3 | Copyright (C) 2002 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, read to the Free Software Foundation, | ||
17 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
18 | |||
19 | #include <stddef.h> | ||
20 | |||
21 | /* Read COUNT bytes at BUF to descriptor FD, retrying if interrupted | ||
22 | or if partial reads occur. Return the number of bytes successfully | ||
23 | read, setting errno if that is less than COUNT. errno = 0 means EOF. */ | ||
24 | extern size_t full_read (int fd, void *buf, size_t count); | ||
diff --git a/lib/getloadavg.c b/lib/getloadavg.c index e9c4c088..c6b6fee1 100644 --- a/lib/getloadavg.c +++ b/lib/getloadavg.c | |||
@@ -1,6 +1,10 @@ | |||
1 | /* Get the system load averages. | 1 | /* Get the system load averages. |
2 | Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995, 1997 | 2 | |
3 | Free Software Foundation, Inc. | 3 | Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, |
4 | 1995, 1997, 1999, 2000, 2003, 2004 Free Software Foundation, Inc. | ||
5 | |||
6 | NOTE: The canonical source of this file is maintained with gnulib. | ||
7 | Bugs can be reported to bug-gnulib@gnu.org. | ||
4 | 8 | ||
5 | This program is free software; you can redistribute it and/or modify | 9 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 10 | it under the terms of the GNU General Public License as published by |
@@ -35,12 +39,17 @@ | |||
35 | LOAD_AVE_TYPE Type of the load average array in the kernel. | 39 | LOAD_AVE_TYPE Type of the load average array in the kernel. |
36 | Must be defined unless one of | 40 | Must be defined unless one of |
37 | apollo, DGUX, NeXT, or UMAX is defined; | 41 | apollo, DGUX, NeXT, or UMAX is defined; |
42 | or we have libkstat; | ||
38 | otherwise, no load average is available. | 43 | otherwise, no load average is available. |
44 | HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults | ||
45 | to this. | ||
39 | NLIST_STRUCT Include nlist.h, not a.out.h, and | 46 | NLIST_STRUCT Include nlist.h, not a.out.h, and |
40 | the nlist n_name element is a pointer, | 47 | the nlist n_name element is a pointer, |
41 | not an array. | 48 | not an array. |
42 | NLIST_NAME_UNION struct nlist has an n_un member, not n_name. | 49 | HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'. |
43 | LINUX_LDAV_FILE [__linux__]: File containing load averages. | 50 | LINUX_LDAV_FILE [__linux__]: File containing load averages. |
51 | HAVE_LOCALE_H locale.h is available. | ||
52 | HAVE_SETLOCALE The `setlocale' function is available. | ||
44 | 53 | ||
45 | Specific system predefines this file uses, aside from setting | 54 | Specific system predefines this file uses, aside from setting |
46 | default values if not emacs: | 55 | default values if not emacs: |
@@ -62,7 +71,7 @@ | |||
62 | VMS | 71 | VMS |
63 | WINDOWS32 No-op for Windows95/NT. | 72 | WINDOWS32 No-op for Windows95/NT. |
64 | __linux__ Linux: assumes /proc filesystem mounted. | 73 | __linux__ Linux: assumes /proc filesystem mounted. |
65 | Support from Michael K. Johnson. | 74 | Support from Michael K. Johnson. |
66 | __NetBSD__ NetBSD: assumes /kern filesystem mounted. | 75 | __NetBSD__ NetBSD: assumes /kern filesystem mounted. |
67 | 76 | ||
68 | In addition, to avoid nesting many #ifdefs, we internally set | 77 | In addition, to avoid nesting many #ifdefs, we internally set |
@@ -81,7 +90,7 @@ | |||
81 | /* Both the Emacs and non-Emacs sections want this. Some | 90 | /* Both the Emacs and non-Emacs sections want this. Some |
82 | configuration files' definitions for the LOAD_AVE_CVT macro (like | 91 | configuration files' definitions for the LOAD_AVE_CVT macro (like |
83 | sparc.h's) use macros like FSCALE, defined here. */ | 92 | sparc.h's) use macros like FSCALE, defined here. */ |
84 | #ifdef unix | 93 | #if defined (unix) || defined (__unix) |
85 | # include <sys/param.h> | 94 | # include <sys/param.h> |
86 | #endif | 95 | #endif |
87 | 96 | ||
@@ -98,13 +107,15 @@ | |||
98 | extern int errno; | 107 | extern int errno; |
99 | #endif | 108 | #endif |
100 | 109 | ||
101 | #if HAVE_LOCALE_H | 110 | #ifdef HAVE_LOCALE_H |
102 | # include <locale.h> | 111 | # include <locale.h> |
103 | #endif | 112 | #endif |
104 | #if !HAVE_SETLOCALE | 113 | #ifndef HAVE_SETLOCALE |
105 | # define setlocale(Category, Locale) /* empty */ | 114 | # define setlocale(Category, Locale) /* empty */ |
106 | #endif | 115 | #endif |
107 | 116 | ||
117 | #include "cloexec.h" | ||
118 | |||
108 | #ifndef HAVE_GETLOADAVG | 119 | #ifndef HAVE_GETLOADAVG |
109 | 120 | ||
110 | /* The existing Emacs configuration files define a macro called | 121 | /* The existing Emacs configuration files define a macro called |
@@ -117,7 +128,7 @@ extern int errno; | |||
117 | LOAD_AVE_CVT, but future machine config files should just define | 128 | LOAD_AVE_CVT, but future machine config files should just define |
118 | LDAV_CVT directly. */ | 129 | LDAV_CVT directly. */ |
119 | 130 | ||
120 | # if !defined(LDAV_CVT) && defined(LOAD_AVE_CVT) | 131 | # if !defined (LDAV_CVT) && defined (LOAD_AVE_CVT) |
121 | # define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0) | 132 | # define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0) |
122 | # endif | 133 | # endif |
123 | 134 | ||
@@ -137,6 +148,12 @@ extern int errno; | |||
137 | # undef FSCALE | 148 | # undef FSCALE |
138 | # endif | 149 | # endif |
139 | 150 | ||
151 | /* Same issues as for NeXT apply to the HURD-based GNU system. */ | ||
152 | # ifdef __GNU__ | ||
153 | # undef BSD | ||
154 | # undef FSCALE | ||
155 | # endif /* __GNU__ */ | ||
156 | |||
140 | /* Set values that are different from the defaults, which are | 157 | /* Set values that are different from the defaults, which are |
141 | set a little farther down with #ifndef. */ | 158 | set a little farther down with #ifndef. */ |
142 | 159 | ||
@@ -155,11 +172,11 @@ extern int errno; | |||
155 | # define sun | 172 | # define sun |
156 | # endif | 173 | # endif |
157 | 174 | ||
158 | # if defined(hp300) && !defined(hpux) | 175 | # if defined (hp300) && !defined (hpux) |
159 | # define MORE_BSD | 176 | # define MORE_BSD |
160 | # endif | 177 | # endif |
161 | 178 | ||
162 | # if defined(ultrix) && defined(mips) | 179 | # if defined (ultrix) && defined (mips) |
163 | # define decstation | 180 | # define decstation |
164 | # endif | 181 | # endif |
165 | 182 | ||
@@ -167,7 +184,7 @@ extern int errno; | |||
167 | # define SVR4 | 184 | # define SVR4 |
168 | # endif | 185 | # endif |
169 | 186 | ||
170 | # if (defined(sun) && defined(SVR4)) || defined (SOLARIS2) | 187 | # if (defined (sun) && defined (SVR4)) || defined (SOLARIS2) |
171 | # define SUNOS_5 | 188 | # define SUNOS_5 |
172 | # endif | 189 | # endif |
173 | 190 | ||
@@ -239,7 +256,7 @@ extern int errno; | |||
239 | # define LOAD_AVE_TYPE long | 256 | # define LOAD_AVE_TYPE long |
240 | # endif | 257 | # endif |
241 | 258 | ||
242 | # if defined(alliant) && defined(i860) /* Alliant FX/2800 */ | 259 | # if defined (alliant) && defined (i860) /* Alliant FX/2800 */ |
243 | # define LOAD_AVE_TYPE long | 260 | # define LOAD_AVE_TYPE long |
244 | # endif | 261 | # endif |
245 | 262 | ||
@@ -263,7 +280,7 @@ extern int errno; | |||
263 | # define FSCALE 1024.0 | 280 | # define FSCALE 1024.0 |
264 | # endif | 281 | # endif |
265 | 282 | ||
266 | # if defined(alliant) && defined(i860) /* Alliant FX/2800 */ | 283 | # if defined (alliant) && defined (i860) /* Alliant FX/2800 */ |
267 | /* <sys/param.h> defines an incorrect value for FSCALE on an | 284 | /* <sys/param.h> defines an incorrect value for FSCALE on an |
268 | Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu. */ | 285 | Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu. */ |
269 | # undef FSCALE | 286 | # undef FSCALE |
@@ -279,7 +296,7 @@ extern int errno; | |||
279 | # define FSCALE 2048.0 | 296 | # define FSCALE 2048.0 |
280 | # endif | 297 | # endif |
281 | 298 | ||
282 | # if defined(MIPS) || defined(SVR4) || defined(decstation) | 299 | # if defined (MIPS) || defined (SVR4) || defined (decstation) |
283 | # define FSCALE 256 | 300 | # define FSCALE 256 |
284 | # endif | 301 | # endif |
285 | 302 | ||
@@ -314,69 +331,7 @@ extern int errno; | |||
314 | # endif | 331 | # endif |
315 | # endif | 332 | # endif |
316 | 333 | ||
317 | /* VAX C can't handle multi-line #ifs, or lines longer that 256 characters. */ | 334 | # if defined (sgi) || (defined (mips) && !defined (BSD)) |
318 | # ifndef NLIST_STRUCT | ||
319 | |||
320 | # ifdef MORE_BSD | ||
321 | # define NLIST_STRUCT | ||
322 | # endif | ||
323 | |||
324 | # ifdef sun | ||
325 | # define NLIST_STRUCT | ||
326 | # endif | ||
327 | |||
328 | # ifdef decstation | ||
329 | # define NLIST_STRUCT | ||
330 | # endif | ||
331 | |||
332 | # ifdef hpux | ||
333 | # define NLIST_STRUCT | ||
334 | # endif | ||
335 | |||
336 | # if defined (_SEQUENT_) || defined (sequent) | ||
337 | # define NLIST_STRUCT | ||
338 | # endif | ||
339 | |||
340 | # ifdef sgi | ||
341 | # define NLIST_STRUCT | ||
342 | # endif | ||
343 | |||
344 | # ifdef SVR4 | ||
345 | # define NLIST_STRUCT | ||
346 | # endif | ||
347 | |||
348 | # ifdef sony_news | ||
349 | # define NLIST_STRUCT | ||
350 | # endif | ||
351 | |||
352 | # ifdef OSF_ALPHA | ||
353 | # define NLIST_STRUCT | ||
354 | # endif | ||
355 | |||
356 | # if defined (ardent) && defined (titan) | ||
357 | # define NLIST_STRUCT | ||
358 | # endif | ||
359 | |||
360 | # ifdef tek4300 | ||
361 | # define NLIST_STRUCT | ||
362 | # endif | ||
363 | |||
364 | # ifdef butterfly | ||
365 | # define NLIST_STRUCT | ||
366 | # endif | ||
367 | |||
368 | # if defined(alliant) && defined(i860) /* Alliant FX/2800 */ | ||
369 | # define NLIST_STRUCT | ||
370 | # endif | ||
371 | |||
372 | # ifdef _AIX | ||
373 | # define NLIST_STRUCT | ||
374 | # endif | ||
375 | |||
376 | # endif /* defined (NLIST_STRUCT) */ | ||
377 | |||
378 | |||
379 | # if defined(sgi) || (defined(mips) && !defined(BSD)) | ||
380 | # define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31)) | 335 | # define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31)) |
381 | # endif | 336 | # endif |
382 | 337 | ||
@@ -389,7 +344,7 @@ extern int errno; | |||
389 | # define KERNEL_FILE "/hp-ux" | 344 | # define KERNEL_FILE "/hp-ux" |
390 | # endif | 345 | # endif |
391 | 346 | ||
392 | # if !defined(KERNEL_FILE) && (defined(_SEQUENT_) || defined(MIPS) || defined(SVR4) || defined(ISC) || defined (sgi) || (defined (ardent) && defined (titan))) | 347 | # if !defined (KERNEL_FILE) && (defined (_SEQUENT_) || defined (MIPS) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan))) |
393 | # define KERNEL_FILE "/unix" | 348 | # define KERNEL_FILE "/unix" |
394 | # endif | 349 | # endif |
395 | 350 | ||
@@ -398,7 +353,7 @@ extern int errno; | |||
398 | # define LDAV_SYMBOL "_Loadavg" | 353 | # define LDAV_SYMBOL "_Loadavg" |
399 | # endif | 354 | # endif |
400 | 355 | ||
401 | # if !defined(LDAV_SYMBOL) && ((defined(hpux) && !defined(hp9000s300)) || defined(_SEQUENT_) || defined(SVR4) || defined(ISC) || defined(sgi) || (defined (ardent) && defined (titan)) || defined (_AIX)) | 356 | # if !defined (LDAV_SYMBOL) && ((defined (hpux) && !defined (hp9000s300)) || defined (_SEQUENT_) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan)) || defined (_AIX)) |
402 | # define LDAV_SYMBOL "avenrun" | 357 | # define LDAV_SYMBOL "avenrun" |
403 | # endif | 358 | # endif |
404 | 359 | ||
@@ -410,7 +365,7 @@ extern int errno; | |||
410 | 365 | ||
411 | /* LOAD_AVE_TYPE should only get defined if we're going to use the | 366 | /* LOAD_AVE_TYPE should only get defined if we're going to use the |
412 | nlist method. */ | 367 | nlist method. */ |
413 | # if !defined(LOAD_AVE_TYPE) && (defined(BSD) || defined(LDAV_CVT) || defined(KERNEL_FILE) || defined(LDAV_SYMBOL)) | 368 | # if !defined (LOAD_AVE_TYPE) && (defined (BSD) || defined (LDAV_CVT) || defined (KERNEL_FILE) || defined (LDAV_SYMBOL)) |
414 | # define LOAD_AVE_TYPE double | 369 | # define LOAD_AVE_TYPE double |
415 | # endif | 370 | # endif |
416 | 371 | ||
@@ -459,7 +414,7 @@ extern int errno; | |||
459 | 414 | ||
460 | # endif /* LOAD_AVE_TYPE */ | 415 | # endif /* LOAD_AVE_TYPE */ |
461 | 416 | ||
462 | # if defined(__GNU__) && !defined (NeXT) | 417 | # if defined (__GNU__) && !defined (NeXT) |
463 | /* Note that NeXT Openstep defines __GNU__ even though it should not. */ | 418 | /* Note that NeXT Openstep defines __GNU__ even though it should not. */ |
464 | /* GNU system acts much like NeXT, for load average purposes, | 419 | /* GNU system acts much like NeXT, for load average purposes, |
465 | but not exactly. */ | 420 | but not exactly. */ |
@@ -506,7 +461,7 @@ extern int errno; | |||
506 | # include <sys/dg_sys_info.h> | 461 | # include <sys/dg_sys_info.h> |
507 | # endif | 462 | # endif |
508 | 463 | ||
509 | # if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION) | 464 | # if defined (HAVE_FCNTL_H) || defined (_POSIX_VERSION) |
510 | # include <fcntl.h> | 465 | # include <fcntl.h> |
511 | # else | 466 | # else |
512 | # include <sys/file.h> | 467 | # include <sys/file.h> |
@@ -528,7 +483,7 @@ static unsigned int samples; | |||
528 | static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ | 483 | static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ |
529 | # endif /* DGUX */ | 484 | # endif /* DGUX */ |
530 | 485 | ||
531 | # ifdef LOAD_AVE_TYPE | 486 | # if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE) |
532 | /* File descriptor open to /dev/kmem or VMS load ave driver. */ | 487 | /* File descriptor open to /dev/kmem or VMS load ave driver. */ |
533 | static int channel; | 488 | static int channel; |
534 | /* Nonzero iff channel is valid. */ | 489 | /* Nonzero iff channel is valid. */ |
@@ -536,7 +491,7 @@ static int getloadavg_initialized; | |||
536 | /* Offset in kmem to seek to read load average, or 0 means invalid. */ | 491 | /* Offset in kmem to seek to read load average, or 0 means invalid. */ |
537 | static long offset; | 492 | static long offset; |
538 | 493 | ||
539 | # if !defined(VMS) && !defined(sgi) && !defined(__linux__) | 494 | # if !defined (VMS) && !defined (sgi) && !defined (__linux__) |
540 | static struct nlist nl[2]; | 495 | static struct nlist nl[2]; |
541 | # endif /* Not VMS or sgi */ | 496 | # endif /* Not VMS or sgi */ |
542 | 497 | ||
@@ -544,7 +499,7 @@ static struct nlist nl[2]; | |||
544 | static kvm_t *kd; | 499 | static kvm_t *kd; |
545 | # endif /* SUNOS_5 */ | 500 | # endif /* SUNOS_5 */ |
546 | 501 | ||
547 | # endif /* LOAD_AVE_TYPE */ | 502 | # endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */ |
548 | 503 | ||
549 | /* Put the 1 minute, 5 minute and 15 minute load averages | 504 | /* Put the 1 minute, 5 minute and 15 minute load averages |
550 | into the first NELEM elements of LOADAVG. | 505 | into the first NELEM elements of LOADAVG. |
@@ -552,9 +507,7 @@ static kvm_t *kd; | |||
552 | or -1 if an error occurred. */ | 507 | or -1 if an error occurred. */ |
553 | 508 | ||
554 | int | 509 | int |
555 | getloadavg (loadavg, nelem) | 510 | getloadavg (double loadavg[], int nelem) |
556 | double loadavg[]; | ||
557 | int nelem; | ||
558 | { | 511 | { |
559 | int elem = 0; /* Return value. */ | 512 | int elem = 0; /* Return value. */ |
560 | 513 | ||
@@ -577,7 +530,7 @@ getloadavg (loadavg, nelem) | |||
577 | if (kc == 0) | 530 | if (kc == 0) |
578 | return -1; | 531 | return -1; |
579 | ksp = kstat_lookup (kc, "unix", 0, "system_misc"); | 532 | ksp = kstat_lookup (kc, "unix", 0, "system_misc"); |
580 | if (ksp == 0 ) | 533 | if (ksp == 0) |
581 | return -1; | 534 | return -1; |
582 | if (kstat_read (kc, ksp, 0) == -1) | 535 | if (kstat_read (kc, ksp, 0) == -1) |
583 | return -1; | 536 | return -1; |
@@ -592,20 +545,20 @@ getloadavg (loadavg, nelem) | |||
592 | } | 545 | } |
593 | 546 | ||
594 | if (nelem >= 1) | 547 | if (nelem >= 1) |
595 | loadavg[elem++] = (double) kn->value.ul/FSCALE; | 548 | loadavg[elem++] = (double) kn->value.ul / FSCALE; |
596 | 549 | ||
597 | if (nelem >= 2) | 550 | if (nelem >= 2) |
598 | { | 551 | { |
599 | kn = kstat_data_lookup (ksp, "avenrun_5min"); | 552 | kn = kstat_data_lookup (ksp, "avenrun_5min"); |
600 | if (kn != 0) | 553 | if (kn != 0) |
601 | { | 554 | { |
602 | loadavg[elem++] = (double) kn->value.ul/FSCALE; | 555 | loadavg[elem++] = (double) kn->value.ul / FSCALE; |
603 | 556 | ||
604 | if (nelem >= 3) | 557 | if (nelem >= 3) |
605 | { | 558 | { |
606 | kn = kstat_data_lookup (ksp, "avenrun_15min"); | 559 | kn = kstat_data_lookup (ksp, "avenrun_15min"); |
607 | if (kn != 0) | 560 | if (kn != 0) |
608 | loadavg[elem++] = (double) kn->value.ul/FSCALE; | 561 | loadavg[elem++] = (double) kn->value.ul / FSCALE; |
609 | } | 562 | } |
610 | } | 563 | } |
611 | } | 564 | } |
@@ -870,8 +823,8 @@ getloadavg (loadavg, nelem) | |||
870 | for (elem = 0; elem < nelem; elem++) | 823 | for (elem = 0; elem < nelem; elem++) |
871 | loadavg[elem] | 824 | loadavg[elem] |
872 | = (load_ave.tl_lscale == 0 | 825 | = (load_ave.tl_lscale == 0 |
873 | ? load_ave.tl_avenrun.d[elem] | 826 | ? load_ave.tl_avenrun.d[elem] |
874 | : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); | 827 | : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); |
875 | # endif /* OSF_ALPHA */ | 828 | # endif /* OSF_ALPHA */ |
876 | 829 | ||
877 | # if !defined (LDAV_DONE) && defined (VMS) | 830 | # if !defined (LDAV_DONE) && defined (VMS) |
@@ -914,7 +867,7 @@ getloadavg (loadavg, nelem) | |||
914 | return -1; | 867 | return -1; |
915 | # endif /* VMS */ | 868 | # endif /* VMS */ |
916 | 869 | ||
917 | # if !defined (LDAV_DONE) && defined(LOAD_AVE_TYPE) && !defined(VMS) | 870 | # if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) && !defined (VMS) |
918 | 871 | ||
919 | /* UNIX-specific code -- read the average from /dev/kmem. */ | 872 | /* UNIX-specific code -- read the average from /dev/kmem. */ |
920 | 873 | ||
@@ -930,13 +883,13 @@ getloadavg (loadavg, nelem) | |||
930 | strcpy (nl[0].n_name, LDAV_SYMBOL); | 883 | strcpy (nl[0].n_name, LDAV_SYMBOL); |
931 | strcpy (nl[1].n_name, ""); | 884 | strcpy (nl[1].n_name, ""); |
932 | # else /* NLIST_STRUCT */ | 885 | # else /* NLIST_STRUCT */ |
933 | # ifdef NLIST_NAME_UNION | 886 | # ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME |
934 | nl[0].n_un.n_name = LDAV_SYMBOL; | 887 | nl[0].n_un.n_name = LDAV_SYMBOL; |
935 | nl[1].n_un.n_name = 0; | 888 | nl[1].n_un.n_name = 0; |
936 | # else /* not NLIST_NAME_UNION */ | 889 | # else /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ |
937 | nl[0].n_name = LDAV_SYMBOL; | 890 | nl[0].n_name = LDAV_SYMBOL; |
938 | nl[1].n_name = 0; | 891 | nl[1].n_name = 0; |
939 | # endif /* not NLIST_NAME_UNION */ | 892 | # endif /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ |
940 | # endif /* NLIST_STRUCT */ | 893 | # endif /* NLIST_STRUCT */ |
941 | 894 | ||
942 | # ifndef SUNOS_5 | 895 | # ifndef SUNOS_5 |
@@ -973,12 +926,7 @@ getloadavg (loadavg, nelem) | |||
973 | { | 926 | { |
974 | /* Set the channel to close on exec, so it does not | 927 | /* Set the channel to close on exec, so it does not |
975 | litter any child's descriptor table. */ | 928 | litter any child's descriptor table. */ |
976 | # ifdef FD_SETFD | 929 | set_cloexec_flag (channel, true); |
977 | # ifndef FD_CLOEXEC | ||
978 | # define FD_CLOEXEC 1 | ||
979 | # endif | ||
980 | (void) fcntl (channel, F_SETFD, FD_CLOEXEC); | ||
981 | # endif | ||
982 | getloadavg_initialized = 1; | 930 | getloadavg_initialized = 1; |
983 | } | 931 | } |
984 | # else /* SUNOS_5 */ | 932 | # else /* SUNOS_5 */ |
@@ -1010,9 +958,9 @@ getloadavg (loadavg, nelem) | |||
1010 | # else /* SUNOS_5 */ | 958 | # else /* SUNOS_5 */ |
1011 | if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) | 959 | if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) |
1012 | != sizeof (load_ave)) | 960 | != sizeof (load_ave)) |
1013 | { | 961 | { |
1014 | kvm_close (kd); | 962 | kvm_close (kd); |
1015 | getloadavg_initialized = 0; | 963 | getloadavg_initialized = 0; |
1016 | } | 964 | } |
1017 | # endif /* SUNOS_5 */ | 965 | # endif /* SUNOS_5 */ |
1018 | } | 966 | } |
@@ -1046,9 +994,7 @@ getloadavg (loadavg, nelem) | |||
1046 | 994 | ||
1047 | #ifdef TEST | 995 | #ifdef TEST |
1048 | void | 996 | void |
1049 | main (argc, argv) | 997 | main (int argc, char **argv) |
1050 | int argc; | ||
1051 | char **argv; | ||
1052 | { | 998 | { |
1053 | int naptime = 0; | 999 | int naptime = 0; |
1054 | 1000 | ||
diff --git a/lib/getopt.c b/lib/getopt.c index 289d137e..6dcdbebf 100644 --- a/lib/getopt.c +++ b/lib/getopt.c | |||
@@ -2,24 +2,26 @@ | |||
2 | NOTE: getopt is now part of the C library, so if you don't know what | 2 | NOTE: getopt is now part of the C library, so if you don't know what |
3 | "Keep this file name-space clean" means, talk to drepper@gnu.org | 3 | "Keep this file name-space clean" means, talk to drepper@gnu.org |
4 | before changing it! | 4 | before changing it! |
5 | Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001,2002 | 5 | |
6 | Free Software Foundation, Inc. | 6 | Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
7 | 1996, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, | ||
8 | Inc. | ||
9 | |||
7 | This file is part of the GNU C Library. | 10 | This file is part of the GNU C Library. |
8 | 11 | ||
9 | The GNU C Library is free software; you can redistribute it and/or | 12 | This program is free software; you can redistribute it and/or modify |
10 | modify it under the terms of the GNU Lesser General Public | 13 | it under the terms of the GNU General Public License as published by |
11 | License as published by the Free Software Foundation; either | 14 | the Free Software Foundation; either version 2, or (at your option) |
12 | version 2.1 of the License, or (at your option) any later version. | 15 | any later version. |
13 | 16 | ||
14 | The GNU C Library is distributed in the hope that it will be useful, | 17 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | Lesser General Public License for more details. | 20 | GNU General Public License for more details. |
18 | 21 | ||
19 | You should have received a copy of the GNU Lesser General Public | 22 | You should have received a copy of the GNU General Public License along |
20 | License along with the GNU C Library; if not, write to the Free | 23 | with this program; if not, write to the Free Software Foundation, |
21 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | 24 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
22 | 02111-1307 USA. */ | ||
23 | 25 | ||
24 | /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. | 26 | /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. |
25 | Ditto for AIX 3.2 and <stdlib.h>. */ | 27 | Ditto for AIX 3.2 and <stdlib.h>. */ |
@@ -31,14 +33,6 @@ | |||
31 | # include <config.h> | 33 | # include <config.h> |
32 | #endif | 34 | #endif |
33 | 35 | ||
34 | #if !defined __STDC__ || !__STDC__ | ||
35 | /* This is a separate conditional since some stdc systems | ||
36 | reject `defined (const)'. */ | ||
37 | # ifndef const | ||
38 | # define const | ||
39 | # endif | ||
40 | #endif | ||
41 | |||
42 | #include <stdio.h> | 36 | #include <stdio.h> |
43 | 37 | ||
44 | /* Comment out all this code if we are using the GNU C Library, and are not | 38 | /* Comment out all this code if we are using the GNU C Library, and are not |
@@ -69,26 +63,22 @@ | |||
69 | # include <unistd.h> | 63 | # include <unistd.h> |
70 | #endif /* GNU C library. */ | 64 | #endif /* GNU C library. */ |
71 | 65 | ||
66 | #include <string.h> | ||
67 | |||
72 | #ifdef VMS | 68 | #ifdef VMS |
73 | # include <unixlib.h> | 69 | # include <unixlib.h> |
74 | # if HAVE_STRING_H - 0 | ||
75 | # include <string.h> | ||
76 | # endif | ||
77 | #endif | 70 | #endif |
78 | 71 | ||
79 | #ifndef _ | 72 | #ifdef _LIBC |
73 | # include <libintl.h> | ||
74 | #else | ||
80 | /* This is for other GNU distributions with internationalized messages. */ | 75 | /* This is for other GNU distributions with internationalized messages. */ |
81 | # if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC | 76 | # include "gettext.h" |
82 | # include <libintl.h> | 77 | #endif |
83 | # ifndef _ | 78 | #define _(msgid) gettext (msgid) |
84 | # define _(msgid) gettext (msgid) | 79 | |
85 | # endif | 80 | #if defined _LIBC && defined USE_IN_LIBIO |
86 | # else | 81 | # include <wchar.h> |
87 | # define _(msgid) (msgid) | ||
88 | # endif | ||
89 | # if defined _LIBC && defined USE_IN_LIBIO | ||
90 | # include <wchar.h> | ||
91 | # endif | ||
92 | #endif | 82 | #endif |
93 | 83 | ||
94 | #ifndef attribute_hidden | 84 | #ifndef attribute_hidden |
@@ -197,20 +187,7 @@ static enum | |||
197 | /* Value of POSIXLY_CORRECT environment variable. */ | 187 | /* Value of POSIXLY_CORRECT environment variable. */ |
198 | static char *posixly_correct; | 188 | static char *posixly_correct; |
199 | 189 | ||
200 | #ifdef __GNU_LIBRARY__ | 190 | #ifndef __GNU_LIBRARY__ |
201 | /* We want to avoid inclusion of string.h with non-GNU libraries | ||
202 | because there are many ways it can cause trouble. | ||
203 | On some systems, it contains special magic macros that don't work | ||
204 | in GCC. */ | ||
205 | # include <string.h> | ||
206 | # define my_index strchr | ||
207 | #else | ||
208 | |||
209 | # if HAVE_STRING_H | ||
210 | # include <string.h> | ||
211 | # else | ||
212 | # include <strings.h> | ||
213 | # endif | ||
214 | 191 | ||
215 | /* Avoid depending on library functions or files | 192 | /* Avoid depending on library functions or files |
216 | whose names are inconsistent. */ | 193 | whose names are inconsistent. */ |
@@ -219,32 +196,6 @@ static char *posixly_correct; | |||
219 | extern char *getenv (); | 196 | extern char *getenv (); |
220 | #endif | 197 | #endif |
221 | 198 | ||
222 | static char * | ||
223 | my_index (str, chr) | ||
224 | const char *str; | ||
225 | int chr; | ||
226 | { | ||
227 | while (*str) | ||
228 | { | ||
229 | if (*str == chr) | ||
230 | return (char *) str; | ||
231 | str++; | ||
232 | } | ||
233 | return 0; | ||
234 | } | ||
235 | |||
236 | /* If using GCC, we can safely declare strlen this way. | ||
237 | If not using GCC, it is ok not to declare it. */ | ||
238 | #ifdef __GNUC__ | ||
239 | /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. | ||
240 | That was relevant to code that was here before. */ | ||
241 | # if (!defined __STDC__ || !__STDC__) && !defined strlen | ||
242 | /* gcc with -traditional declares the built-in strlen to return int, | ||
243 | and has done so at least since version 2.4.5. -- rms. */ | ||
244 | extern int strlen (const char *); | ||
245 | # endif /* not __STDC__ */ | ||
246 | #endif /* __GNUC__ */ | ||
247 | |||
248 | #endif /* not __GNU_LIBRARY__ */ | 199 | #endif /* not __GNU_LIBRARY__ */ |
249 | 200 | ||
250 | /* Handle permutation of arguments. */ | 201 | /* Handle permutation of arguments. */ |
@@ -298,13 +249,8 @@ static int nonoption_flags_len; | |||
298 | `first_nonopt' and `last_nonopt' are relocated so that they describe | 249 | `first_nonopt' and `last_nonopt' are relocated so that they describe |
299 | the new indices of the non-options in ARGV after they are moved. */ | 250 | the new indices of the non-options in ARGV after they are moved. */ |
300 | 251 | ||
301 | #if defined __STDC__ && __STDC__ | ||
302 | static void exchange (char **); | ||
303 | #endif | ||
304 | |||
305 | static void | 252 | static void |
306 | exchange (argv) | 253 | exchange (char **argv) |
307 | char **argv; | ||
308 | { | 254 | { |
309 | int bottom = first_nonopt; | 255 | int bottom = first_nonopt; |
310 | int middle = last_nonopt; | 256 | int middle = last_nonopt; |
@@ -384,14 +330,8 @@ exchange (argv) | |||
384 | 330 | ||
385 | /* Initialize the internal data when the first call is made. */ | 331 | /* Initialize the internal data when the first call is made. */ |
386 | 332 | ||
387 | #if defined __STDC__ && __STDC__ | ||
388 | static const char *_getopt_initialize (int, char *const *, const char *); | ||
389 | #endif | ||
390 | static const char * | 333 | static const char * |
391 | _getopt_initialize (argc, argv, optstring) | 334 | _getopt_initialize (int argc, char *const *argv, const char *optstring) |
392 | int argc; | ||
393 | char *const *argv; | ||
394 | const char *optstring; | ||
395 | { | 335 | { |
396 | /* Start processing options with ARGV-element 1 (since ARGV-element 0 | 336 | /* Start processing options with ARGV-element 1 (since ARGV-element 0 |
397 | is the program name); the sequence of previously skipped | 337 | is the program name); the sequence of previously skipped |
@@ -510,13 +450,9 @@ _getopt_initialize (argc, argv, optstring) | |||
510 | long-named options. */ | 450 | long-named options. */ |
511 | 451 | ||
512 | int | 452 | int |
513 | _getopt_internal (argc, argv, optstring, longopts, longind, long_only) | 453 | _getopt_internal (int argc, char *const *argv, |
514 | int argc; | 454 | const char *optstring, const struct option *longopts, |
515 | char *const *argv; | 455 | int *longind, int long_only) |
516 | const char *optstring; | ||
517 | const struct option *longopts; | ||
518 | int *longind; | ||
519 | int long_only; | ||
520 | { | 456 | { |
521 | int print_errors = opterr; | 457 | int print_errors = opterr; |
522 | if (optstring[0] == ':') | 458 | if (optstring[0] == ':') |
@@ -641,7 +577,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) | |||
641 | 577 | ||
642 | if (longopts != NULL | 578 | if (longopts != NULL |
643 | && (argv[optind][1] == '-' | 579 | && (argv[optind][1] == '-' |
644 | || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) | 580 | || (long_only |
581 | && (argv[optind][2] || !strchr (optstring, argv[optind][1]))))) | ||
645 | { | 582 | { |
646 | char *nameend; | 583 | char *nameend; |
647 | const struct option *p; | 584 | const struct option *p; |
@@ -826,7 +763,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) | |||
826 | option, then it's an error. | 763 | option, then it's an error. |
827 | Otherwise interpret it as a short option. */ | 764 | Otherwise interpret it as a short option. */ |
828 | if (!long_only || argv[optind][1] == '-' | 765 | if (!long_only || argv[optind][1] == '-' |
829 | || my_index (optstring, *nextchar) == NULL) | 766 | || strchr (optstring, *nextchar) == NULL) |
830 | { | 767 | { |
831 | if (print_errors) | 768 | if (print_errors) |
832 | { | 769 | { |
@@ -881,7 +818,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) | |||
881 | 818 | ||
882 | { | 819 | { |
883 | char c = *nextchar++; | 820 | char c = *nextchar++; |
884 | char *temp = my_index (optstring, c); | 821 | char *temp = strchr (optstring, c); |
885 | 822 | ||
886 | /* Increment `optind' when we start to process its last character. */ | 823 | /* Increment `optind' when we start to process its last character. */ |
887 | if (*nextchar == '\0') | 824 | if (*nextchar == '\0') |
@@ -1191,10 +1128,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) | |||
1191 | } | 1128 | } |
1192 | 1129 | ||
1193 | int | 1130 | int |
1194 | getopt (argc, argv, optstring) | 1131 | getopt (int argc, char *const *argv, const char *optstring) |
1195 | int argc; | ||
1196 | char *const *argv; | ||
1197 | const char *optstring; | ||
1198 | { | 1132 | { |
1199 | return _getopt_internal (argc, argv, optstring, | 1133 | return _getopt_internal (argc, argv, optstring, |
1200 | (const struct option *) 0, | 1134 | (const struct option *) 0, |
@@ -1210,9 +1144,7 @@ getopt (argc, argv, optstring) | |||
1210 | the above definition of `getopt'. */ | 1144 | the above definition of `getopt'. */ |
1211 | 1145 | ||
1212 | int | 1146 | int |
1213 | main (argc, argv) | 1147 | main (int argc, char **argv) |
1214 | int argc; | ||
1215 | char **argv; | ||
1216 | { | 1148 | { |
1217 | int c; | 1149 | int c; |
1218 | int digit_optind = 0; | 1150 | int digit_optind = 0; |
diff --git a/lib/getopt.h b/lib/getopt.h index 4283c35b..5e15191e 100644 --- a/lib/getopt.h +++ b/lib/getopt.h | |||
@@ -1,21 +1,23 @@ | |||
1 | /* Declarations for getopt. | 1 | /* Declarations for getopt. |
2 | Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, | ||
4 | 1999, 2001, 2003 Free Software Foundation, Inc. | ||
5 | |||
3 | This file is part of the GNU C Library. | 6 | This file is part of the GNU C Library. |
4 | 7 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | 8 | This program is free software; you can redistribute it and/or modify |
6 | modify it under the terms of the GNU Lesser General Public | 9 | it under the terms of the GNU General Public License as published by |
7 | License as published by the Free Software Foundation; either | 10 | the Free Software Foundation; either version 2, or (at your option) |
8 | version 2.1 of the License, or (at your option) any later version. | 11 | any later version. |
9 | 12 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | Lesser General Public License for more details. | 16 | GNU General Public License for more details. |
14 | 17 | ||
15 | You should have received a copy of the GNU Lesser General Public | 18 | You should have received a copy of the GNU General Public License along |
16 | License along with the GNU C Library; if not, write to the Free | 19 | with this program; if not, write to the Free Software Foundation, |
17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | 20 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
18 | 02111-1307 USA. */ | ||
19 | 21 | ||
20 | #ifndef _GETOPT_H | 22 | #ifndef _GETOPT_H |
21 | 23 | ||
@@ -78,7 +80,7 @@ extern int optopt; | |||
78 | The field `has_arg' is: | 80 | The field `has_arg' is: |
79 | no_argument (or 0) if the option does not take an argument, | 81 | no_argument (or 0) if the option does not take an argument, |
80 | required_argument (or 1) if the option requires an argument, | 82 | required_argument (or 1) if the option requires an argument, |
81 | optional_argument (or 2) if the option takes an optional argument. | 83 | optional_argument (or 2) if the option takes an optional argument. |
82 | 84 | ||
83 | If the field `flag' is not NULL, it points to a variable that is set | 85 | If the field `flag' is not NULL, it points to a variable that is set |
84 | to the value given in the field `val' when the option is found, but | 86 | to the value given in the field `val' when the option is found, but |
@@ -93,11 +95,7 @@ extern int optopt; | |||
93 | 95 | ||
94 | struct option | 96 | struct option |
95 | { | 97 | { |
96 | # if (defined __STDC__ && __STDC__) || defined __cplusplus | ||
97 | const char *name; | 98 | const char *name; |
98 | # else | ||
99 | char *name; | ||
100 | # endif | ||
101 | /* has_arg can't be an enum because some compilers complain about | 99 | /* has_arg can't be an enum because some compilers complain about |
102 | type mismatches in all the code that assumes it is an int. */ | 100 | type mismatches in all the code that assumes it is an int. */ |
103 | int has_arg; | 101 | int has_arg; |
@@ -137,17 +135,16 @@ struct option | |||
137 | arguments to the option '\0'. This behavior is specific to the GNU | 135 | arguments to the option '\0'. This behavior is specific to the GNU |
138 | `getopt'. */ | 136 | `getopt'. */ |
139 | 137 | ||
140 | #if (defined __STDC__ && __STDC__) || defined __cplusplus | 138 | #ifdef __GNU_LIBRARY__ |
141 | # ifdef __GNU_LIBRARY__ | ||
142 | /* Many other libraries have conflicting prototypes for getopt, with | 139 | /* Many other libraries have conflicting prototypes for getopt, with |
143 | differences in the consts, in stdlib.h. To avoid compilation | 140 | differences in the consts, in stdlib.h. To avoid compilation |
144 | errors, only prototype getopt for the GNU C library. */ | 141 | errors, only prototype getopt for the GNU C library. */ |
145 | extern int getopt (int ___argc, char *const *___argv, const char *__shortopts); | 142 | extern int getopt (int ___argc, char *const *___argv, const char *__shortopts); |
146 | # else /* not __GNU_LIBRARY__ */ | 143 | #else /* not __GNU_LIBRARY__ */ |
147 | extern int getopt (); | 144 | extern int getopt (); |
148 | # endif /* __GNU_LIBRARY__ */ | 145 | #endif /* __GNU_LIBRARY__ */ |
149 | 146 | ||
150 | # ifndef __need_getopt | 147 | #ifndef __need_getopt |
151 | extern int getopt_long (int ___argc, char *const *___argv, | 148 | extern int getopt_long (int ___argc, char *const *___argv, |
152 | const char *__shortopts, | 149 | const char *__shortopts, |
153 | const struct option *__longopts, int *__longind); | 150 | const struct option *__longopts, int *__longind); |
@@ -160,16 +157,7 @@ extern int _getopt_internal (int ___argc, char *const *___argv, | |||
160 | const char *__shortopts, | 157 | const char *__shortopts, |
161 | const struct option *__longopts, int *__longind, | 158 | const struct option *__longopts, int *__longind, |
162 | int __long_only); | 159 | int __long_only); |
163 | # endif | 160 | #endif |
164 | #else /* not __STDC__ */ | ||
165 | extern int getopt (); | ||
166 | # ifndef __need_getopt | ||
167 | extern int getopt_long (); | ||
168 | extern int getopt_long_only (); | ||
169 | |||
170 | extern int _getopt_internal (); | ||
171 | # endif | ||
172 | #endif /* __STDC__ */ | ||
173 | 161 | ||
174 | #ifdef __cplusplus | 162 | #ifdef __cplusplus |
175 | } | 163 | } |
diff --git a/lib/getopt1.c b/lib/getopt1.c index ad06cc7f..3288c726 100644 --- a/lib/getopt1.c +++ b/lib/getopt1.c | |||
@@ -1,22 +1,23 @@ | |||
1 | /* getopt_long and getopt_long_only entry points for GNU getopt. | 1 | /* getopt_long and getopt_long_only entry points for GNU getopt. |
2 | Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 | 2 | |
3 | Free Software Foundation, Inc. | 3 | Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, |
4 | 1997, 1998, 2003 Free Software Foundation, Inc. | ||
5 | |||
4 | This file is part of the GNU C Library. | 6 | This file is part of the GNU C Library. |
5 | 7 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | 8 | This program is free software; you can redistribute it and/or modify |
7 | modify it under the terms of the GNU Lesser General Public | 9 | it under the terms of the GNU General Public License as published by |
8 | License as published by the Free Software Foundation; either | 10 | the Free Software Foundation; either version 2, or (at your option) |
9 | version 2.1 of the License, or (at your option) any later version. | 11 | any later version. |
10 | 12 | ||
11 | The GNU C Library is distributed in the hope that it will be useful, | 13 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | Lesser General Public License for more details. | 16 | GNU General Public License for more details. |
15 | 17 | ||
16 | You should have received a copy of the GNU Lesser General Public | 18 | You should have received a copy of the GNU General Public License along |
17 | License along with the GNU C Library; if not, write to the Free | 19 | with this program; if not, write to the Free Software Foundation, |
18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | 20 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
19 | 02111-1307 USA. */ | ||
20 | 21 | ||
21 | #ifdef HAVE_CONFIG_H | 22 | #ifdef HAVE_CONFIG_H |
22 | #include <config.h> | 23 | #include <config.h> |
@@ -28,14 +29,6 @@ | |||
28 | # include "getopt.h" | 29 | # include "getopt.h" |
29 | #endif | 30 | #endif |
30 | 31 | ||
31 | #if !defined __STDC__ || !__STDC__ | ||
32 | /* This is a separate conditional since some stdc systems | ||
33 | reject `defined (const)'. */ | ||
34 | #ifndef const | ||
35 | #define const | ||
36 | #endif | ||
37 | #endif | ||
38 | |||
39 | #include <stdio.h> | 32 | #include <stdio.h> |
40 | 33 | ||
41 | /* Comment out all this code if we are using the GNU C Library, and are not | 34 | /* Comment out all this code if we are using the GNU C Library, and are not |
@@ -68,12 +61,11 @@ | |||
68 | #endif | 61 | #endif |
69 | 62 | ||
70 | int | 63 | int |
71 | getopt_long (argc, argv, options, long_options, opt_index) | 64 | getopt_long (int argc, |
72 | int argc; | 65 | char *const *argv, |
73 | char *const *argv; | 66 | const char *options, |
74 | const char *options; | 67 | const struct option *long_options, |
75 | const struct option *long_options; | 68 | int *opt_index) |
76 | int *opt_index; | ||
77 | { | 69 | { |
78 | return _getopt_internal (argc, argv, options, long_options, opt_index, 0); | 70 | return _getopt_internal (argc, argv, options, long_options, opt_index, 0); |
79 | } | 71 | } |
@@ -84,12 +76,11 @@ getopt_long (argc, argv, options, long_options, opt_index) | |||
84 | instead. */ | 76 | instead. */ |
85 | 77 | ||
86 | int | 78 | int |
87 | getopt_long_only (argc, argv, options, long_options, opt_index) | 79 | getopt_long_only (int argc, |
88 | int argc; | 80 | char *const *argv, |
89 | char *const *argv; | 81 | const char *options, |
90 | const char *options; | 82 | const struct option *long_options, |
91 | const struct option *long_options; | 83 | int *opt_index) |
92 | int *opt_index; | ||
93 | { | 84 | { |
94 | return _getopt_internal (argc, argv, options, long_options, opt_index, 1); | 85 | return _getopt_internal (argc, argv, options, long_options, opt_index, 1); |
95 | } | 86 | } |
@@ -106,9 +97,7 @@ libc_hidden_def (getopt_long_only) | |||
106 | #include <stdio.h> | 97 | #include <stdio.h> |
107 | 98 | ||
108 | int | 99 | int |
109 | main (argc, argv) | 100 | main (int argc, char **argv) |
110 | int argc; | ||
111 | char **argv; | ||
112 | { | 101 | { |
113 | int c; | 102 | int c; |
114 | int digit_optind = 0; | 103 | int digit_optind = 0; |
diff --git a/lib/gettext.h b/lib/gettext.h index 8b262f4c..835732e0 100644 --- a/lib/gettext.h +++ b/lib/gettext.h | |||
@@ -1,20 +1,19 @@ | |||
1 | /* Convenience header for conditional use of GNU <libintl.h>. | 1 | /* Convenience header for conditional use of GNU <libintl.h>. |
2 | Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. | 2 | Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify it | 4 | This program is free software; you can redistribute it and/or modify |
5 | under the terms of the GNU Library General Public License as published | 5 | it under the terms of the GNU General Public License as published by |
6 | by the Free Software Foundation; either version 2, or (at your option) | 6 | the Free Software Foundation; either version 2, or (at your option) |
7 | any later version. | 7 | any later version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, | 9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | Library General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public | 14 | You should have received a copy of the GNU General Public License along |
15 | License along with this program; if not, write to the Free Software | 15 | with this program; if not, write to the Free Software Foundation, |
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | 16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 | USA. */ | ||
18 | 17 | ||
19 | #ifndef _LIBGETTEXT_H | 18 | #ifndef _LIBGETTEXT_H |
20 | #define _LIBGETTEXT_H 1 | 19 | #define _LIBGETTEXT_H 1 |
diff --git a/lib/ls-mntd-fs.m4 b/lib/ls-mntd-fs.m4 index 3ba42a31..c28466bb 100644 --- a/lib/ls-mntd-fs.m4 +++ b/lib/ls-mntd-fs.m4 | |||
@@ -1,4 +1,4 @@ | |||
1 | #serial 12 | 1 | #serial 14 |
2 | 2 | ||
3 | dnl From Jim Meyering. | 3 | dnl From Jim Meyering. |
4 | dnl | 4 | dnl |
@@ -10,13 +10,20 @@ dnl | |||
10 | AC_DEFUN([jm_LIST_MOUNTED_FILESYSTEMS], | 10 | AC_DEFUN([jm_LIST_MOUNTED_FILESYSTEMS], |
11 | [ | 11 | [ |
12 | AC_CHECK_FUNCS(listmntent getmntinfo) | 12 | AC_CHECK_FUNCS(listmntent getmntinfo) |
13 | AC_CHECK_HEADERS(mntent.h sys/param.h sys/ucred.h sys/mount.h sys/fs_types.h) | 13 | AC_CHECK_HEADERS_ONCE(sys/param.h) |
14 | |||
15 | # We must include grp.h before ucred.h on OSF V4.0, since ucred.h uses | ||
16 | # NGROUPS (as the array dimension for a struct member) without a definition. | ||
17 | AC_CHECK_HEADERS(sys/ucred.h, [], [], [#include <grp.h>]) | ||
18 | |||
19 | AC_CHECK_HEADERS(mntent.h sys/mount.h sys/fs_types.h) | ||
14 | getfsstat_includes="\ | 20 | getfsstat_includes="\ |
15 | $ac_includes_default | 21 | $ac_includes_default |
16 | #if HAVE_SYS_PARAM_H | 22 | #if HAVE_SYS_PARAM_H |
17 | # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */ | 23 | # include <sys/param.h> /* needed by powerpc-apple-darwin1.3.7 */ |
18 | #endif | 24 | #endif |
19 | #if HAVE_SYS_UCRED_H | 25 | #if HAVE_SYS_UCRED_H |
26 | # include <grp.h> /* needed for definition of NGROUPS */ | ||
20 | # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */ | 27 | # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */ |
21 | #endif | 28 | #endif |
22 | #if HAVE_SYS_MOUNT_H | 29 | #if HAVE_SYS_MOUNT_H |
@@ -63,7 +70,7 @@ yes | |||
63 | ac_list_mounted_fs=found | 70 | ac_list_mounted_fs=found |
64 | AC_DEFINE(MOUNTED_LISTMNTENT, 1, | 71 | AC_DEFINE(MOUNTED_LISTMNTENT, 1, |
65 | [Define if there is a function named listmntent that can be used to | 72 | [Define if there is a function named listmntent that can be used to |
66 | list all mounted filesystems. (UNICOS)]) | 73 | list all mounted filesystems. (UNICOS)]) |
67 | fi | 74 | fi |
68 | fi | 75 | fi |
69 | 76 | ||
@@ -79,8 +86,8 @@ if test -z "$ac_list_mounted_fs"; then | |||
79 | ac_list_mounted_fs=found | 86 | ac_list_mounted_fs=found |
80 | AC_DEFINE(MOUNTED_VMOUNT, 1, | 87 | AC_DEFINE(MOUNTED_VMOUNT, 1, |
81 | [Define if there is a function named mntctl that can be used to read | 88 | [Define if there is a function named mntctl that can be used to read |
82 | the list of mounted filesystems, and there is a system header file | 89 | the list of mounted filesystems, and there is a system header file |
83 | that declares `struct vmount.' (AIX)]) | 90 | that declares `struct vmount.' (AIX)]) |
84 | fi | 91 | fi |
85 | fi | 92 | fi |
86 | 93 | ||
@@ -117,9 +124,9 @@ if test $ac_cv_func_getmntent = yes; then | |||
117 | if test $fu_cv_sys_mounted_getmntent1 = yes; then | 124 | if test $fu_cv_sys_mounted_getmntent1 = yes; then |
118 | ac_list_mounted_fs=found | 125 | ac_list_mounted_fs=found |
119 | AC_DEFINE(MOUNTED_GETMNTENT1, 1, | 126 | AC_DEFINE(MOUNTED_GETMNTENT1, 1, |
120 | [Define if there is a function named getmntent for reading the list | 127 | [Define if there is a function named getmntent for reading the list |
121 | of mounted filesystems, and that function takes a single argument. | 128 | of mounted filesystems, and that function takes a single argument. |
122 | (4.3BSD, SunOS, HP-UX, Dynix, Irix)]) | 129 | (4.3BSD, SunOS, HP-UX, Dynix, Irix)]) |
123 | fi | 130 | fi |
124 | fi | 131 | fi |
125 | 132 | ||
@@ -134,8 +141,8 @@ if test $ac_cv_func_getmntent = yes; then | |||
134 | if test $fu_cv_sys_mounted_getmntent2 = yes; then | 141 | if test $fu_cv_sys_mounted_getmntent2 = yes; then |
135 | ac_list_mounted_fs=found | 142 | ac_list_mounted_fs=found |
136 | AC_DEFINE(MOUNTED_GETMNTENT2, 1, | 143 | AC_DEFINE(MOUNTED_GETMNTENT2, 1, |
137 | [Define if there is a function named getmntent for reading the list of | 144 | [Define if there is a function named getmntent for reading the list of |
138 | mounted filesystems, and that function takes two arguments. (SVR4)]) | 145 | mounted filesystems, and that function takes two arguments. (SVR4)]) |
139 | fi | 146 | fi |
140 | fi | 147 | fi |
141 | 148 | ||
@@ -166,7 +173,7 @@ if test -z "$ac_list_mounted_fs"; then | |||
166 | ac_list_mounted_fs=found | 173 | ac_list_mounted_fs=found |
167 | AC_DEFINE(MOUNTED_GETFSSTAT, 1, | 174 | AC_DEFINE(MOUNTED_GETFSSTAT, 1, |
168 | [Define if there is a function named getfsstat for reading the | 175 | [Define if there is a function named getfsstat for reading the |
169 | list of mounted filesystems. (DEC Alpha running OSF/1)]) | 176 | list of mounted filesystems. (DEC Alpha running OSF/1)]) |
170 | fi | 177 | fi |
171 | fi | 178 | fi |
172 | 179 | ||
@@ -184,9 +191,9 @@ if test -z "$ac_list_mounted_fs"; then | |||
184 | if test $fu_cv_sys_mounted_fread_fstyp = yes; then | 191 | if test $fu_cv_sys_mounted_fread_fstyp = yes; then |
185 | ac_list_mounted_fs=found | 192 | ac_list_mounted_fs=found |
186 | AC_DEFINE(MOUNTED_FREAD_FSTYP, 1, | 193 | AC_DEFINE(MOUNTED_FREAD_FSTYP, 1, |
187 | [Define if (like SVR2) there is no specific function for reading the | 194 | [Define if (like SVR2) there is no specific function for reading the |
188 | list of mounted filesystems, and your system has these header files: | 195 | list of mounted filesystems, and your system has these header files: |
189 | <sys/fstyp.h> and <sys/statfs.h>. (SVR3)]) | 196 | <sys/fstyp.h> and <sys/statfs.h>. (SVR3)]) |
190 | fi | 197 | fi |
191 | fi | 198 | fi |
192 | 199 | ||
@@ -204,7 +211,7 @@ if test -z "$ac_list_mounted_fs"; then | |||
204 | ac_list_mounted_fs=found | 211 | ac_list_mounted_fs=found |
205 | AC_DEFINE(MOUNTED_GETMNTINFO, 1, | 212 | AC_DEFINE(MOUNTED_GETMNTINFO, 1, |
206 | [Define if there is a function named getmntinfo for reading the | 213 | [Define if there is a function named getmntinfo for reading the |
207 | list of mounted filesystems. (4.4BSD, Darwin)]) | 214 | list of mounted filesystems. (4.4BSD, Darwin)]) |
208 | fi | 215 | fi |
209 | fi | 216 | fi |
210 | 217 | ||
@@ -222,7 +229,7 @@ if test -z "$ac_list_mounted_fs"; then | |||
222 | ac_list_mounted_fs=found | 229 | ac_list_mounted_fs=found |
223 | AC_DEFINE(MOUNTED_GETMNT, 1, | 230 | AC_DEFINE(MOUNTED_GETMNT, 1, |
224 | [Define if there is a function named getmnt for reading the list of | 231 | [Define if there is a function named getmnt for reading the list of |
225 | mounted filesystems. (Ultrix)]) | 232 | mounted filesystems. (Ultrix)]) |
226 | fi | 233 | fi |
227 | fi | 234 | fi |
228 | 235 | ||
@@ -243,7 +250,7 @@ if test -z "$ac_list_mounted_fs"; then | |||
243 | ac_list_mounted_fs=found | 250 | ac_list_mounted_fs=found |
244 | AC_DEFINE(MOUNTED_FS_STAT_DEV, 1, | 251 | AC_DEFINE(MOUNTED_FS_STAT_DEV, 1, |
245 | [Define if there are functions named next_dev and fs_stat_dev for | 252 | [Define if there are functions named next_dev and fs_stat_dev for |
246 | reading the list of mounted filesystems. (BeOS)]) | 253 | reading the list of mounted filesystems. (BeOS)]) |
247 | fi | 254 | fi |
248 | fi | 255 | fi |
249 | 256 | ||
@@ -259,7 +266,8 @@ if test -z "$ac_list_mounted_fs"; then | |||
259 | ac_list_mounted_fs=found | 266 | ac_list_mounted_fs=found |
260 | AC_DEFINE(MOUNTED_FREAD, 1, | 267 | AC_DEFINE(MOUNTED_FREAD, 1, |
261 | [Define if there is no specific function for reading the list of | 268 | [Define if there is no specific function for reading the list of |
262 | mounted filesystems. fread will be used to read /etc/mnttab. (SVR2) ]) | 269 | mounted filesystems. fread will be used to read /etc/mnttab. |
270 | (SVR2) ]) | ||
263 | fi | 271 | fi |
264 | fi | 272 | fi |
265 | 273 | ||
diff --git a/lib/malloc.c b/lib/malloc.c index 5e7674bd..a43d1692 100644 --- a/lib/malloc.c +++ b/lib/malloc.c | |||
@@ -22,14 +22,12 @@ | |||
22 | #endif | 22 | #endif |
23 | #undef malloc | 23 | #undef malloc |
24 | 24 | ||
25 | #include <sys/types.h> | 25 | #include <stdlib.h> |
26 | |||
27 | char *malloc (); | ||
28 | 26 | ||
29 | /* Allocate an N-byte block of memory from the heap. | 27 | /* Allocate an N-byte block of memory from the heap. |
30 | If N is zero, allocate a 1-byte block. */ | 28 | If N is zero, allocate a 1-byte block. */ |
31 | 29 | ||
32 | char * | 30 | void * |
33 | rpl_malloc (size_t n) | 31 | rpl_malloc (size_t n) |
34 | { | 32 | { |
35 | if (n == 0) | 33 | if (n == 0) |
diff --git a/lib/mountlist.c b/lib/mountlist.c index 1af3cbbd..631be312 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* mountlist.c -- return a list of mounted filesystems | 1 | /* mountlist.c -- return a list of mounted filesystems |
2 | Copyright (C) 1991, 1992, 1997-2000 Free Software Foundation, Inc. | 2 | Copyright (C) 1991, 1992, 1997-2004 Free Software Foundation, Inc. |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify | 4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
@@ -15,29 +15,24 @@ | |||
15 | along with this program; if not, write to the Free Software Foundation, | 15 | along with this program; if not, write to the Free Software Foundation, |
16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | 16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 | 17 | ||
18 | #include "config.h" | 18 | #if HAVE_CONFIG_H |
19 | # include <config.h> | ||
20 | #endif | ||
19 | 21 | ||
20 | #include <stdio.h> | 22 | #include <stdio.h> |
21 | #include <sys/types.h> | 23 | #include <sys/types.h> |
22 | #include "mountlist.h" | 24 | #include <stdlib.h> |
25 | #include <string.h> | ||
23 | 26 | ||
24 | #ifdef STDC_HEADERS | 27 | #include "xalloc.h" |
25 | # include <stdlib.h> | 28 | |
26 | #else | 29 | #ifndef SIZE_MAX |
27 | void free (); | 30 | # define SIZE_MAX ((size_t) -1) |
28 | #endif | ||
29 | #if defined(STDC_HEADERS) || defined(HAVE_STRING_H) | ||
30 | # include <string.h> | ||
31 | #else | ||
32 | # include <strings.h> | ||
33 | #endif | 31 | #endif |
34 | 32 | ||
35 | #ifndef strstr | 33 | #ifndef strstr |
36 | char *strstr (); | 34 | char *strstr (); |
37 | #endif | 35 | #endif |
38 | /* char *xmalloc (); */ | ||
39 | /* char *realloc (); */ | ||
40 | /* char *xstrdup (); */ | ||
41 | 36 | ||
42 | #include <errno.h> | 37 | #include <errno.h> |
43 | #ifndef errno | 38 | #ifndef errno |
@@ -56,18 +51,35 @@ extern int errno; | |||
56 | # include <sys/param.h> | 51 | # include <sys/param.h> |
57 | #endif | 52 | #endif |
58 | 53 | ||
59 | #if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */ | 54 | #if defined MOUNTED_GETFSSTAT /* OSF_1 and Darwin1.3.x */ |
60 | # include <sys/mount.h> | 55 | # if HAVE_SYS_UCRED_H |
61 | # include <sys/fs_types.h> | 56 | # include <grp.h> /* needed on OSF V4.0 for definition of NGROUPS, |
57 | NGROUPS is used as an array dimension in ucred.h */ | ||
58 | # include <sys/ucred.h> /* needed by powerpc-apple-darwin1.3.7 */ | ||
59 | # endif | ||
60 | # if HAVE_SYS_MOUNT_H | ||
61 | # include <sys/mount.h> | ||
62 | # endif | ||
63 | # if HAVE_SYS_FS_TYPES_H | ||
64 | # include <sys/fs_types.h> /* needed by powerpc-apple-darwin1.3.7 */ | ||
65 | # endif | ||
66 | # if HAVE_STRUCT_FSSTAT_F_FSTYPENAME | ||
67 | # define FS_TYPE(Ent) ((Ent).f_fstypename) | ||
68 | # else | ||
69 | # define FS_TYPE(Ent) mnt_names[(Ent).f_type] | ||
70 | # endif | ||
62 | #endif /* MOUNTED_GETFSSTAT */ | 71 | #endif /* MOUNTED_GETFSSTAT */ |
63 | 72 | ||
64 | #ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ | 73 | #ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ |
65 | # include <mntent.h> | 74 | # include <mntent.h> |
66 | # if !defined(MOUNTED) | 75 | # if !defined MOUNTED |
67 | # if defined(MNT_MNTTAB) /* HP-UX. */ | 76 | # if defined _PATH_MOUNTED /* GNU libc */ |
77 | # define MOUNTED _PATH_MOUNTED | ||
78 | # endif | ||
79 | # if defined MNT_MNTTAB /* HP-UX. */ | ||
68 | # define MOUNTED MNT_MNTTAB | 80 | # define MOUNTED MNT_MNTTAB |
69 | # endif | 81 | # endif |
70 | # if defined(MNTTABNAME) /* Dynix. */ | 82 | # if defined MNTTABNAME /* Dynix. */ |
71 | # define MOUNTED MNTTABNAME | 83 | # define MOUNTED MNTTABNAME |
72 | # endif | 84 | # endif |
73 | # endif | 85 | # endif |
@@ -121,12 +133,16 @@ extern int errno; | |||
121 | # include <sys/mntent.h> | 133 | # include <sys/mntent.h> |
122 | #endif | 134 | #endif |
123 | 135 | ||
124 | #if defined (MNTOPT_IGNORE) && defined (HAVE_HASMNTOPT) | 136 | #undef MNT_IGNORE |
137 | #if defined MNTOPT_IGNORE && defined HAVE_HASMNTOPT | ||
125 | # define MNT_IGNORE(M) hasmntopt ((M), MNTOPT_IGNORE) | 138 | # define MNT_IGNORE(M) hasmntopt ((M), MNTOPT_IGNORE) |
126 | #else | 139 | #else |
127 | # define MNT_IGNORE(M) 0 | 140 | # define MNT_IGNORE(M) 0 |
128 | #endif | 141 | #endif |
129 | 142 | ||
143 | #include "mountlist.h" | ||
144 | #include "unlocked-io.h" | ||
145 | |||
130 | #ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ | 146 | #ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ |
131 | /* Return the value of the hexadecimal number represented by CP. | 147 | /* Return the value of the hexadecimal number represented by CP. |
132 | No prefix (like '0x') or suffix (like 'h') is expected to be | 148 | No prefix (like '0x') or suffix (like 'h') is expected to be |
@@ -303,21 +319,22 @@ read_filesystem_list (int need_fs_type) | |||
303 | remove. Specifically, automount create normal NFS mounts. | 319 | remove. Specifically, automount create normal NFS mounts. |
304 | */ | 320 | */ |
305 | 321 | ||
306 | if(listmntent(&mntlist, KMTAB, NULL, NULL) < 0) | 322 | if (listmntent (&mntlist, KMTAB, NULL, NULL) < 0) |
307 | return NULL; | 323 | return NULL; |
308 | for (p = mntlist; p; p = p->next) { | 324 | for (p = mntlist; p; p = p->next) { |
309 | mnt = p->ment; | 325 | mnt = p->ment; |
310 | me = (struct mount_entry*) malloc(sizeof (struct mount_entry)); | 326 | me = xmalloc (sizeof *me); |
311 | me->me_devname = strdup(mnt->mnt_fsname); | 327 | me->me_devname = xstrdup (mnt->mnt_fsname); |
312 | me->me_mountdir = strdup(mnt->mnt_dir); | 328 | me->me_mountdir = xstrdup (mnt->mnt_dir); |
313 | me->me_type = strdup(mnt->mnt_type); | 329 | me->me_type = xstrdup (mnt->mnt_type); |
330 | me->me_type_malloced = 1; | ||
314 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 331 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
315 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 332 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
316 | me->me_dev = -1; | 333 | me->me_dev = -1; |
317 | *mtail = me; | 334 | *mtail = me; |
318 | mtail = &me->me_next; | 335 | mtail = &me->me_next; |
319 | } | 336 | } |
320 | freemntlist(mntlist); | 337 | freemntlist (mntlist); |
321 | } | 338 | } |
322 | #endif | 339 | #endif |
323 | 340 | ||
@@ -334,10 +351,11 @@ read_filesystem_list (int need_fs_type) | |||
334 | 351 | ||
335 | while ((mnt = getmntent (fp))) | 352 | while ((mnt = getmntent (fp))) |
336 | { | 353 | { |
337 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); | 354 | me = xmalloc (sizeof *me); |
338 | me->me_devname = strdup (mnt->mnt_fsname); | 355 | me->me_devname = xstrdup (mnt->mnt_fsname); |
339 | me->me_mountdir = strdup (mnt->mnt_dir); | 356 | me->me_mountdir = xstrdup (mnt->mnt_dir); |
340 | me->me_type = strdup (mnt->mnt_type); | 357 | me->me_type = xstrdup (mnt->mnt_type); |
358 | me->me_type_malloced = 1; | ||
341 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 359 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
342 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 360 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
343 | devopt = strstr (mnt->mnt_opts, "dev="); | 361 | devopt = strstr (mnt->mnt_opts, "dev="); |
@@ -373,10 +391,11 @@ read_filesystem_list (int need_fs_type) | |||
373 | { | 391 | { |
374 | char *fs_type = fsp_to_string (fsp); | 392 | char *fs_type = fsp_to_string (fsp); |
375 | 393 | ||
376 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); | 394 | me = xmalloc (sizeof *me); |
377 | me->me_devname = strdup (fsp->f_mntfromname); | 395 | me->me_devname = xstrdup (fsp->f_mntfromname); |
378 | me->me_mountdir = strdup (fsp->f_mntonname); | 396 | me->me_mountdir = xstrdup (fsp->f_mntonname); |
379 | me->me_type = fs_type; | 397 | me->me_type = fs_type; |
398 | me->me_type_malloced = 0; | ||
380 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 399 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
381 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 400 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
382 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 401 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ |
@@ -398,10 +417,11 @@ read_filesystem_list (int need_fs_type) | |||
398 | 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, | 417 | 0 < (val = getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, |
399 | (char *) 0))) | 418 | (char *) 0))) |
400 | { | 419 | { |
401 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); | 420 | me = xmalloc (sizeof *me); |
402 | me->me_devname = strdup (fsd.fd_req.devname); | 421 | me->me_devname = xstrdup (fsd.fd_req.devname); |
403 | me->me_mountdir = strdup (fsd.fd_req.path); | 422 | me->me_mountdir = xstrdup (fsd.fd_req.path); |
404 | me->me_type = gt_names[fsd.fd_req.fstype]; | 423 | me->me_type = gt_names[fsd.fd_req.fstype]; |
424 | me->me_type_malloced = 0; | ||
405 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 425 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
406 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 426 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
407 | me->me_dev = fsd.fd_req.dev; | 427 | me->me_dev = fsd.fd_req.dev; |
@@ -415,7 +435,7 @@ read_filesystem_list (int need_fs_type) | |||
415 | } | 435 | } |
416 | #endif /* MOUNTED_GETMNT. */ | 436 | #endif /* MOUNTED_GETMNT. */ |
417 | 437 | ||
418 | #if defined (MOUNTED_FS_STAT_DEV) /* BeOS */ | 438 | #if defined MOUNTED_FS_STAT_DEV /* BeOS */ |
419 | { | 439 | { |
420 | /* The next_dev() and fs_stat_dev() system calls give the list of | 440 | /* The next_dev() and fs_stat_dev() system calls give the list of |
421 | all filesystems, including the information returned by statvfs() | 441 | all filesystems, including the information returned by statvfs() |
@@ -458,19 +478,17 @@ read_filesystem_list (int need_fs_type) | |||
458 | continue; | 478 | continue; |
459 | 479 | ||
460 | if (strcmp (d->d_name, ".") == 0) | 480 | if (strcmp (d->d_name, ".") == 0) |
461 | name = strdup ("/"); | 481 | name = xstrdup ("/"); |
462 | else | 482 | else |
463 | { | 483 | { |
464 | name = malloc (1 + strlen (d->d_name) + 1); | 484 | name = xmalloc (1 + strlen (d->d_name) + 1); |
465 | name[0] = '/'; | 485 | name[0] = '/'; |
466 | strcpy (name + 1, d->d_name); | 486 | strcpy (name + 1, d->d_name); |
467 | } | 487 | } |
468 | 488 | ||
469 | if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode)) | 489 | if (lstat (name, &statbuf) >= 0 && S_ISDIR (statbuf.st_mode)) |
470 | { | 490 | { |
471 | struct rootdir_entry *re; | 491 | struct rootdir_entry *re = xmalloc (sizeof *re); |
472 | |||
473 | re = (struct rootdir_entry *) malloc (sizeof (struct rootdir_entry)); | ||
474 | re->name = name; | 492 | re->name = name; |
475 | re->dev = statbuf.st_dev; | 493 | re->dev = statbuf.st_dev; |
476 | re->ino = statbuf.st_ino; | 494 | re->ino = statbuf.st_ino; |
@@ -496,10 +514,11 @@ read_filesystem_list (int need_fs_type) | |||
496 | if (re->dev == fi.dev && re->ino == fi.root) | 514 | if (re->dev == fi.dev && re->ino == fi.root) |
497 | break; | 515 | break; |
498 | 516 | ||
499 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); | 517 | me = xmalloc (sizeof *me); |
500 | me->me_devname = strdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name); | 518 | me->me_devname = xstrdup (fi.device_name[0] != '\0' ? fi.device_name : fi.fsh_name); |
501 | me->me_mountdir = strdup (re != NULL ? re->name : fi.fsh_name); | 519 | me->me_mountdir = xstrdup (re != NULL ? re->name : fi.fsh_name); |
502 | me->me_type = strdup (fi.fsh_name); | 520 | me->me_type = xstrdup (fi.fsh_name); |
521 | me->me_type_malloced = 1; | ||
503 | me->me_dev = fi.dev; | 522 | me->me_dev = fi.dev; |
504 | me->me_dummy = 0; | 523 | me->me_dummy = 0; |
505 | me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; | 524 | me->me_remote = (fi.flags & B_FS_IS_SHARED) != 0; |
@@ -520,18 +539,21 @@ read_filesystem_list (int need_fs_type) | |||
520 | } | 539 | } |
521 | #endif /* MOUNTED_FS_STAT_DEV */ | 540 | #endif /* MOUNTED_FS_STAT_DEV */ |
522 | 541 | ||
523 | #if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */ | 542 | #if defined MOUNTED_GETFSSTAT /* __alpha running OSF_1 */ |
524 | { | 543 | { |
525 | int numsys, counter, bufsize; | 544 | int numsys, counter; |
545 | size_t bufsize; | ||
526 | struct statfs *stats; | 546 | struct statfs *stats; |
527 | 547 | ||
528 | numsys = getfsstat ((struct statfs *)0, 0L, MNT_WAIT); | 548 | numsys = getfsstat ((struct statfs *)0, 0L, MNT_NOWAIT); |
529 | if (numsys < 0) | 549 | if (numsys < 0) |
530 | return (NULL); | 550 | return (NULL); |
551 | if (SIZE_MAX / sizeof *stats <= numsys) | ||
552 | xalloc_die (); | ||
531 | 553 | ||
532 | bufsize = (1 + numsys) * sizeof (struct statfs); | 554 | bufsize = (1 + numsys) * sizeof *stats; |
533 | stats = (struct statfs *)malloc (bufsize); | 555 | stats = xmalloc (bufsize); |
534 | numsys = getfsstat (stats, bufsize, MNT_WAIT); | 556 | numsys = getfsstat (stats, bufsize, MNT_NOWAIT); |
535 | 557 | ||
536 | if (numsys < 0) | 558 | if (numsys < 0) |
537 | { | 559 | { |
@@ -541,10 +563,11 @@ read_filesystem_list (int need_fs_type) | |||
541 | 563 | ||
542 | for (counter = 0; counter < numsys; counter++) | 564 | for (counter = 0; counter < numsys; counter++) |
543 | { | 565 | { |
544 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); | 566 | me = xmalloc (sizeof *me); |
545 | me->me_devname = strdup (stats[counter].f_mntfromname); | 567 | me->me_devname = xstrdup (stats[counter].f_mntfromname); |
546 | me->me_mountdir = strdup (stats[counter].f_mntonname); | 568 | me->me_mountdir = xstrdup (stats[counter].f_mntonname); |
547 | me->me_type = mnt_names[stats[counter].f_type]; | 569 | me->me_type = xstrdup (FS_TYPE (stats[counter])); |
570 | me->me_type_malloced = 1; | ||
548 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 571 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
549 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 572 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
550 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 573 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ |
@@ -558,7 +581,7 @@ read_filesystem_list (int need_fs_type) | |||
558 | } | 581 | } |
559 | #endif /* MOUNTED_GETFSSTAT */ | 582 | #endif /* MOUNTED_GETFSSTAT */ |
560 | 583 | ||
561 | #if defined (MOUNTED_FREAD) || defined (MOUNTED_FREAD_FSTYP) /* SVR[23]. */ | 584 | #if defined MOUNTED_FREAD || defined MOUNTED_FREAD_FSTYP /* SVR[23]. */ |
562 | { | 585 | { |
563 | struct mnttab mnt; | 586 | struct mnttab mnt; |
564 | char *table = "/etc/mnttab"; | 587 | char *table = "/etc/mnttab"; |
@@ -570,17 +593,18 @@ read_filesystem_list (int need_fs_type) | |||
570 | 593 | ||
571 | while (fread (&mnt, sizeof mnt, 1, fp) > 0) | 594 | while (fread (&mnt, sizeof mnt, 1, fp) > 0) |
572 | { | 595 | { |
573 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); | 596 | me = xmalloc (sizeof *me); |
574 | # ifdef GETFSTYP /* SVR3. */ | 597 | # ifdef GETFSTYP /* SVR3. */ |
575 | me->me_devname = strdup (mnt.mt_dev); | 598 | me->me_devname = xstrdup (mnt.mt_dev); |
576 | # else | 599 | # else |
577 | me->me_devname = malloc (strlen (mnt.mt_dev) + 6); | 600 | me->me_devname = xmalloc (strlen (mnt.mt_dev) + 6); |
578 | strcpy (me->me_devname, "/dev/"); | 601 | strcpy (me->me_devname, "/dev/"); |
579 | strcpy (me->me_devname + 5, mnt.mt_dev); | 602 | strcpy (me->me_devname + 5, mnt.mt_dev); |
580 | # endif | 603 | # endif |
581 | me->me_mountdir = strdup (mnt.mt_filsys); | 604 | me->me_mountdir = xstrdup (mnt.mt_filsys); |
582 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 605 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ |
583 | me->me_type = ""; | 606 | me->me_type = ""; |
607 | me->me_type_malloced = 0; | ||
584 | # ifdef GETFSTYP /* SVR3. */ | 608 | # ifdef GETFSTYP /* SVR3. */ |
585 | if (need_fs_type) | 609 | if (need_fs_type) |
586 | { | 610 | { |
@@ -589,7 +613,10 @@ read_filesystem_list (int need_fs_type) | |||
589 | 613 | ||
590 | if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1 | 614 | if (statfs (me->me_mountdir, &fsd, sizeof fsd, 0) != -1 |
591 | && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1) | 615 | && sysfs (GETFSTYP, fsd.f_fstyp, typebuf) != -1) |
592 | me->me_type = strdup (typebuf); | 616 | { |
617 | me->me_type = xstrdup (typebuf); | ||
618 | me->me_type_malloced = 1; | ||
619 | } | ||
593 | } | 620 | } |
594 | # endif | 621 | # endif |
595 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 622 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
@@ -602,6 +629,7 @@ read_filesystem_list (int need_fs_type) | |||
602 | 629 | ||
603 | if (ferror (fp)) | 630 | if (ferror (fp)) |
604 | { | 631 | { |
632 | /* The last fread() call must have failed. */ | ||
605 | int saved_errno = errno; | 633 | int saved_errno = errno; |
606 | fclose (fp); | 634 | fclose (fp); |
607 | errno = saved_errno; | 635 | errno = saved_errno; |
@@ -615,13 +643,14 @@ read_filesystem_list (int need_fs_type) | |||
615 | 643 | ||
616 | #ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */ | 644 | #ifdef MOUNTED_GETMNTTBL /* DolphinOS goes it's own way */ |
617 | { | 645 | { |
618 | struct mntent **mnttbl=getmnttbl(),**ent; | 646 | struct mntent **mnttbl = getmnttbl (), **ent; |
619 | for (ent=mnttbl;*ent;ent++) | 647 | for (ent=mnttbl;*ent;ent++) |
620 | { | 648 | { |
621 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); | 649 | me = xmalloc (sizeof *me); |
622 | me->me_devname = strdup ( (*ent)->mt_resource); | 650 | me->me_devname = xstrdup ( (*ent)->mt_resource); |
623 | me->me_mountdir = strdup( (*ent)->mt_directory); | 651 | me->me_mountdir = xstrdup ( (*ent)->mt_directory); |
624 | me->me_type = strdup ((*ent)->mt_fstype); | 652 | me->me_type = xstrdup ((*ent)->mt_fstype); |
653 | me->me_type_malloced = 1; | ||
625 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); | 654 | me->me_dummy = ME_DUMMY (me->me_devname, me->me_type); |
626 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 655 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
627 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 656 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ |
@@ -630,7 +659,7 @@ read_filesystem_list (int need_fs_type) | |||
630 | *mtail = me; | 659 | *mtail = me; |
631 | mtail = &me->me_next; | 660 | mtail = &me->me_next; |
632 | } | 661 | } |
633 | endmnttbl(); | 662 | endmnttbl (); |
634 | } | 663 | } |
635 | #endif | 664 | #endif |
636 | 665 | ||
@@ -679,10 +708,11 @@ read_filesystem_list (int need_fs_type) | |||
679 | { | 708 | { |
680 | while ((ret = getmntent (fp, &mnt)) == 0) | 709 | while ((ret = getmntent (fp, &mnt)) == 0) |
681 | { | 710 | { |
682 | me = (struct mount_entry *) malloc (sizeof (struct mount_entry)); | 711 | me = xmalloc (sizeof *me); |
683 | me->me_devname = strdup (mnt.mnt_special); | 712 | me->me_devname = xstrdup (mnt.mnt_special); |
684 | me->me_mountdir = strdup (mnt.mnt_mountp); | 713 | me->me_mountdir = xstrdup (mnt.mnt_mountp); |
685 | me->me_type = strdup (mnt.mnt_fstype); | 714 | me->me_type = xstrdup (mnt.mnt_fstype); |
715 | me->me_type_malloced = 1; | ||
686 | me->me_dummy = MNT_IGNORE (&mnt) != 0; | 716 | me->me_dummy = MNT_IGNORE (&mnt) != 0; |
687 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); | 717 | me->me_remote = ME_REMOTE (me->me_devname, me->me_type); |
688 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ | 718 | me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ |
@@ -711,21 +741,32 @@ read_filesystem_list (int need_fs_type) | |||
711 | int bufsize; | 741 | int bufsize; |
712 | char *entries, *thisent; | 742 | char *entries, *thisent; |
713 | struct vmount *vmp; | 743 | struct vmount *vmp; |
744 | int n_entries; | ||
745 | int i; | ||
714 | 746 | ||
715 | /* Ask how many bytes to allocate for the mounted filesystem info. */ | 747 | /* Ask how many bytes to allocate for the mounted filesystem info. */ |
716 | mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize); | 748 | if (mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize) != 0) |
717 | entries = malloc (bufsize); | 749 | return NULL; |
750 | entries = xmalloc (bufsize); | ||
718 | 751 | ||
719 | /* Get the list of mounted filesystems. */ | 752 | /* Get the list of mounted filesystems. */ |
720 | mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); | 753 | n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); |
754 | if (n_entries < 0) | ||
755 | { | ||
756 | int saved_errno = errno; | ||
757 | free (entries); | ||
758 | errno = saved_errno; | ||
759 | return NULL; | ||
760 | } | ||
721 | 761 | ||
722 | for (thisent = entries; thisent < entries + bufsize; | 762 | for (i = 0, thisent = entries; |
723 | thisent += vmp->vmt_length) | 763 | i < n_entries; |
764 | i++, thisent += vmp->vmt_length) | ||
724 | { | 765 | { |
725 | char *options, *ignore; | 766 | char *options, *ignore; |
726 | 767 | ||
727 | vmp = (struct vmount *) thisent; | 768 | vmp = (struct vmount *) thisent; |
728 | me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry)); | 769 | me = xmalloc (sizeof *me); |
729 | if (vmp->vmt_flags & MNT_REMOTE) | 770 | if (vmp->vmt_flags & MNT_REMOTE) |
730 | { | 771 | { |
731 | char *host, *path; | 772 | char *host, *path; |
@@ -734,7 +775,7 @@ read_filesystem_list (int need_fs_type) | |||
734 | /* Prepend the remote pathname. */ | 775 | /* Prepend the remote pathname. */ |
735 | host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; | 776 | host = thisent + vmp->vmt_data[VMT_HOSTNAME].vmt_off; |
736 | path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; | 777 | path = thisent + vmp->vmt_data[VMT_OBJECT].vmt_off; |
737 | me->me_devname = malloc (strlen (host) + strlen (path) + 2); | 778 | me->me_devname = xmalloc (strlen (host) + strlen (path) + 2); |
738 | strcpy (me->me_devname, host); | 779 | strcpy (me->me_devname, host); |
739 | strcat (me->me_devname, ":"); | 780 | strcat (me->me_devname, ":"); |
740 | strcat (me->me_devname, path); | 781 | strcat (me->me_devname, path); |
@@ -742,11 +783,12 @@ read_filesystem_list (int need_fs_type) | |||
742 | else | 783 | else |
743 | { | 784 | { |
744 | me->me_remote = 0; | 785 | me->me_remote = 0; |
745 | me->me_devname = strdup (thisent + | 786 | me->me_devname = xstrdup (thisent + |
746 | vmp->vmt_data[VMT_OBJECT].vmt_off); | 787 | vmp->vmt_data[VMT_OBJECT].vmt_off); |
747 | } | 788 | } |
748 | me->me_mountdir = strdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); | 789 | me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off); |
749 | me->me_type = strdup (fstype_to_string (vmp->vmt_gfstype)); | 790 | me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype)); |
791 | me->me_type_malloced = 1; | ||
750 | options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; | 792 | options = thisent + vmp->vmt_data[VMT_ARGS].vmt_off; |
751 | ignore = strstr (options, "ignore"); | 793 | ignore = strstr (options, "ignore"); |
752 | me->me_dummy = (ignore | 794 | me->me_dummy = (ignore |
@@ -777,7 +819,8 @@ read_filesystem_list (int need_fs_type) | |||
777 | me = mount_list->me_next; | 819 | me = mount_list->me_next; |
778 | free (mount_list->me_devname); | 820 | free (mount_list->me_devname); |
779 | free (mount_list->me_mountdir); | 821 | free (mount_list->me_mountdir); |
780 | /* FIXME: me_type is not always malloced. */ | 822 | if (mount_list->me_type_malloced) |
823 | free (mount_list->me_type); | ||
781 | free (mount_list); | 824 | free (mount_list); |
782 | mount_list = me; | 825 | mount_list = me; |
783 | } | 826 | } |
diff --git a/lib/mountlist.h b/lib/mountlist.h index c41490c9..9e550a08 100644 --- a/lib/mountlist.h +++ b/lib/mountlist.h | |||
@@ -1,5 +1,7 @@ | |||
1 | /* mountlist.h -- declarations for list of mounted filesystems | 1 | /* mountlist.h -- declarations for list of mounted filesystems |
2 | Copyright (C) 1991, 1992, 1998, 2000 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 1991, 1992, 1998, 2000, 2001, 2002, 2003 Free | ||
4 | Software Foundation, Inc. | ||
3 | 5 | ||
4 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -24,27 +26,28 @@ struct mount_entry | |||
24 | dev_t me_dev; /* Device number of me_mountdir. */ | 26 | dev_t me_dev; /* Device number of me_mountdir. */ |
25 | unsigned int me_dummy : 1; /* Nonzero for dummy filesystems. */ | 27 | unsigned int me_dummy : 1; /* Nonzero for dummy filesystems. */ |
26 | unsigned int me_remote : 1; /* Nonzero for remote fileystems. */ | 28 | unsigned int me_remote : 1; /* Nonzero for remote fileystems. */ |
29 | unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */ | ||
27 | struct mount_entry *me_next; | 30 | struct mount_entry *me_next; |
28 | }; | 31 | }; |
29 | 32 | ||
30 | #ifndef PARAMS | 33 | struct mount_entry *read_filesystem_list (int need_fs_type); |
31 | # if defined PROTOTYPES || (defined __STDC__ && __STDC__) | ||
32 | # define PARAMS(Args) Args | ||
33 | # else | ||
34 | # define PARAMS(Args) () | ||
35 | # endif | ||
36 | #endif | ||
37 | |||
38 | struct mount_entry *read_filesystem_list PARAMS ((int need_fs_type)); | ||
39 | 34 | ||
40 | #ifndef ME_DUMMY | 35 | #ifndef ME_DUMMY |
41 | # define ME_DUMMY(fs_name, fs_type) \ | 36 | # define ME_DUMMY(Fs_name, Fs_type) \ |
42 | (!strcmp (fs_type, "auto") \ | 37 | (!strcmp (Fs_type, "autofs") \ |
43 | || !strcmp (fs_type, "autofs") \ | ||
44 | /* for Irix 6.5 */ \ | 38 | /* for Irix 6.5 */ \ |
45 | || !strcmp (fs_type, "ignore")) | 39 | || !strcmp (Fs_type, "ignore")) |
46 | #endif | 40 | #endif |
47 | 41 | ||
42 | #undef STREQ | ||
43 | #define STREQ(a, b) (strcmp ((a), (b)) == 0) | ||
44 | |||
48 | #ifndef ME_REMOTE | 45 | #ifndef ME_REMOTE |
49 | # define ME_REMOTE(fs_name, fs_type) (strchr (fs_name, ':') != 0) | 46 | /* A file system is `remote' if its Fs_name contains a `:' |
47 | or if (it is of type smbfs and its Fs_name starts with `//'). */ | ||
48 | # define ME_REMOTE(Fs_name, Fs_type) \ | ||
49 | (strchr ((Fs_name), ':') != 0 \ | ||
50 | || ((Fs_name)[0] == '/' \ | ||
51 | && (Fs_name)[1] == '/' \ | ||
52 | && STREQ (Fs_type, "smbfs"))) | ||
50 | #endif | 53 | #endif |
diff --git a/lib/onceonly.m4 b/lib/onceonly.m4 new file mode 100644 index 00000000..50b33f48 --- /dev/null +++ b/lib/onceonly.m4 | |||
@@ -0,0 +1,63 @@ | |||
1 | # onceonly.m4 serial 3 (gettext-0.12) | ||
2 | dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc. | ||
3 | dnl This file is free software, distributed under the terms of the GNU | ||
4 | dnl General Public License. As a special exception to the GNU General | ||
5 | dnl Public License, this file may be distributed as part of a program | ||
6 | dnl that contains a configuration script generated by Autoconf, under | ||
7 | dnl the same distribution terms as the rest of that program. | ||
8 | |||
9 | dnl This file defines some "once only" variants of standard autoconf macros. | ||
10 | dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS | ||
11 | dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS | ||
12 | dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS | ||
13 | dnl AC_REQUIRE([AC_HEADER_STDC]) like AC_HEADER_STDC | ||
14 | dnl The advantage is that the check for each of the headers/functions/decls | ||
15 | dnl will be put only once into the 'configure' file. It keeps the size of | ||
16 | dnl the 'configure' file down, and avoids redundant output when 'configure' | ||
17 | dnl is run. | ||
18 | dnl The drawback is that the checks cannot be conditionalized. If you write | ||
19 | dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi | ||
20 | dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to | ||
21 | dnl empty, and the check will be inserted before the body of the AC_DEFUNed | ||
22 | dnl function. | ||
23 | |||
24 | dnl Autoconf version 2.57 or newer is recommended. | ||
25 | AC_PREREQ(2.54) | ||
26 | |||
27 | # AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of | ||
28 | # AC_CHECK_HEADERS(HEADER1 HEADER2 ...). | ||
29 | AC_DEFUN([AC_CHECK_HEADERS_ONCE], [ | ||
30 | : | ||
31 | AC_FOREACH([gl_HEADER_NAME], [$1], [ | ||
32 | AC_DEFUN([gl_CHECK_HEADER_]m4_quote(translit(m4_defn([gl_HEADER_NAME]), | ||
33 | [-./], [___])), [ | ||
34 | AC_CHECK_HEADERS(gl_HEADER_NAME) | ||
35 | ]) | ||
36 | AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME, | ||
37 | [-./], [___]))) | ||
38 | ]) | ||
39 | ]) | ||
40 | |||
41 | # AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of | ||
42 | # AC_CHECK_FUNCS(FUNC1 FUNC2 ...). | ||
43 | AC_DEFUN([AC_CHECK_FUNCS_ONCE], [ | ||
44 | : | ||
45 | AC_FOREACH([gl_FUNC_NAME], [$1], [ | ||
46 | AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [ | ||
47 | AC_CHECK_FUNCS(m4_defn([gl_FUNC_NAME])) | ||
48 | ]) | ||
49 | AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME])) | ||
50 | ]) | ||
51 | ]) | ||
52 | |||
53 | # AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of | ||
54 | # AC_CHECK_DECLS(DECL1, DECL2, ...). | ||
55 | AC_DEFUN([AC_CHECK_DECLS_ONCE], [ | ||
56 | : | ||
57 | AC_FOREACH([gl_DECL_NAME], [$1], [ | ||
58 | AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [ | ||
59 | AC_CHECK_DECLS(m4_defn([gl_DECL_NAME])) | ||
60 | ]) | ||
61 | AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME])) | ||
62 | ]) | ||
63 | ]) | ||
diff --git a/lib/realloc.c b/lib/realloc.c index d0d3e4ab..ccbf9913 100644 --- a/lib/realloc.c +++ b/lib/realloc.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Work around bug on some systems where realloc (NULL, 0) fails. | 1 | /* Work around bug on some systems where realloc (NULL, 0) fails. |
2 | Copyright (C) 1997 Free Software Foundation, Inc. | 2 | Copyright (C) 1997, 2003 Free Software Foundation, Inc. |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify | 4 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
@@ -22,19 +22,14 @@ | |||
22 | #endif | 22 | #endif |
23 | #undef realloc | 23 | #undef realloc |
24 | 24 | ||
25 | #include <sys/types.h> | 25 | #include <stdlib.h> |
26 | |||
27 | char *malloc (); | ||
28 | char *realloc (); | ||
29 | 26 | ||
30 | /* Change the size of an allocated block of memory P to N bytes, | 27 | /* Change the size of an allocated block of memory P to N bytes, |
31 | with error checking. If N is zero, change it to 1. If P is NULL, | 28 | with error checking. If N is zero, change it to 1. If P is NULL, |
32 | use malloc. */ | 29 | use malloc. */ |
33 | 30 | ||
34 | char * | 31 | void * |
35 | rpl_realloc (p, n) | 32 | rpl_realloc (void *p, size_t n) |
36 | char *p; | ||
37 | size_t n; | ||
38 | { | 33 | { |
39 | if (n == 0) | 34 | if (n == 0) |
40 | n = 1; | 35 | n = 1; |
diff --git a/lib/snprintf.c b/lib/snprintf.c index 3de2a96f..633517de 100644 --- a/lib/snprintf.c +++ b/lib/snprintf.c | |||
@@ -1,4 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * NOTE: If you change this file, please merge it into rsync, samba, etc. | ||
3 | */ | ||
4 | |||
5 | /* | ||
2 | * Copyright Patrick Powell 1995 | 6 | * Copyright Patrick Powell 1995 |
3 | * This code is based on code written by Patrick Powell (papowell@astart.com) | 7 | * This code is based on code written by Patrick Powell (papowell@astart.com) |
4 | * It may be used for any purpose as long as this notice remains intact | 8 | * It may be used for any purpose as long as this notice remains intact |
@@ -53,17 +57,57 @@ | |||
53 | * got rid of fcvt code (twas buggy and made testing harder) | 57 | * got rid of fcvt code (twas buggy and made testing harder) |
54 | * added C99 semantics | 58 | * added C99 semantics |
55 | * | 59 | * |
60 | * date: 2002/12/19 19:56:31; author: herb; state: Exp; lines: +2 -0 | ||
61 | * actually print args for %g and %e | ||
62 | * | ||
63 | * date: 2002/06/03 13:37:52; author: jmcd; state: Exp; lines: +8 -0 | ||
64 | * Since includes.h isn't included here, VA_COPY has to be defined here. I don't | ||
65 | * see any include file that is guaranteed to be here, so I'm defining it | ||
66 | * locally. Fixes AIX and Solaris builds. | ||
67 | * | ||
68 | * date: 2002/06/03 03:07:24; author: tridge; state: Exp; lines: +5 -13 | ||
69 | * put the ifdef for HAVE_VA_COPY in one place rather than in lots of | ||
70 | * functions | ||
71 | * | ||
72 | * date: 2002/05/17 14:51:22; author: jmcd; state: Exp; lines: +21 -4 | ||
73 | * Fix usage of va_list passed as an arg. Use __va_copy before using it | ||
74 | * when it exists. | ||
75 | * | ||
76 | * date: 2002/04/16 22:38:04; author: idra; state: Exp; lines: +20 -14 | ||
77 | * Fix incorrect zpadlen handling in fmtfp. | ||
78 | * Thanks to Ollie Oldham <ollie.oldham@metro-optix.com> for spotting it. | ||
79 | * few mods to make it easier to compile the tests. | ||
80 | * addedd the "Ollie" test to the floating point ones. | ||
81 | * | ||
82 | * Martin Pool (mbp@samba.org) April 2003 | ||
83 | * Remove NO_CONFIG_H so that the test case can be built within a source | ||
84 | * tree with less trouble. | ||
85 | * Remove unnecessary SAFE_FREE() definition. | ||
86 | * | ||
87 | * Martin Pool (mbp@samba.org) May 2003 | ||
88 | * Put in a prototype for dummy_snprintf() to quiet compiler warnings. | ||
89 | * | ||
90 | * Move #endif to make sure VA_COPY, LDOUBLE, etc are defined even | ||
91 | * if the C library has some snprintf functions already. | ||
56 | **************************************************************/ | 92 | **************************************************************/ |
57 | 93 | ||
58 | #ifndef NO_CONFIG_H /* for some tests */ | 94 | #ifndef NO_CONFIG_H |
59 | #include "config.h" | 95 | #include "config.h" |
60 | #else | 96 | #else |
61 | #define NULL 0 | 97 | #define NULL 0 |
62 | #endif | 98 | #endif |
63 | 99 | ||
64 | #ifdef TEST_SNPRINTF /* need math library headers for testing */ | 100 | #ifdef TEST_SNPRINTF /* need math library headers for testing */ |
65 | #include <math.h> | 101 | |
66 | #endif | 102 | /* In test mode, we pretend that this system doesn't have any snprintf |
103 | * functions, regardless of what config.h says. */ | ||
104 | # undef HAVE_SNPRINTF | ||
105 | # undef HAVE_VSNPRINTF | ||
106 | # undef HAVE_C99_VSNPRINTF | ||
107 | # undef HAVE_ASPRINTF | ||
108 | # undef HAVE_VASPRINTF | ||
109 | # include <math.h> | ||
110 | #endif /* TEST_SNPRINTF */ | ||
67 | 111 | ||
68 | #ifdef HAVE_STRING_H | 112 | #ifdef HAVE_STRING_H |
69 | #include <string.h> | 113 | #include <string.h> |
@@ -75,12 +119,8 @@ | |||
75 | #ifdef HAVE_CTYPE_H | 119 | #ifdef HAVE_CTYPE_H |
76 | #include <ctype.h> | 120 | #include <ctype.h> |
77 | #endif | 121 | #endif |
78 | #ifdef HAVE_SYS_TYPES_H | ||
79 | #include <sys/types.h> | 122 | #include <sys/types.h> |
80 | #endif | ||
81 | #ifdef HAVE_STDARG_H | ||
82 | #include <stdarg.h> | 123 | #include <stdarg.h> |
83 | #endif | ||
84 | #ifdef HAVE_STDLIB_H | 124 | #ifdef HAVE_STDLIB_H |
85 | #include <stdlib.h> | 125 | #include <stdlib.h> |
86 | #endif | 126 | #endif |
@@ -89,8 +129,9 @@ | |||
89 | /* only include stdio.h if we are not re-defining snprintf or vsnprintf */ | 129 | /* only include stdio.h if we are not re-defining snprintf or vsnprintf */ |
90 | #include <stdio.h> | 130 | #include <stdio.h> |
91 | /* make the compiler happy with an empty file */ | 131 | /* make the compiler happy with an empty file */ |
132 | void dummy_snprintf(void); | ||
92 | void dummy_snprintf(void) {} | 133 | void dummy_snprintf(void) {} |
93 | #else | 134 | #endif /* HAVE_SNPRINTF, etc */ |
94 | 135 | ||
95 | #ifdef HAVE_LONG_DOUBLE | 136 | #ifdef HAVE_LONG_DOUBLE |
96 | #define LDOUBLE long double | 137 | #define LDOUBLE long double |
@@ -104,29 +145,17 @@ | |||
104 | #define LLONG long | 145 | #define LLONG long |
105 | #endif | 146 | #endif |
106 | 147 | ||
107 | /* free memory if the pointer is valid and zero the pointer */ | ||
108 | #ifndef SAFE_FREE | ||
109 | #define SAFE_FREE(x) do { if ((x) != NULL) {free((x)); (x)=NULL;} } while(0) | ||
110 | #endif | ||
111 | |||
112 | #ifndef VA_COPY | 148 | #ifndef VA_COPY |
113 | #ifdef HAVE_VA_COPY | 149 | #ifdef HAVE_VA_COPY |
150 | #define VA_COPY(dest, src) va_copy(dest, src) | ||
151 | #else | ||
152 | #ifdef HAVE___VA_COPY | ||
114 | #define VA_COPY(dest, src) __va_copy(dest, src) | 153 | #define VA_COPY(dest, src) __va_copy(dest, src) |
115 | #else | 154 | #else |
116 | #define VA_COPY(dest, src) (dest) = (src) | 155 | #define VA_COPY(dest, src) (dest) = (src) |
117 | #endif | 156 | #endif |
118 | #endif | 157 | #endif |
119 | 158 | ||
120 | static size_t dopr(char *buffer, size_t maxlen, const char *format, | ||
121 | va_list args_in); | ||
122 | static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, | ||
123 | char *value, int flags, int min, int max); | ||
124 | static void fmtint(char *buffer, size_t *currlen, size_t maxlen, | ||
125 | long value, int base, int min, int max, int flags); | ||
126 | static void fmtfp(char *buffer, size_t *currlen, size_t maxlen, | ||
127 | LDOUBLE fvalue, int min, int max, int flags); | ||
128 | static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c); | ||
129 | |||
130 | /* | 159 | /* |
131 | * dopr(): poor man's version of doprintf | 160 | * dopr(): poor man's version of doprintf |
132 | */ | 161 | */ |
@@ -161,6 +190,19 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c); | |||
161 | #define MAX(p,q) (((p) >= (q)) ? (p) : (q)) | 190 | #define MAX(p,q) (((p) >= (q)) ? (p) : (q)) |
162 | #endif | 191 | #endif |
163 | 192 | ||
193 | /* yes this really must be a ||. Don't muck with this (tridge) */ | ||
194 | #if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF) | ||
195 | |||
196 | static size_t dopr(char *buffer, size_t maxlen, const char *format, | ||
197 | va_list args_in); | ||
198 | static void fmtstr(char *buffer, size_t *currlen, size_t maxlen, | ||
199 | char *value, int flags, int min, int max); | ||
200 | static void fmtint(char *buffer, size_t *currlen, size_t maxlen, | ||
201 | long value, int base, int min, int max, int flags); | ||
202 | static void fmtfp(char *buffer, size_t *currlen, size_t maxlen, | ||
203 | LDOUBLE fvalue, int min, int max, int flags); | ||
204 | static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c); | ||
205 | |||
164 | static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | 206 | static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) |
165 | { | 207 | { |
166 | char ch; | 208 | char ch; |
@@ -345,6 +387,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
345 | fvalue = va_arg (args, LDOUBLE); | 387 | fvalue = va_arg (args, LDOUBLE); |
346 | else | 388 | else |
347 | fvalue = va_arg (args, double); | 389 | fvalue = va_arg (args, double); |
390 | fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); | ||
348 | break; | 391 | break; |
349 | case 'G': | 392 | case 'G': |
350 | flags |= DP_F_UP; | 393 | flags |= DP_F_UP; |
@@ -353,6 +396,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args | |||
353 | fvalue = va_arg (args, LDOUBLE); | 396 | fvalue = va_arg (args, LDOUBLE); |
354 | else | 397 | else |
355 | fvalue = va_arg (args, double); | 398 | fvalue = va_arg (args, double); |
399 | fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags); | ||
356 | break; | 400 | break; |
357 | case 'c': | 401 | case 'c': |
358 | dopr_outch (buffer, &currlen, maxlen, va_arg (args, int)); | 402 | dopr_outch (buffer, &currlen, maxlen, va_arg (args, int)); |
@@ -625,7 +669,7 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, | |||
625 | int padlen = 0; /* amount to pad */ | 669 | int padlen = 0; /* amount to pad */ |
626 | int zpadlen = 0; | 670 | int zpadlen = 0; |
627 | int caps = 0; | 671 | int caps = 0; |
628 | int index; | 672 | int idx; |
629 | double intpart; | 673 | double intpart; |
630 | double fracpart; | 674 | double fracpart; |
631 | double temp; | 675 | double temp; |
@@ -684,11 +728,11 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, | |||
684 | do { | 728 | do { |
685 | temp = intpart*0.1; | 729 | temp = intpart*0.1; |
686 | my_modf(temp, &intpart); | 730 | my_modf(temp, &intpart); |
687 | index = (int) ((temp -intpart +0.05)* 10.0); | 731 | idx = (int) ((temp -intpart +0.05)* 10.0); |
688 | /* index = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */ | 732 | /* idx = (int) (((double)(temp*0.1) -intpart +0.05) *10.0); */ |
689 | /* printf ("%llf, %f, %x\n", temp, intpart, index); */ | 733 | /* printf ("%llf, %f, %x\n", temp, intpart, idx); */ |
690 | iconvert[iplace++] = | 734 | iconvert[iplace++] = |
691 | (caps? "0123456789ABCDEF":"0123456789abcdef")[index]; | 735 | (caps? "0123456789ABCDEF":"0123456789abcdef")[idx]; |
692 | } while (intpart && (iplace < 311)); | 736 | } while (intpart && (iplace < 311)); |
693 | if (iplace == 311) iplace--; | 737 | if (iplace == 311) iplace--; |
694 | iconvert[iplace] = 0; | 738 | iconvert[iplace] = 0; |
@@ -699,11 +743,11 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen, | |||
699 | do { | 743 | do { |
700 | temp = fracpart*0.1; | 744 | temp = fracpart*0.1; |
701 | my_modf(temp, &fracpart); | 745 | my_modf(temp, &fracpart); |
702 | index = (int) ((temp -fracpart +0.05)* 10.0); | 746 | idx = (int) ((temp -fracpart +0.05)* 10.0); |
703 | /* index = (int) ((((temp/10) -fracpart) +0.05) *10); */ | 747 | /* idx = (int) ((((temp/10) -fracpart) +0.05) *10); */ |
704 | /* printf ("%lf, %lf, %ld\n", temp, fracpart, index); */ | 748 | /* printf ("%lf, %lf, %ld\n", temp, fracpart, idx ); */ |
705 | fconvert[fplace++] = | 749 | fconvert[fplace++] = |
706 | (caps? "0123456789ABCDEF":"0123456789abcdef")[index]; | 750 | (caps? "0123456789ABCDEF":"0123456789abcdef")[idx]; |
707 | } while(fracpart && (fplace < 311)); | 751 | } while(fracpart && (fplace < 311)); |
708 | if (fplace == 311) fplace--; | 752 | if (fplace == 311) fplace--; |
709 | } | 753 | } |
@@ -773,24 +817,21 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) | |||
773 | (*currlen)++; | 817 | (*currlen)++; |
774 | } | 818 | } |
775 | 819 | ||
776 | /* yes this really must be a ||. Don't muck with this (tridge) */ | 820 | int smb_vsnprintf (char *str, size_t count, const char *fmt, va_list args) |
777 | #if !defined(HAVE_VSNPRINTF) || !defined(HAVE_C99_VSNPRINTF) | ||
778 | int vsnprintf (char *str, size_t count, const char *fmt, va_list args) | ||
779 | { | 821 | { |
780 | return dopr(str, count, fmt, args); | 822 | return dopr(str, count, fmt, args); |
781 | } | 823 | } |
824 | #define vsnprintf smb_vsnprintf | ||
782 | #endif | 825 | #endif |
783 | 826 | ||
784 | /* yes this really must be a ||. Don't muck wiith this (tridge) | 827 | /* yes this really must be a ||. Don't muck with this (tridge) |
785 | * | 828 | * |
786 | * The logic for these two is that we need our own definition if the | 829 | * The logic for these two is that we need our own definition if the |
787 | * OS *either* has no definition of *sprintf, or if it does have one | 830 | * OS *either* has no definition of *sprintf, or if it does have one |
788 | * that doesn't work properly according to the autoconf test. Perhaps | 831 | * that doesn't work properly according to the autoconf test. |
789 | * these should really be smb_snprintf to avoid conflicts with buggy | ||
790 | * linkers? -- mbp | ||
791 | */ | 832 | */ |
792 | #if !defined(HAVE_SNPRINTF) /* || !defined(HAVE_C99_SNPRINTF) */ | 833 | #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF) |
793 | int snprintf(char *str,size_t count,const char *fmt,...) | 834 | int smb_snprintf(char *str,size_t count,const char *fmt,...) |
794 | { | 835 | { |
795 | size_t ret; | 836 | size_t ret; |
796 | va_list ap; | 837 | va_list ap; |
@@ -800,6 +841,7 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) | |||
800 | va_end(ap); | 841 | va_end(ap); |
801 | return ret; | 842 | return ret; |
802 | } | 843 | } |
844 | #define snprintf smb_snprintf | ||
803 | #endif | 845 | #endif |
804 | 846 | ||
805 | #endif | 847 | #endif |
@@ -868,8 +910,9 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) | |||
868 | "-16.16f", | 910 | "-16.16f", |
869 | NULL | 911 | NULL |
870 | }; | 912 | }; |
871 | double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996, | 913 | double fp_nums[] = { 6442452944.1234, -1.5, 134.21, 91340.2, 341.1234, 203.9, 0.96, 0.996, |
872 | 0.9996, 1.996, 4.136, 5.030201, 0}; | 914 | 0.9996, 1.996, 4.136, 5.030201, 0.00205, |
915 | /* END LIST */ 0}; | ||
873 | char *int_fmt[] = { | 916 | char *int_fmt[] = { |
874 | "%-1.5d", | 917 | "%-1.5d", |
875 | "%1.5d", | 918 | "%1.5d", |
@@ -977,4 +1020,4 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) | |||
977 | 1020 | ||
978 | return 0; | 1021 | return 0; |
979 | } | 1022 | } |
980 | #endif /* SNPRINTF_TEST */ | 1023 | #endif /* TEST_SNPRINTF */ |
diff --git a/lib/strtod.c b/lib/strtod.c index 10edb5cf..161f97a7 100644 --- a/lib/strtod.c +++ b/lib/strtod.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* Copyright (C) 1991, 1992, 1997, 1999 Free Software Foundation, Inc. | 1 | /* Copyright (C) 1991, 1992, 1997, 1999, 2003 Free Software Foundation, Inc. |
2 | 2 | ||
3 | This program is free software; you can redistribute it and/or modify | 3 | This program is free software; you can redistribute it and/or modify |
4 | it under the terms of the GNU General Public License as published by | 4 | it under the terms of the GNU General Public License as published by |
@@ -37,22 +37,9 @@ extern int errno; | |||
37 | 37 | ||
38 | #include <math.h> | 38 | #include <math.h> |
39 | 39 | ||
40 | #if HAVE_FLOAT_H | 40 | #include <float.h> |
41 | # include <float.h> | 41 | #include <stdlib.h> |
42 | #else | 42 | #include <string.h> |
43 | # define DBL_MAX 1.7976931348623159e+308 | ||
44 | # define DBL_MIN 2.2250738585072010e-308 | ||
45 | #endif | ||
46 | |||
47 | #if STDC_HEADERS | ||
48 | # include <stdlib.h> | ||
49 | # include <string.h> | ||
50 | #else | ||
51 | # define NULL 0 | ||
52 | # ifndef HUGE_VAL | ||
53 | # define HUGE_VAL HUGE | ||
54 | # endif | ||
55 | #endif | ||
56 | 43 | ||
57 | /* Convert NPTR to a double. If ENDPTR is not NULL, a pointer to the | 44 | /* Convert NPTR to a double. If ENDPTR is not NULL, a pointer to the |
58 | character after the last one used in the number is put in *ENDPTR. */ | 45 | character after the last one used in the number is put in *ENDPTR. */ |
diff --git a/lib/unlocked-io.h b/lib/unlocked-io.h index a7240fb9..36a7a488 100644 --- a/lib/unlocked-io.h +++ b/lib/unlocked-io.h | |||
@@ -1,21 +1,20 @@ | |||
1 | /* Prefer faster, non-thread-safe stdio functions if available. | 1 | /* Prefer faster, non-thread-safe stdio functions if available. |
2 | 2 | ||
3 | Copyright (C) 2001, 2002 Free Software Foundation, Inc. | 3 | Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify it | 5 | This program is free software; you can redistribute it and/or modify |
6 | under the terms of the GNU Library General Public License as published | 6 | it under the terms of the GNU General Public License as published by |
7 | by the Free Software Foundation; either version 2, or (at your option) | 7 | the Free Software Foundation; either version 2, or (at your option) |
8 | any later version. | 8 | any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | Library General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public | 15 | You should have received a copy of the GNU General Public License along |
16 | License along with this program; if not, write to the Free Software | 16 | with this program; if not, write to the Free Software Foundation, |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | 17 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
18 | USA. */ | ||
19 | 18 | ||
20 | /* Written by Jim Meyering. */ | 19 | /* Written by Jim Meyering. */ |
21 | 20 | ||
@@ -28,63 +27,106 @@ | |||
28 | 27 | ||
29 | # if USE_UNLOCKED_IO | 28 | # if USE_UNLOCKED_IO |
30 | 29 | ||
31 | /* These are wrappers for functions/macros from GNU libc. | 30 | /* These are wrappers for functions/macros from the GNU C library, and |
31 | from other C libraries supporting POSIX's optional thread-safe functions. | ||
32 | |||
32 | The standard I/O functions are thread-safe. These *_unlocked ones are | 33 | The standard I/O functions are thread-safe. These *_unlocked ones are |
33 | more efficient but not thread-safe. That they're not thread-safe is | 34 | more efficient but not thread-safe. That they're not thread-safe is |
34 | fine since all of the applications in this package are single threaded. */ | 35 | fine since all of the applications in this package are single threaded. |
36 | |||
37 | Also, some code that is shared with the GNU C library may invoke | ||
38 | the *_unlocked functions directly. On hosts that lack those | ||
39 | functions, invoke the non-thread-safe versions instead. */ | ||
40 | |||
41 | # include <stdio.h> | ||
35 | 42 | ||
36 | # if HAVE_DECL_CLEARERR_UNLOCKED | 43 | # if HAVE_DECL_CLEARERR_UNLOCKED |
37 | # undef clearerr | 44 | # undef clearerr |
38 | # define clearerr(x) clearerr_unlocked (x) | 45 | # define clearerr(x) clearerr_unlocked (x) |
46 | # else | ||
47 | # define clearerr_unlocked(x) clearerr (x) | ||
39 | # endif | 48 | # endif |
40 | # if HAVE_DECL_FEOF_UNLOCKED | 49 | # if HAVE_DECL_FEOF_UNLOCKED |
41 | # undef feof | 50 | # undef feof |
42 | # define feof(x) feof_unlocked (x) | 51 | # define feof(x) feof_unlocked (x) |
52 | # else | ||
53 | # define feof_unlocked(x) feof (x) | ||
43 | # endif | 54 | # endif |
44 | # if HAVE_DECL_FERROR_UNLOCKED | 55 | # if HAVE_DECL_FERROR_UNLOCKED |
45 | # undef ferror | 56 | # undef ferror |
46 | # define ferror(x) ferror_unlocked (x) | 57 | # define ferror(x) ferror_unlocked (x) |
58 | # else | ||
59 | # define ferror_unlocked(x) ferror (x) | ||
47 | # endif | 60 | # endif |
48 | # if HAVE_DECL_FFLUSH_UNLOCKED | 61 | # if HAVE_DECL_FFLUSH_UNLOCKED |
49 | # undef fflush | 62 | # undef fflush |
50 | # define fflush(x) fflush_unlocked (x) | 63 | # define fflush(x) fflush_unlocked (x) |
64 | # else | ||
65 | # define fflush_unlocked(x) fflush (x) | ||
51 | # endif | 66 | # endif |
52 | # if HAVE_DECL_FGETS_UNLOCKED | 67 | # if HAVE_DECL_FGETS_UNLOCKED |
53 | # undef fgets | 68 | # undef fgets |
54 | # define fgets(x,y,z) fgets_unlocked (x,y,z) | 69 | # define fgets(x,y,z) fgets_unlocked (x,y,z) |
70 | # else | ||
71 | # define fgets_unlocked(x,y,z) fgets (x,y,z) | ||
55 | # endif | 72 | # endif |
56 | # if HAVE_DECL_FPUTC_UNLOCKED | 73 | # if HAVE_DECL_FPUTC_UNLOCKED |
57 | # undef fputc | 74 | # undef fputc |
58 | # define fputc(x,y) fputc_unlocked (x,y) | 75 | # define fputc(x,y) fputc_unlocked (x,y) |
76 | # else | ||
77 | # define fputc_unlocked(x,y) fputc (x,y) | ||
59 | # endif | 78 | # endif |
60 | # if HAVE_DECL_FPUTS_UNLOCKED | 79 | # if HAVE_DECL_FPUTS_UNLOCKED |
61 | # undef fputs | 80 | # undef fputs |
62 | # define fputs(x,y) fputs_unlocked (x,y) | 81 | # define fputs(x,y) fputs_unlocked (x,y) |
82 | # else | ||
83 | # define fputs_unlocked(x,y) fputs (x,y) | ||
63 | # endif | 84 | # endif |
64 | # if HAVE_DECL_FREAD_UNLOCKED | 85 | # if HAVE_DECL_FREAD_UNLOCKED |
65 | # undef fread | 86 | # undef fread |
66 | # define fread(w,x,y,z) fread_unlocked (w,x,y,z) | 87 | # define fread(w,x,y,z) fread_unlocked (w,x,y,z) |
88 | # else | ||
89 | # define fread_unlocked(w,x,y,z) fread (w,x,y,z) | ||
67 | # endif | 90 | # endif |
68 | # if HAVE_DECL_FWRITE_UNLOCKED | 91 | # if HAVE_DECL_FWRITE_UNLOCKED |
69 | # undef fwrite | 92 | # undef fwrite |
70 | # define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z) | 93 | # define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z) |
94 | # else | ||
95 | # define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) | ||
71 | # endif | 96 | # endif |
72 | # if HAVE_DECL_GETC_UNLOCKED | 97 | # if HAVE_DECL_GETC_UNLOCKED |
73 | # undef getc | 98 | # undef getc |
74 | # define getc(x) getc_unlocked (x) | 99 | # define getc(x) getc_unlocked (x) |
100 | # else | ||
101 | # define getc_unlocked(x) getc (x) | ||
75 | # endif | 102 | # endif |
76 | # if HAVE_DECL_GETCHAR_UNLOCKED | 103 | # if HAVE_DECL_GETCHAR_UNLOCKED |
77 | # undef getchar | 104 | # undef getchar |
78 | # define getchar() getchar_unlocked () | 105 | # define getchar() getchar_unlocked () |
106 | # else | ||
107 | # define getchar_unlocked() getchar () | ||
79 | # endif | 108 | # endif |
80 | # if HAVE_DECL_PUTC_UNLOCKED | 109 | # if HAVE_DECL_PUTC_UNLOCKED |
81 | # undef putc | 110 | # undef putc |
82 | # define putc(x,y) putc_unlocked (x,y) | 111 | # define putc(x,y) putc_unlocked (x,y) |
112 | # else | ||
113 | # define putc_unlocked(x,y) putc (x,y) | ||
83 | # endif | 114 | # endif |
84 | # if HAVE_DECL_PUTCHAR_UNLOCKED | 115 | # if HAVE_DECL_PUTCHAR_UNLOCKED |
85 | # undef putchar | 116 | # undef putchar |
86 | # define putchar(x) putchar_unlocked (x) | 117 | # define putchar(x) putchar_unlocked (x) |
118 | # else | ||
119 | # define putchar_unlocked(x) putchar (x) | ||
87 | # endif | 120 | # endif |
88 | 121 | ||
122 | # undef flockfile | ||
123 | # define flockfile(x) ((void) 0) | ||
124 | |||
125 | # undef ftrylockfile | ||
126 | # define ftrylockfile(x) 0 | ||
127 | |||
128 | # undef funlockfile | ||
129 | # define funlockfile(x) ((void) 0) | ||
130 | |||
89 | # endif /* USE_UNLOCKED_IO */ | 131 | # endif /* USE_UNLOCKED_IO */ |
90 | #endif /* UNLOCKED_IO_H */ | 132 | #endif /* UNLOCKED_IO_H */ |
diff --git a/lib/unlocked-io.m4 b/lib/unlocked-io.m4 new file mode 100644 index 00000000..f8e98f1d --- /dev/null +++ b/lib/unlocked-io.m4 | |||
@@ -0,0 +1,22 @@ | |||
1 | #serial 8 -*- autoconf -*- | ||
2 | |||
3 | dnl From Jim Meyering. | ||
4 | dnl | ||
5 | dnl See if the glibc *_unlocked I/O macros or functions are available. | ||
6 | dnl Use only those *_unlocked macros or functions that are declared | ||
7 | dnl (because some of them were declared in Solaris 2.5.1 but were removed | ||
8 | dnl in Solaris 2.6, whereas we want binaries built on Solaris 2.5.1 to run | ||
9 | dnl on Solaris 2.6). | ||
10 | |||
11 | AC_DEFUN([jm_FUNC_GLIBC_UNLOCKED_IO], | ||
12 | [ | ||
13 | dnl Persuade glibc and Solaris <stdio.h> to declare | ||
14 | dnl fgets_unlocked(), fputs_unlocked() etc. | ||
15 | AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) | ||
16 | |||
17 | AC_CHECK_DECLS_ONCE( | ||
18 | [clearerr_unlocked feof_unlocked ferror_unlocked | ||
19 | fflush_unlocked fgets_unlocked fputc_unlocked fputs_unlocked | ||
20 | fread_unlocked fwrite_unlocked getc_unlocked | ||
21 | getchar_unlocked putc_unlocked putchar_unlocked]) | ||
22 | ]) | ||
diff --git a/lib/xalloc.h b/lib/xalloc.h index 098a6c2e..4b658581 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h | |||
@@ -1,5 +1,7 @@ | |||
1 | /* xalloc.h -- malloc with out-of-memory checking | 1 | /* xalloc.h -- malloc with out-of-memory checking |
2 | Copyright (C) 1990-1998, 1999, 2000 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | ||
4 | 1999, 2000, 2003 Free Software Foundation, Inc. | ||
3 | 5 | ||
4 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -18,13 +20,7 @@ | |||
18 | #ifndef XALLOC_H_ | 20 | #ifndef XALLOC_H_ |
19 | # define XALLOC_H_ | 21 | # define XALLOC_H_ |
20 | 22 | ||
21 | # ifndef PARAMS | 23 | # include <stddef.h> |
22 | # if defined PROTOTYPES || (defined __STDC__ && __STDC__) | ||
23 | # define PARAMS(Args) Args | ||
24 | # else | ||
25 | # define PARAMS(Args) () | ||
26 | # endif | ||
27 | # endif | ||
28 | 24 | ||
29 | # ifndef __attribute__ | 25 | # ifndef __attribute__ |
30 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ | 26 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ |
@@ -36,14 +32,9 @@ | |||
36 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | 32 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) |
37 | # endif | 33 | # endif |
38 | 34 | ||
39 | /* Exit value when the requested amount of memory is not available. | ||
40 | It is initialized to EXIT_FAILURE, but the caller may set it to | ||
41 | some other value. */ | ||
42 | extern int xalloc_exit_failure; | ||
43 | |||
44 | /* If this pointer is non-zero, run the specified function upon each | 35 | /* If this pointer is non-zero, run the specified function upon each |
45 | allocation failure. It is initialized to zero. */ | 36 | allocation failure. It is initialized to zero. */ |
46 | extern void (*xalloc_fail_func) PARAMS ((void)); | 37 | extern void (*xalloc_fail_func) (void); |
47 | 38 | ||
48 | /* If XALLOC_FAIL_FUNC is undefined or a function that returns, this | 39 | /* If XALLOC_FAIL_FUNC is undefined or a function that returns, this |
49 | message is output. It is translated via gettext. | 40 | message is output. It is translated via gettext. |
@@ -51,37 +42,46 @@ extern void (*xalloc_fail_func) PARAMS ((void)); | |||
51 | extern char const xalloc_msg_memory_exhausted[]; | 42 | extern char const xalloc_msg_memory_exhausted[]; |
52 | 43 | ||
53 | /* This function is always triggered when memory is exhausted. It is | 44 | /* This function is always triggered when memory is exhausted. It is |
54 | in charge of honoring the three previous items. This is the | 45 | in charge of honoring the two previous items. It exits with status |
46 | exit_failure (defined in exitfail.h). This is the | ||
55 | function to call when one wants the program to die because of a | 47 | function to call when one wants the program to die because of a |
56 | memory allocation failure. */ | 48 | memory allocation failure. */ |
57 | extern void xalloc_die PARAMS ((void)) ATTRIBUTE_NORETURN; | 49 | extern void xalloc_die (void) ATTRIBUTE_NORETURN; |
58 | 50 | ||
59 | void *xmalloc PARAMS ((size_t n)); | 51 | void *xmalloc (size_t s); |
60 | void *xcalloc PARAMS ((size_t n, size_t s)); | 52 | void *xnmalloc (size_t n, size_t s); |
61 | void *xrealloc PARAMS ((void *p, size_t n)); | 53 | void *xzalloc (size_t s); |
62 | char *xstrdup PARAMS ((const char *str)); | 54 | void *xcalloc (size_t n, size_t s); |
63 | 55 | void *xrealloc (void *p, size_t s); | |
64 | # define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items))) | 56 | void *xnrealloc (void *p, size_t n, size_t s); |
65 | # define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items))) | 57 | void *x2realloc (void *p, size_t *pn); |
66 | # define XREALLOC(Ptr, Type, N_items) \ | 58 | void *x2nrealloc (void *p, size_t *pn, size_t s); |
67 | ((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items))) | 59 | void *xclone (void const *p, size_t s); |
68 | 60 | char *xstrdup (const char *str); | |
69 | /* Declare and alloc memory for VAR of type TYPE. */ | 61 | |
70 | # define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1) | 62 | /* Return 1 if an array of N objects, each of size S, cannot exist due |
71 | 63 | to size arithmetic overflow. S must be positive and N must be | |
72 | /* Free VAR only if non NULL. */ | 64 | nonnegative. This is a macro, not an inline function, so that it |
73 | # define XFREE(Var) \ | 65 | works correctly even when SIZE_MAX < N. |
74 | do { \ | 66 | |
75 | if (Var) \ | 67 | By gnulib convention, SIZE_MAX represents overflow in size |
76 | free (Var); \ | 68 | calculations, so the conservative dividend to use here is |
77 | } while (0) | 69 | SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. |
78 | 70 | However, malloc (SIZE_MAX) fails on all known hosts where | |
79 | /* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */ | 71 | sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for |
80 | # define CCLONE(Src, Num) \ | 72 | exactly-SIZE_MAX allocations on such hosts; this avoids a test and |
81 | (memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num))) | 73 | branch when S is known to be 1. */ |
82 | 74 | # define xalloc_oversized(n, s) \ | |
83 | /* Return a malloc'ed copy of SRC. */ | 75 | ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n)) |
84 | # define CLONE(Src) CCLONE (Src, 1) | 76 | |
85 | 77 | /* These macros are deprecated; they will go away soon, and are retained | |
78 | temporarily only to ease conversion to the functions described above. */ | ||
79 | # define CCLONE(p, n) xclone (p, (n) * sizeof *(p)) | ||
80 | # define CLONE(p) xclone (p, sizeof *(p)) | ||
81 | # define NEW(type, var) type *var = xmalloc (sizeof (type)) | ||
82 | # define XCALLOC(type, n) xcalloc (n, sizeof (type)) | ||
83 | # define XMALLOC(type, n) xnmalloc (n, sizeof (type)) | ||
84 | # define XREALLOC(p, type, n) xnrealloc (p, n, sizeof (type)) | ||
85 | # define XFREE(p) free (p) | ||
86 | 86 | ||
87 | #endif /* !XALLOC_H_ */ | 87 | #endif /* !XALLOC_H_ */ |
diff --git a/lib/xalloc.m4 b/lib/xalloc.m4 new file mode 100644 index 00000000..dec84177 --- /dev/null +++ b/lib/xalloc.m4 | |||
@@ -0,0 +1,32 @@ | |||
1 | # xalloc.m4 serial 8 | ||
2 | dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. | ||
3 | dnl This file is free software, distributed under the terms of the GNU | ||
4 | dnl General Public License. As a special exception to the GNU General | ||
5 | dnl Public License, this file may be distributed as part of a program | ||
6 | dnl that contains a configuration script generated by Autoconf, under | ||
7 | dnl the same distribution terms as the rest of that program. | ||
8 | |||
9 | AC_DEFUN([gl_XALLOC], | ||
10 | [ | ||
11 | gl_PREREQ_XALLOC | ||
12 | gl_PREREQ_XMALLOC | ||
13 | gl_PREREQ_XSTRDUP | ||
14 | ]) | ||
15 | |||
16 | # Prerequisites of lib/xalloc.h. | ||
17 | AC_DEFUN([gl_PREREQ_XALLOC], [ | ||
18 | : | ||
19 | ]) | ||
20 | |||
21 | # Prerequisites of lib/xmalloc.c. | ||
22 | AC_DEFUN([gl_PREREQ_XMALLOC], [ | ||
23 | AC_REQUIRE([AC_C_INLINE]) | ||
24 | AC_REQUIRE([jm_FUNC_MALLOC]) | ||
25 | AC_REQUIRE([jm_FUNC_REALLOC]) | ||
26 | : | ||
27 | ]) | ||
28 | |||
29 | # Prerequisites of lib/xstrdup.c. | ||
30 | AC_DEFUN([gl_PREREQ_XSTRDUP], [ | ||
31 | : | ||
32 | ]) | ||
diff --git a/lib/xmalloc.c b/lib/xmalloc.c index 3affee7a..181006b4 100644 --- a/lib/xmalloc.c +++ b/lib/xmalloc.c | |||
@@ -1,5 +1,7 @@ | |||
1 | /* xmalloc.c -- malloc with out of memory checking | 1 | /* xmalloc.c -- malloc with out of memory checking |
2 | Copyright (C) 1990-1999, 2000, 2002 Free Software Foundation, Inc. | 2 | |
3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2003, | ||
4 | 1999, 2000, 2002, 2003 Free Software Foundation, Inc. | ||
3 | 5 | ||
4 | This program is free software; you can redistribute it and/or modify | 6 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 7 | it under the terms of the GNU General Public License as published by |
@@ -19,30 +21,22 @@ | |||
19 | # include <config.h> | 21 | # include <config.h> |
20 | #endif | 22 | #endif |
21 | 23 | ||
22 | #include <sys/types.h> | 24 | #include "xalloc.h" |
23 | 25 | ||
24 | #if STDC_HEADERS | 26 | #include <stdlib.h> |
25 | # include <stdlib.h> | 27 | #include <string.h> |
26 | #else | ||
27 | void *calloc (); | ||
28 | void *malloc (); | ||
29 | void *realloc (); | ||
30 | void free (); | ||
31 | #endif | ||
32 | 28 | ||
33 | #include "gettext.h" | 29 | #include "gettext.h" |
34 | #define _(msgid) gettext (msgid) | 30 | #define _(msgid) gettext (msgid) |
35 | #define N_(msgid) msgid | 31 | #define N_(msgid) msgid |
36 | 32 | ||
37 | #include "error.h" | 33 | #include "error.h" |
38 | #include "xalloc.h" | 34 | #include "exitfail.h" |
39 | 35 | ||
40 | #ifndef EXIT_FAILURE | 36 | #ifndef SIZE_MAX |
41 | # define EXIT_FAILURE 1 | 37 | # define SIZE_MAX ((size_t) -1) |
42 | #endif | 38 | #endif |
43 | 39 | ||
44 | /* The following tests require AC_PREREQ(2.54). */ | ||
45 | |||
46 | #ifndef HAVE_MALLOC | 40 | #ifndef HAVE_MALLOC |
47 | "you must run the autoconf test for a GNU libc compatible malloc" | 41 | "you must run the autoconf test for a GNU libc compatible malloc" |
48 | #endif | 42 | #endif |
@@ -51,12 +45,8 @@ void free (); | |||
51 | "you must run the autoconf test for a GNU libc compatible realloc" | 45 | "you must run the autoconf test for a GNU libc compatible realloc" |
52 | #endif | 46 | #endif |
53 | 47 | ||
54 | /* Exit value when the requested amount of memory is not available. | ||
55 | The caller may set it to some other value. */ | ||
56 | int xalloc_exit_failure = EXIT_FAILURE; | ||
57 | |||
58 | /* If non NULL, call this function when memory is exhausted. */ | 48 | /* If non NULL, call this function when memory is exhausted. */ |
59 | void (*xalloc_fail_func) PARAMS ((void)) = 0; | 49 | void (*xalloc_fail_func) (void) = 0; |
60 | 50 | ||
61 | /* If XALLOC_FAIL_FUNC is NULL, or does return, display this message | 51 | /* If XALLOC_FAIL_FUNC is NULL, or does return, display this message |
62 | before exiting when memory is exhausted. Goes through gettext. */ | 52 | before exiting when memory is exhausted. Goes through gettext. */ |
@@ -67,11 +57,29 @@ xalloc_die (void) | |||
67 | { | 57 | { |
68 | if (xalloc_fail_func) | 58 | if (xalloc_fail_func) |
69 | (*xalloc_fail_func) (); | 59 | (*xalloc_fail_func) (); |
70 | error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted)); | 60 | error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted)); |
71 | /* The `noreturn' cannot be given to error, since it may return if | 61 | /* The `noreturn' cannot be given to error, since it may return if |
72 | its first argument is 0. To help compilers understand the | 62 | its first argument is 0. To help compilers understand the |
73 | xalloc_die does terminate, call exit. */ | 63 | xalloc_die does terminate, call abort. */ |
74 | exit (EXIT_FAILURE); | 64 | abort (); |
65 | } | ||
66 | |||
67 | /* Allocate an array of N objects, each with S bytes of memory, | ||
68 | dynamically, with error checking. S must be nonzero. */ | ||
69 | |||
70 | static inline void * | ||
71 | xnmalloc_inline (size_t n, size_t s) | ||
72 | { | ||
73 | void *p; | ||
74 | if (xalloc_oversized (n, s) || ! (p = malloc (n * s))) | ||
75 | xalloc_die (); | ||
76 | return p; | ||
77 | } | ||
78 | |||
79 | void * | ||
80 | xnmalloc (size_t n, size_t s) | ||
81 | { | ||
82 | return xnmalloc_inline (n, s); | ||
75 | } | 83 | } |
76 | 84 | ||
77 | /* Allocate N bytes of memory dynamically, with error checking. */ | 85 | /* Allocate N bytes of memory dynamically, with error checking. */ |
@@ -79,35 +87,169 @@ xalloc_die (void) | |||
79 | void * | 87 | void * |
80 | xmalloc (size_t n) | 88 | xmalloc (size_t n) |
81 | { | 89 | { |
82 | void *p; | 90 | return xnmalloc_inline (n, 1); |
91 | } | ||
92 | |||
93 | /* Change the size of an allocated block of memory P to an array of N | ||
94 | objects each of S bytes, with error checking. S must be nonzero. */ | ||
83 | 95 | ||
84 | p = malloc (n); | 96 | static inline void * |
85 | if (p == 0) | 97 | xnrealloc_inline (void *p, size_t n, size_t s) |
98 | { | ||
99 | if (xalloc_oversized (n, s) || ! (p = realloc (p, n * s))) | ||
86 | xalloc_die (); | 100 | xalloc_die (); |
87 | return p; | 101 | return p; |
88 | } | 102 | } |
89 | 103 | ||
104 | void * | ||
105 | xnrealloc (void *p, size_t n, size_t s) | ||
106 | { | ||
107 | return xnrealloc_inline (p, n, s); | ||
108 | } | ||
109 | |||
90 | /* Change the size of an allocated block of memory P to N bytes, | 110 | /* Change the size of an allocated block of memory P to N bytes, |
91 | with error checking. */ | 111 | with error checking. */ |
92 | 112 | ||
93 | void * | 113 | void * |
94 | xrealloc (void *p, size_t n) | 114 | xrealloc (void *p, size_t n) |
95 | { | 115 | { |
96 | p = realloc (p, n); | 116 | return xnrealloc_inline (p, n, 1); |
97 | if (p == 0) | ||
98 | xalloc_die (); | ||
99 | return p; | ||
100 | } | 117 | } |
101 | 118 | ||
102 | /* Allocate memory for N elements of S bytes, with error checking. */ | 119 | |
120 | /* If P is null, allocate a block of at least *PN such objects; | ||
121 | otherwise, reallocate P so that it contains more than *PN objects | ||
122 | each of S bytes. *PN must be nonzero unless P is null, and S must | ||
123 | be nonzero. Set *PN to the new number of objects, and return the | ||
124 | pointer to the new block. *PN is never set to zero, and the | ||
125 | returned pointer is never null. | ||
126 | |||
127 | Repeated reallocations are guaranteed to make progress, either by | ||
128 | allocating an initial block with a nonzero size, or by allocating a | ||
129 | larger block. | ||
130 | |||
131 | In the following implementation, nonzero sizes are doubled so that | ||
132 | repeated reallocations have O(N log N) overall cost rather than | ||
133 | O(N**2) cost, but the specification for this function does not | ||
134 | guarantee that sizes are doubled. | ||
135 | |||
136 | Here is an example of use: | ||
137 | |||
138 | int *p = NULL; | ||
139 | size_t used = 0; | ||
140 | size_t allocated = 0; | ||
141 | |||
142 | void | ||
143 | append_int (int value) | ||
144 | { | ||
145 | if (used == allocated) | ||
146 | p = x2nrealloc (p, &allocated, sizeof *p); | ||
147 | p[used++] = value; | ||
148 | } | ||
149 | |||
150 | This causes x2nrealloc to allocate a block of some nonzero size the | ||
151 | first time it is called. | ||
152 | |||
153 | To have finer-grained control over the initial size, set *PN to a | ||
154 | nonzero value before calling this function with P == NULL. For | ||
155 | example: | ||
156 | |||
157 | int *p = NULL; | ||
158 | size_t used = 0; | ||
159 | size_t allocated = 0; | ||
160 | size_t allocated1 = 1000; | ||
161 | |||
162 | void | ||
163 | append_int (int value) | ||
164 | { | ||
165 | if (used == allocated) | ||
166 | { | ||
167 | p = x2nrealloc (p, &allocated1, sizeof *p); | ||
168 | allocated = allocated1; | ||
169 | } | ||
170 | p[used++] = value; | ||
171 | } | ||
172 | |||
173 | */ | ||
174 | |||
175 | static inline void * | ||
176 | x2nrealloc_inline (void *p, size_t *pn, size_t s) | ||
177 | { | ||
178 | size_t n = *pn; | ||
179 | |||
180 | if (! p) | ||
181 | { | ||
182 | if (! n) | ||
183 | { | ||
184 | /* The approximate size to use for initial small allocation | ||
185 | requests, when the invoking code specifies an old size of | ||
186 | zero. 64 bytes is the largest "small" request for the | ||
187 | GNU C library malloc. */ | ||
188 | enum { DEFAULT_MXFAST = 64 }; | ||
189 | |||
190 | n = DEFAULT_MXFAST / s; | ||
191 | n += !n; | ||
192 | } | ||
193 | } | ||
194 | else | ||
195 | { | ||
196 | if (SIZE_MAX / 2 / s < n) | ||
197 | xalloc_die (); | ||
198 | n *= 2; | ||
199 | } | ||
200 | |||
201 | *pn = n; | ||
202 | return xrealloc (p, n * s); | ||
203 | } | ||
204 | |||
205 | void * | ||
206 | x2nrealloc (void *p, size_t *pn, size_t s) | ||
207 | { | ||
208 | return x2nrealloc_inline (p, pn, s); | ||
209 | } | ||
210 | |||
211 | /* If P is null, allocate a block of at least *PN bytes; otherwise, | ||
212 | reallocate P so that it contains more than *PN bytes. *PN must be | ||
213 | nonzero unless P is null. Set *PN to the new block's size, and | ||
214 | return the pointer to the new block. *PN is never set to zero, and | ||
215 | the returned pointer is never null. */ | ||
216 | |||
217 | void * | ||
218 | x2realloc (void *p, size_t *pn) | ||
219 | { | ||
220 | return x2nrealloc_inline (p, pn, 1); | ||
221 | } | ||
222 | |||
223 | /* Allocate S bytes of zeroed memory dynamically, with error checking. | ||
224 | There's no need for xnzalloc (N, S), since it would be equivalent | ||
225 | to xcalloc (N, S). */ | ||
226 | |||
227 | void * | ||
228 | xzalloc (size_t s) | ||
229 | { | ||
230 | return memset (xmalloc (s), 0, s); | ||
231 | } | ||
232 | |||
233 | /* Allocate zeroed memory for N elements of S bytes, with error | ||
234 | checking. S must be nonzero. */ | ||
103 | 235 | ||
104 | void * | 236 | void * |
105 | xcalloc (size_t n, size_t s) | 237 | xcalloc (size_t n, size_t s) |
106 | { | 238 | { |
107 | void *p; | 239 | void *p; |
108 | 240 | /* Test for overflow, since some calloc implementations don't have | |
109 | p = calloc (n, s); | 241 | proper overflow checks. */ |
110 | if (p == 0) | 242 | if (xalloc_oversized (n, s) || ! (p = calloc (n, s))) |
111 | xalloc_die (); | 243 | xalloc_die (); |
112 | return p; | 244 | return p; |
113 | } | 245 | } |
246 | |||
247 | /* Clone an object P of size S, with error checking. There's no need | ||
248 | for xnclone (P, N, S), since xclone (P, N * S) works without any | ||
249 | need for an arithmetic overflow check. */ | ||
250 | |||
251 | void * | ||
252 | xclone (void const *p, size_t s) | ||
253 | { | ||
254 | return memcpy (xmalloc (s), p, s); | ||
255 | } | ||
diff --git a/lib/xstrdup.c b/lib/xstrdup.c new file mode 100644 index 00000000..58f18beb --- /dev/null +++ b/lib/xstrdup.c | |||
@@ -0,0 +1,33 @@ | |||
1 | /* xstrdup.c -- copy a string with out of memory checking | ||
2 | Copyright (C) 1990, 1996, 1998, 2001, 2003 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software Foundation, | ||
16 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | ||
17 | |||
18 | #if HAVE_CONFIG_H | ||
19 | # include <config.h> | ||
20 | #endif | ||
21 | |||
22 | /* Specification. */ | ||
23 | #include "xalloc.h" | ||
24 | |||
25 | #include <string.h> | ||
26 | |||
27 | /* Return a newly allocated copy of STRING. */ | ||
28 | |||
29 | char * | ||
30 | xstrdup (const char *string) | ||
31 | { | ||
32 | return xclone (string, strlen (string) + 1); | ||
33 | } | ||