From a62be9f4039b4499cfbb76e394cad2259d03fa84 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 7 Aug 2004 00:09:38 +0000 Subject: [PATCH] Merge from coreutils. --- ChangeLog | 14 ++++++ lib/ChangeLog | 22 +++++++++ lib/chown.c | 3 -- lib/closeout.c | 8 ++-- lib/dup2.c | 5 +- lib/exclude.c | 7 +-- lib/fileblocks.c | 5 +- lib/filemode.c | 121 +---------------------------------------------- lib/fnmatch.c | 5 +- lib/fnmatch_loop.c | 44 ++++++++--------- lib/fopen-safer.c | 6 +-- lib/fsusage.c | 16 ++++--- lib/fsusage.h | 13 +++-- lib/ftruncate.c | 3 -- lib/full-write.c | 6 +-- lib/getdate.y | 7 ++- lib/getloadavg.c | 126 +++++++++++++++++++++++-------------------------- lib/getugroups.c | 14 +++++- lib/hard-locale.c | 17 +++---- lib/hard-locale.h | 6 ++- lib/hash.c | 14 +++--- lib/human.c | 4 +- lib/human.h | 15 +++--- lib/lchown.c | 27 +++-------- lib/lchown.h | 8 ++-- lib/makepath.c | 131 ++++++++++++++++++--------------------------------- lib/makepath.h | 29 ++++++------ lib/md5.c | 15 ++---- lib/md5.h | 43 ++++------------- lib/memchr.c | 56 +++++++++++----------- lib/memcoll.c | 6 +-- lib/memrchr.c | 59 +++++++++++------------ lib/modechange.c | 15 +++--- lib/modechange.h | 4 +- lib/mountlist.c | 64 ++++++------------------- lib/mountlist.h | 10 ++-- lib/nanosleep.c | 8 ++-- lib/posixtm.c | 10 ++-- lib/putenv.c | 7 +-- lib/quotearg.c | 25 +++++----- lib/quotearg.h | 2 +- lib/readtokens.c | 5 +- lib/readutmp.c | 45 +++++++++--------- lib/readutmp.h | 10 ++-- lib/rmdir.c | 14 +----- lib/safe-read.c | 38 +++++++-------- lib/save-cwd.c | 22 ++++----- lib/savedir.c | 9 ++-- lib/setenv.c | 7 +-- lib/sig2str.c | 8 ++-- lib/stat.c | 18 +------ lib/strtoimax.c | 15 +++--- lib/strverscmp.c | 4 +- lib/userspec.c | 83 +++++++++++++++----------------- lib/utime.c | 5 +- lib/version-etc.c | 2 +- lib/xgethostname.c | 54 ++++++++++----------- lib/xmemcoll.c | 6 +-- lib/xreadlink.c | 4 -- lib/xstrtod.c | 18 +++---- lib/xstrtod.h | 8 ++-- lib/xstrtoimax.c | 8 +--- lib/xstrtol.c | 18 +++---- lib/xstrtol.h | 8 ++-- lib/xstrtoumax.c | 8 +--- m4/ChangeLog | 9 ++++ m4/acl.m4 | 2 +- m4/afs.m4 | 13 +++-- m4/calloc.m4 | 6 +-- m4/dirfd.m4 | 2 +- m4/fsusage.m4 | 35 +++++++++++--- m4/jm-macros.m4 | 59 +++++++++++++++++------ m4/ls-mntd-fs.m4 | 58 ++++++++++++++++------- m4/md5.m4 | 10 ++-- m4/mountlist.m4 | 10 ++-- m4/prereq.m4 | 8 +++- m4/sha.m4 | 7 +-- modules/canonicalize | 2 +- modules/euidaccess | 3 +- modules/filemode | 3 +- modules/lchown | 3 +- modules/makepath | 3 +- modules/rmdir | 2 + modules/stat | 2 + 84 files changed, 741 insertions(+), 913 deletions(-) diff --git a/ChangeLog b/ChangeLog index cee6ae85c..870c2c36c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2004-08-06 Paul Eggert + + More merge from coreutils. + * modules/raise, modules/readtokens0, modules/utimens, + modules/utimecmp, module/xnanosleep: New files. + * modules/strftime: Add lib/strftime.h. + Change include from to "strftime.h". + * modules/yesno: Add lib/yesno.h. + * modules/backupfile: Remove lib/addext.c. + * modules/euidaccess: Add stat-macros.h. + * modules/canonicalize, modules/euidaccess, + modules/filemode, modules/lchown, modules/makepath, + modules/rmdir, modules/stat: Likewise. + 2004-08-03 Simon Josefsson * modules/progname (Depends-on): Don't depend on stdbool. diff --git a/lib/ChangeLog b/lib/ChangeLog index cb82d426a..eed8bc39e 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,25 @@ +2004-08-06 Paul Eggert + + More merges from coreutils. + * raise.c, readtokens0.h, readtokens0.c, strftime.h, utimens.h, + utimens.c, utimecmp.h, utimecmp.c, xnanosleep.h, xnanosleep.c, + yesno.h: New files. + * addext.c: Remove; no longer needed. + * yesno.c, argmatch.h, argmatch.c, backupfile.h, backupfile.c, + euidaccess.c, filemode.c, closeout.c, dup2.c, exclude.c, + fileblocks.c, filemode.c, fnmatch.c, fnmtahc_loop.c, + fopen-safer.c, fsusage.c, fsusage.h, ftruncate.c, full-write.c, + getdate.y, getloadavg.c, getugroups.c, hard-locale.c, hard-locale.h, + hash.c, human.c, human.h, lchown.c, lchown.h, makepath.c, makepath.h, + md5.c, md5.h, memchr.c, memcoll.c, memrchr.c, modechange.c, + modechange.h, mountlist.c, mountlist.h, nanosleep.c, posixtm.c, + putenv.c, quotearg.c, quotearg.h, readtokens.c, readutmp.c, + readutmp.h, rmdir.c, safe-read.c, save-cwd.c, savedir.c, setenv.c, + sig2str.c, stat.c, strtoimax.c, strverscmp.c, userspec.c, utime.c, + version-etc.c., xgethostname.c, xmemcoll.c, xreadlink.c, xstrtod.c, + xstrtod.h, xstrtoimax.c, xstrtol.c, xstrtol.h, xstrtoumax.c: + Import changes from coreutils. + 2004-08-03 Simon Josefsson * progname.h: Don't include stdbool.h. diff --git a/lib/chown.c b/lib/chown.c index 460e4f623..d761c7339 100644 --- a/lib/chown.c +++ b/lib/chown.c @@ -36,9 +36,6 @@ # include #endif #include -#ifndef errno -extern int errno; -#endif /* Provide a more-closely POSIX-conforming version of chown on systems with one or both of the following problems: diff --git a/lib/closeout.c b/lib/closeout.c index a551d1ae8..3c7bed9c3 100644 --- a/lib/closeout.c +++ b/lib/closeout.c @@ -1,5 +1,7 @@ /* closeout.c - close standard output - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,11 +24,7 @@ #include "closeout.h" #include - #include -#ifndef errno -extern int errno; -#endif #include "gettext.h" #define _(msgid) gettext (msgid) diff --git a/lib/dup2.c b/lib/dup2.c index 32afed50f..6d3e4fc53 100644 --- a/lib/dup2.c +++ b/lib/dup2.c @@ -1,5 +1,5 @@ /* Duplicate an open file descriptor to a specified file descriptor. - Copyright 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,9 +22,6 @@ #endif #include -#ifndef errno -extern int errno; -#endif #if HAVE_FCNTL_H # include diff --git a/lib/exclude.c b/lib/exclude.c index 55f1a3918..4ca2c7856 100644 --- a/lib/exclude.c +++ b/lib/exclude.c @@ -1,7 +1,7 @@ /* exclude.c -- exclude file names - Copyright (C) 1992, 1993, 1994, 1997, 1999, 2000, 2001, 2002, 2003 Free - Software Foundation, Inc. + Copyright (C) 1992, 1993, 1994, 1997, 1999, 2000, 2001, 2002, 2003, + 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,9 +28,6 @@ #include #include -#ifndef errno -extern int errno; -#endif #include #include #include diff --git a/lib/fileblocks.c b/lib/fileblocks.c index 2c944307d..72e78a5e1 100644 --- a/lib/fileblocks.c +++ b/lib/fileblocks.c @@ -1,5 +1,6 @@ /* Convert file size to number of blocks on System V-like machines. - Copyright (C) 1990, 1997, 1998, 1999 Free Software Foundation, Inc. + + Copyright (C) 1990, 1997, 1998, 1999, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -73,5 +74,5 @@ st_blocks (off_t size) #else /* This declaration is solely to ensure that after preprocessing this file is never empty. */ -extern int textutils_fileblocks_unused; +typedef int textutils_fileblocks_unused; #endif diff --git a/lib/filemode.c b/lib/filemode.c index 5e909dfca..0e38e3af3 100644 --- a/lib/filemode.c +++ b/lib/filemode.c @@ -1,5 +1,5 @@ /* filemode.c -- make a string describing file modes - Copyright (C) 1985, 1990, 1993, 1998-2000 Free Software Foundation, Inc. + Copyright (C) 1985, 1990, 1993, 1998-2000, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,98 +23,7 @@ #include #include "filemode.h" - -#if !S_IRUSR -# if S_IREAD -# define S_IRUSR S_IREAD -# else -# define S_IRUSR 00400 -# endif -#endif - -#if !S_IWUSR -# if S_IWRITE -# define S_IWUSR S_IWRITE -# else -# define S_IWUSR 00200 -# endif -#endif - -#if !S_IXUSR -# if S_IEXEC -# define S_IXUSR S_IEXEC -# else -# define S_IXUSR 00100 -# endif -#endif - -#if !S_IRGRP -# define S_IRGRP (S_IRUSR >> 3) -#endif -#if !S_IWGRP -# define S_IWGRP (S_IWUSR >> 3) -#endif -#if !S_IXGRP -# define S_IXGRP (S_IXUSR >> 3) -#endif -#if !S_IROTH -# define S_IROTH (S_IRUSR >> 6) -#endif -#if !S_IWOTH -# define S_IWOTH (S_IWUSR >> 6) -#endif -#if !S_IXOTH -# define S_IXOTH (S_IXUSR >> 6) -#endif - -#ifdef STAT_MACROS_BROKEN -# undef S_ISBLK -# undef S_ISCHR -# undef S_ISDIR -# undef S_ISFIFO -# undef S_ISLNK -# undef S_ISMPB -# undef S_ISMPC -# undef S_ISNWK -# undef S_ISREG -# undef S_ISSOCK -#endif /* STAT_MACROS_BROKEN. */ - -#if !defined S_ISBLK && defined S_IFBLK -# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) -#endif -#if !defined S_ISCHR && defined S_IFCHR -# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) -#endif -#if !defined S_ISDIR && defined S_IFDIR -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif -#if !defined S_ISREG && defined S_IFREG -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif -#if !defined S_ISFIFO && defined S_IFIFO -# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) -#endif -#if !defined S_ISLNK && defined S_IFLNK -# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -#endif -#if !defined S_ISSOCK && defined S_IFSOCK -# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) -#endif -#if !defined S_ISMPB && defined S_IFMPB /* V7 */ -# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) -# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) -#endif -#if !defined S_ISNWK && defined S_IFNWK /* HP/UX */ -# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) -#endif -#if !defined S_ISDOOR && defined S_IFDOOR /* Solaris 2.5 and up */ -# define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR) -#endif -#if !defined S_ISCTG && defined S_IFCTG /* MassComp */ -# define S_ISCTG(m) (((m) & S_IFMT) == S_IFCTG) -#endif - +#include "stat-macros.h" /* Set the 's' and 't' flags in file attributes string CHARS, @@ -123,7 +32,6 @@ static void setst (mode_t bits, char *chars) { -#ifdef S_ISUID if (bits & S_ISUID) { if (chars[3] != 'x') @@ -132,8 +40,6 @@ setst (mode_t bits, char *chars) else chars[3] = 's'; } -#endif -#ifdef S_ISGID if (bits & S_ISGID) { if (chars[6] != 'x') @@ -142,8 +48,6 @@ setst (mode_t bits, char *chars) else chars[6] = 's'; } -#endif -#ifdef S_ISVTX if (bits & S_ISVTX) { if (chars[9] != 'x') @@ -152,7 +56,6 @@ setst (mode_t bits, char *chars) else chars[9] = 't'; } -#endif } /* Return a character indicating the type of file described by @@ -174,60 +77,40 @@ setst (mode_t bits, char *chars) static char ftypelet (mode_t bits) { -#ifdef S_ISBLK if (S_ISBLK (bits)) return 'b'; -#endif if (S_ISCHR (bits)) return 'c'; if (S_ISDIR (bits)) return 'd'; if (S_ISREG (bits)) return '-'; -#ifdef S_ISFIFO if (S_ISFIFO (bits)) return 'p'; -#endif -#ifdef S_ISLNK if (S_ISLNK (bits)) return 'l'; -#endif -#ifdef S_ISSOCK if (S_ISSOCK (bits)) return 's'; -#endif -#ifdef S_ISMPC if (S_ISMPC (bits)) return 'm'; -#endif -#ifdef S_ISNWK if (S_ISNWK (bits)) return 'n'; -#endif -#ifdef S_ISDOOR if (S_ISDOOR (bits)) return 'D'; -#endif -#ifdef S_ISCTG if (S_ISCTG (bits)) return 'C'; -#endif /* The following two tests are for Cray DMF (Data Migration Facility), which is a HSM file system. A migrated file has a `st_dm_mode' that is different from the normal `st_mode', so any tests for migrated files should use the former. */ -#ifdef S_ISOFD if (S_ISOFD (bits)) /* off line, with data */ return 'M'; -#endif -#ifdef S_ISOFL /* off line, with no data */ if (S_ISOFL (bits)) return 'M'; -#endif return '?'; } diff --git a/lib/fnmatch.c b/lib/fnmatch.c index b9b059834..32468964d 100644 --- a/lib/fnmatch.c +++ b/lib/fnmatch.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -156,10 +157,6 @@ extern int fnmatch (const char *pattern, const char *string, int flags); /* Avoid depending on library functions or files whose names are inconsistent. */ -# ifndef errno -extern int errno; -# endif - /* Global variable. */ static int posixly_correct; diff --git a/lib/fnmatch_loop.c b/lib/fnmatch_loop.c index 7798b59ec..7cea5a76e 100644 --- a/lib/fnmatch_loop.c +++ b/lib/fnmatch_loop.c @@ -18,14 +18,14 @@ /* Match STRING against the filename pattern PATTERN, returning zero if it matches, nonzero if not. */ static int EXT (INT opt, const CHAR *pattern, const CHAR *string, - const CHAR *string_end, int no_leading_period, int flags) + const CHAR *string_end, bool no_leading_period, int flags) internal_function; static const CHAR *END (const CHAR *patternp) internal_function; static int internal_function FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, - int no_leading_period, int flags) + bool no_leading_period, int flags) { register const CHAR *p = pattern, *n = string; register UCHAR c; @@ -41,7 +41,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, while ((c = *p++) != L('\0')) { - int new_no_leading_period = 0; + bool new_no_leading_period = false; c = FOLD (c); switch (c) @@ -161,9 +161,9 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, { int flags2 = ((flags & FNM_FILE_NAME) ? flags : (flags & ~FNM_PERIOD)); - int no_leading_period2 = no_leading_period; + bool no_leading_period2 = no_leading_period; - for (--p; n < endp; ++n, no_leading_period2 = 0) + for (--p; n < endp; ++n, no_leading_period2 = false) if (FCT (p, n, string_end, no_leading_period2, flags2) == 0) return 0; @@ -186,7 +186,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, if (c == L('\\') && !(flags & FNM_NOESCAPE)) c = *p; c = FOLD (c); - for (--p; n < endp; ++n, no_leading_period2 = 0) + for (--p; n < endp; ++n, no_leading_period2 = false) if (FOLD ((UCHAR) *n) == c && (FCT (p, n, string_end, no_leading_period2, flags2) == 0)) @@ -200,7 +200,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, case L('['): { /* Nonzero if the sense of the character class is inverted. */ - register int not; + register bool not; CHAR cold; UCHAR fn; @@ -410,10 +410,10 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, return FNM_NOMATCH; else { - int is_range = 0; + bool is_range = false; #ifdef _LIBC - int is_seqval = 0; + bool is_seqval = false; if (c == L('[') && *p == L('.')) { @@ -460,7 +460,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, const int32_t *symb_table; # ifdef WIDE_CHAR_VERSION char str[c1]; - unsigned int strcnt; + size_t strcnt; # else # define str (startp + 1) # endif @@ -550,7 +550,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, } /* Get the collation sequence value. */ - is_seqval = 1; + is_seqval = true; # ifdef WIDE_CHAR_VERSION cold = wextra[1 + wextra[idx]]; # else @@ -629,7 +629,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, lcollseq = is_seqval ? cold : collseq[(UCHAR) cold]; # endif - is_seqval = 0; + is_seqval = false; if (cend == L('[') && *p == L('.')) { uint32_t nrules = @@ -668,7 +668,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, const int32_t *symb_table; # ifdef WIDE_CHAR_VERSION char str[c1]; - unsigned int strcnt; + size_t strcnt; # else # define str (startp + 1) # endif @@ -738,7 +738,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, wextra = (int32_t *) &extra[idx + 4]; # endif /* Get the collation sequence value. */ - is_seqval = 1; + is_seqval = true; # ifdef WIDE_CHAR_VERSION cend = wextra[1 + wextra[idx]]; # else @@ -929,7 +929,7 @@ FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end, if (n == string_end || c != (UCHAR) *n) return FNM_NOMATCH; - new_no_leading_period = 1; + new_no_leading_period = true; break; } /* FALLTHROUGH */ @@ -996,10 +996,10 @@ END (const CHAR *pattern) static int internal_function EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, - int no_leading_period, int flags) + bool no_leading_period, int flags) { const CHAR *startp; - int level; + size_t level; struct patternlist { struct patternlist *next; @@ -1013,7 +1013,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, /* Parse the pattern. Store the individual parts in the list. */ level = 0; - for (startp = p = pattern + 1; level >= 0; ++p) + for (startp = p = pattern + 1; ; ++p) if (*p == L('\0')) /* This is an invalid pattern. */ return -1; @@ -1066,6 +1066,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, *lastp = newp; \ lastp = &newp->next NEW_PATTERN; + break; } } else if (*p == L('|')) @@ -1100,7 +1101,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, && (FCT (p, rs, string_end, rs == string ? no_leading_period - : rs[-1] == '/' && NO_LEADING_PERIOD (flags) ? 1 : 0, + : rs[-1] == '/' && NO_LEADING_PERIOD (flags), flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0 /* This didn't work. Try the whole pattern. */ @@ -1108,8 +1109,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, && FCT (pattern - 1, rs, string_end, rs == string ? no_leading_period - : (rs[-1] == '/' && NO_LEADING_PERIOD (flags) - ? 1 : 0), + : rs[-1] == '/' && NO_LEADING_PERIOD (flags), flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0))) /* It worked. Signal success. */ @@ -1156,7 +1156,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end, && (FCT (p, rs, string_end, rs == string ? no_leading_period - : rs[-1] == '/' && NO_LEADING_PERIOD (flags) ? 1 : 0, + : rs[-1] == '/' && NO_LEADING_PERIOD (flags), flags & FNM_FILE_NAME ? flags : flags & ~FNM_PERIOD) == 0)) /* This is successful. */ diff --git a/lib/fopen-safer.c b/lib/fopen-safer.c index 6825f9b9f..c5c97c8a1 100644 --- a/lib/fopen-safer.c +++ b/lib/fopen-safer.c @@ -1,5 +1,5 @@ /* Invoke fopen, but avoid some glitches. - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,10 +31,6 @@ #endif #include -#ifndef errno -extern int errno; -#endif - #include #include diff --git a/lib/fsusage.c b/lib/fsusage.c index d92602936..f1dfb2d7e 100644 --- a/lib/fsusage.c +++ b/lib/fsusage.c @@ -1,6 +1,6 @@ -/* fsusage.c -- return space usage of mounted filesystems +/* fsusage.c -- return space usage of mounted file systems - Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003 Free + Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -23,10 +23,12 @@ #if HAVE_INTTYPES_H # include -#else -# if HAVE_STDINT_H -# include -# endif +#endif +#if HAVE_STDINT_H +# include +#endif +#if HAVE_UNISTD_H +# include #endif #ifndef UINTMAX_MAX # define UINTMAX_MAX ((uintmax_t) -1) @@ -102,7 +104,7 @@ int statvfs (); #define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1)) /* Fill in the fields of FSP with information about space usage for - the filesystem on which PATH resides. + the file system on which PATH resides. DISK is the device on which PATH is mounted, for space-getting methods that need to know it. Return 0 if successful, -1 if not. When returning -1, ensure that diff --git a/lib/fsusage.h b/lib/fsusage.h index e2cbbf127..7528b8902 100644 --- a/lib/fsusage.h +++ b/lib/fsusage.h @@ -1,6 +1,7 @@ -/* fsusage.h -- declarations for filesystem space usage info +/* fsusage.h -- declarations for file system space usage info - Copyright (C) 1991, 1992, 1997, 2003 Free Software Foundation, Inc. + Copyright (C) 1991, 1992, 1997, 2003, 2004 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,18 +17,20 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* Space usage statistics for a filesystem. Blocks are 512-byte. */ +/* Space usage statistics for a file system. Blocks are 512-byte. */ #if !defined FSUSAGE_H_ # define FSUSAGE_H_ +# include + struct fs_usage { - int fsu_blocksize; /* Size of a block. */ + uintmax_t fsu_blocksize; /* Size of a block. */ uintmax_t fsu_blocks; /* Total blocks. */ uintmax_t fsu_bfree; /* Free blocks available to superuser. */ uintmax_t fsu_bavail; /* Free blocks available to non-superuser. */ - int fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ + bool fsu_bavail_top_bit_set; /* 1 if fsu_bavail represents a value < 0. */ uintmax_t fsu_files; /* Total file nodes. */ uintmax_t fsu_ffree; /* Free file nodes. */ }; diff --git a/lib/ftruncate.c b/lib/ftruncate.c index adf87f64b..c062fe80d 100644 --- a/lib/ftruncate.c +++ b/lib/ftruncate.c @@ -79,9 +79,6 @@ ftruncate (int fd, off_t length) # else /* not F_CHSIZE nor F_FREESP nor HAVE_CHSIZE */ # include -# ifndef errno -extern int errno; -# endif int ftruncate (int fd, off_t length) diff --git a/lib/full-write.c b/lib/full-write.c index 151370563..d119977e7 100644 --- a/lib/full-write.c +++ b/lib/full-write.c @@ -1,6 +1,7 @@ /* An interface to read and write that retries (if necessary) until complete. - Copyright (C) 1993, 1994, 1997-2003 Free Software Foundation, Inc. + Copyright (C) 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002, 2003, + 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,9 +29,6 @@ #endif #include -#ifndef errno -extern int errno; -#endif #ifdef FULL_READ # include "safe-read.h" diff --git a/lib/getdate.y b/lib/getdate.y index 5784b6ccd..9d948dc12 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -768,8 +768,11 @@ lookup_word (parser_control const *pc, char *word) /* Make it uppercase. */ for (p = word; *p; p++) - if (ISLOWER ((unsigned char) *p)) - *p = toupper ((unsigned char) *p); + { + unsigned char ch = *p; + if (ISLOWER (ch)) + *p = toupper (ch); + } for (tp = meridian_table; tp->name; tp++) if (strcmp (word, tp->name) == 0) diff --git a/lib/getloadavg.c b/lib/getloadavg.c index ed079b2ec..8b6067b8c 100644 --- a/lib/getloadavg.c +++ b/lib/getloadavg.c @@ -48,8 +48,6 @@ not an array. HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'. LINUX_LDAV_FILE [__linux__]: File containing load averages. - HAVE_LOCALE_H locale.h is available. - HAVE_SETLOCALE The `setlocale' function is available. Specific system predefines this file uses, aside from setting default values if not emacs: @@ -70,9 +68,9 @@ UMAX4_3 VMS WINDOWS32 No-op for Windows95/NT. - __linux__ Linux: assumes /proc filesystem mounted. + __linux__ Linux: assumes /proc file system mounted. Support from Michael K. Johnson. - __NetBSD__ NetBSD: assumes /kern filesystem mounted. + __NetBSD__ NetBSD: assumes /kern file system mounted. In addition, to avoid nesting many #ifdefs, we internally set LDAV_DONE to indicate that the load average has been computed. @@ -85,39 +83,28 @@ # include #endif -#include - -/* Both the Emacs and non-Emacs sections want this. Some - configuration files' definitions for the LOAD_AVE_CVT macro (like - sparc.h's) use macros like FSCALE, defined here. */ -#if defined (unix) || defined (__unix) -# include -#endif - +#include +#include +#include +#include /* Exclude all the code except the test program at the end - if the system has its own `getloadavg' function. - - The declaration of `errno' is needed by the test program - as well as the function itself, so it comes first. */ + if the system has its own `getloadavg' function. */ -#include +#ifndef HAVE_GETLOADAVG -#ifndef errno -extern int errno; -#endif +# include -#ifdef HAVE_LOCALE_H -# include -#endif -#ifndef HAVE_SETLOCALE -# define setlocale(Category, Locale) ((char *) NULL) -#endif - -#include "cloexec.h" -#include "xalloc.h" +/* Both the Emacs and non-Emacs sections want this. Some + configuration files' definitions for the LOAD_AVE_CVT macro (like + sparc.h's) use macros like FSCALE, defined here. */ +# if defined (unix) || defined (__unix) +# include +# endif -#ifndef HAVE_GETLOADAVG +# include "c-strtod.h" +# include "cloexec.h" +# include "xalloc.h" /* The existing Emacs configuration files define a macro called LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and @@ -362,7 +349,7 @@ extern int errno; # include # endif -# include +# include /* LOAD_AVE_TYPE should only get defined if we're going to use the nlist method. */ @@ -436,7 +423,6 @@ extern int errno; # endif /* sgi */ # ifdef UMAX -# include # include # include # include @@ -472,7 +458,7 @@ extern int errno; # ifdef NeXT static processor_set_t default_set; -static int getloadavg_initialized; +static bool getloadavg_initialized; # endif /* NeXT */ # ifdef UMAX @@ -487,8 +473,8 @@ static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ # if !defined (HAVE_LIBKSTAT) && defined (LOAD_AVE_TYPE) /* File descriptor open to /dev/kmem or VMS load ave driver. */ static int channel; -/* Nonzero iff channel is valid. */ -static int getloadavg_initialized; +/* True iff channel is valid. */ +static bool getloadavg_initialized; /* Offset in kmem to seek to read load average, or 0 means invalid. */ static long offset; @@ -592,33 +578,37 @@ getloadavg (double loadavg[], int nelem) # define LINUX_LDAV_FILE "/proc/loadavg" # endif - char ldavgbuf[40]; - double load_ave[3]; +/* Upper bound on the string length of an integer converted to string. + 302 / 1000 is ceil (log10 (2.0)). Subtract 1 for the sign bit; + add 1 for integer division truncation; add 1 more for a minus sign. */ +# define INT_STRLEN_BOUND(t) ((sizeof (t) * CHAR_BIT - 1) * 302 / 1000 + 2) + + char ldavgbuf[3 * (INT_STRLEN_BOUND (long int) + sizeof ".00")]; + char const *ptr = ldavgbuf; int fd, count; - char *old_locale; fd = open (LINUX_LDAV_FILE, O_RDONLY); if (fd == -1) return -1; - count = read (fd, ldavgbuf, 40); + count = read (fd, ldavgbuf, sizeof ldavgbuf - 1); (void) close (fd); if (count <= 0) return -1; + ldavgbuf[count] = '\0'; - /* The following sscanf must use the C locale. */ - old_locale = setlocale (LC_NUMERIC, NULL); - if (old_locale) - old_locale = xstrdup (old_locale); - setlocale (LC_NUMERIC, "C"); - count = sscanf (ldavgbuf, "%lf %lf %lf", - &load_ave[0], &load_ave[1], &load_ave[2]); - setlocale (LC_NUMERIC, old_locale); - free (old_locale); - if (count < 1) - return -1; - - for (elem = 0; elem < nelem && elem < count; elem++) - loadavg[elem] = load_ave[elem]; + for (elem = 0; elem < nelem; elem++) + { + char *endptr; + double d = c_strtod (ptr, &endptr); + if (ptr == endptr) + { + if (elem == 0) + return -1; + break; + } + loadavg[elem] = d; + ptr = endptr; + } return elem; @@ -659,7 +649,7 @@ getloadavg (double loadavg[], int nelem) host_t host; struct processor_set_basic_info info; - unsigned info_count; + unsigned int info_count; /* We only know how to get the 1-minute average for this system, so even if the caller asks for more than 1, we only return 1. */ @@ -667,7 +657,7 @@ getloadavg (double loadavg[], int nelem) if (!getloadavg_initialized) { if (processor_set_default (host_self (), &default_set) == KERN_SUCCESS) - getloadavg_initialized = 1; + getloadavg_initialized = true; } if (getloadavg_initialized) @@ -676,7 +666,7 @@ getloadavg (double loadavg[], int nelem) if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, (processor_set_info_t) &info, &info_count) != KERN_SUCCESS) - getloadavg_initialized = 0; + getloadavg_initialized = false; else { if (nelem > 0) @@ -837,7 +827,7 @@ getloadavg (double loadavg[], int nelem) /* VMS specific code -- read from the Load Ave driver. */ LOAD_AVE_TYPE load_ave[3]; - static int getloadavg_initialized = 0; + static bool getloadavg_initialized; # ifdef eunice struct { @@ -857,7 +847,7 @@ getloadavg (double loadavg[], int nelem) $DESCRIPTOR (descriptor, "LAV0:"); # endif if (sys$assign (&descriptor, &channel, 0, 0) & 1) - getloadavg_initialized = 1; + getloadavg_initialized = true; } /* Read the load average vector. */ @@ -866,7 +856,7 @@ getloadavg (double loadavg[], int nelem) load_ave, 12, 0, 0, 0, 0) & 1)) { sys$dassgn (channel); - getloadavg_initialized = 0; + getloadavg_initialized = false; } if (!getloadavg_initialized) @@ -919,7 +909,7 @@ getloadavg (double loadavg[], int nelem) ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); if (ldav_off != -1) - offset = (long) ldav_off & 0x7fffffff; + offset = (long int) ldav_off & 0x7fffffff; # endif /* sgi */ } @@ -933,7 +923,7 @@ getloadavg (double loadavg[], int nelem) /* Set the channel to close on exec, so it does not litter any child's descriptor table. */ set_cloexec_flag (channel, true); - getloadavg_initialized = 1; + getloadavg_initialized = true; } # else /* SUNOS_5 */ /* We pass 0 for the kernel, corefile, and swapfile names @@ -944,7 +934,7 @@ getloadavg (double loadavg[], int nelem) /* nlist the currently running kernel. */ kvm_nlist (kd, nl); offset = nl[0].n_value; - getloadavg_initialized = 1; + getloadavg_initialized = true; } # endif /* SUNOS_5 */ } @@ -959,14 +949,14 @@ getloadavg (double loadavg[], int nelem) != sizeof (load_ave)) { close (channel); - getloadavg_initialized = 0; + getloadavg_initialized = false; } # else /* SUNOS_5 */ if (kvm_read (kd, offset, (char *) load_ave, sizeof (load_ave)) != sizeof (load_ave)) { kvm_close (kd); - getloadavg_initialized = 0; + getloadavg_initialized = false; } # endif /* SUNOS_5 */ } @@ -999,7 +989,7 @@ getloadavg (double loadavg[], int nelem) #endif /* ! HAVE_GETLOADAVG */ #ifdef TEST -void +int main (int argc, char **argv) { int naptime = 0; @@ -1017,7 +1007,7 @@ main (int argc, char **argv) if (loads == -1) { perror ("Error getting load average"); - exit (1); + return EXIT_FAILURE; } if (loads > 0) printf ("1-minute: %f ", avg[0]); @@ -1033,6 +1023,6 @@ main (int argc, char **argv) sleep (naptime); } - exit (0); + return EXIT_SUCCESS; } #endif /* TEST */ diff --git a/lib/getugroups.c b/lib/getugroups.c index b5e268777..dbd86ef93 100644 --- a/lib/getugroups.c +++ b/lib/getugroups.c @@ -1,5 +1,7 @@ /* getugroups.c -- return a list of the groups a user is in - Copyright (C) 1990, 1991, 1998, 1999, 2000, 2003 Free Software Foundation. + + Copyright (C) 1990, 1991, 1998, 1999, 2000, 2003, 2004 Free + Software Foundation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,6 +31,11 @@ # include #endif +#include +#ifndef EOVERFLOW +# define EOVERFLOW EINVAL +#endif + /* setgrent, getgrent, and endgrent are not specified by POSIX.1, so header files might not declare them. If you don't have them at all, we can't implement this function. @@ -88,6 +95,11 @@ getugroups (int maxcount, GETGROUPS_T *grouplist, char *username, gid_t gid) grouplist[count] = grp->gr_gid; } count++; + if (count < 0) + { + errno = EOVERFLOW; + return -1; + } } } } diff --git a/lib/hard-locale.c b/lib/hard-locale.c index 8c0ee8c77..67a4144a6 100644 --- a/lib/hard-locale.c +++ b/lib/hard-locale.c @@ -1,6 +1,7 @@ /* hard-locale.c -- Determine whether a locale is hard. - Copyright (C) 1997, 1998, 1999, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999, 2002, 2003, 2004 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,23 +30,23 @@ #include #include -/* Return nonzero if the current CATEGORY locale is hard, i.e. if you +/* Return true if the current CATEGORY locale is hard, i.e. if you can't get away with assuming traditional C or POSIX behavior. */ -int +bool hard_locale (int category) { #if ! HAVE_SETLOCALE - return 0; + return false; #else - int hard = 1; - char const *p = setlocale (category, 0); + bool hard = true; + char const *p = setlocale (category, NULL); if (p) { # if defined __GLIBC__ && 2 <= __GLIBC__ if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) - hard = 0; + hard = false; # else char *locale = malloc (strlen (p) + 1); if (locale) @@ -59,7 +60,7 @@ hard_locale (int category) && strcmp (p, locale) == 0) || ((p = setlocale (category, "POSIX")) && strcmp (p, locale) == 0)) - hard = 0; + hard = false; /* Restore the caller's locale. */ setlocale (category, locale); diff --git a/lib/hard-locale.h b/lib/hard-locale.h index ddc15d019..010cb2768 100644 --- a/lib/hard-locale.h +++ b/lib/hard-locale.h @@ -1,6 +1,6 @@ /* Determine whether a locale is hard. - Copyright (C) 1999, 2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,6 +19,8 @@ #ifndef HARD_LOCALE_H_ # define HARD_LOCALE_H_ 1 -int hard_locale (int); +# include + +bool hard_locale (int); #endif /* HARD_LOCALE_H_ */ diff --git a/lib/hash.c b/lib/hash.c index 945bb80f7..374c22681 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -1,7 +1,7 @@ /* hash - hashing table processing. - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software - Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free + Software Foundation, Inc. Written by Jim Meyering, 1992. @@ -400,9 +400,10 @@ hash_string (const char *string, size_t n_buckets) ((Byte) + ROTATE_LEFT (Value, 7)) size_t value = 0; + unsigned char ch; - for (; *string; string++) - value = HASH_ONE_CHAR (value, (unsigned char) *string); + for (; (ch = *string); string++) + value = HASH_ONE_CHAR (value, ch); return value % n_buckets; # undef ROTATE_LEFT @@ -420,9 +421,10 @@ size_t hash_string (const char *string, size_t n_buckets) { size_t value = 0; + unsigned char ch; - while (*string) - value = (value * 31 + (unsigned char) *string++) % n_buckets; + for (; (ch = *string); string++) + value = (value * 31 + ch) % n_buckets; return value; } diff --git a/lib/human.c b/lib/human.c index dbf536b1e..f024c73ea 100644 --- a/lib/human.c +++ b/lib/human.c @@ -300,8 +300,8 @@ human_readable (uintmax_t n, char *buf, int opts, { do { - unsigned r10 = (amt % base) * 10 + tenths; - unsigned r2 = (r10 % base) * 2 + (rounding >> 1); + unsigned int r10 = (amt % base) * 10 + tenths; + unsigned int r2 = (r10 % base) * 2 + (rounding >> 1); amt /= base; tenths = r10 / base; rounding = (r2 < base diff --git a/lib/human.h b/lib/human.h index 604fec1ba..b67ba4e9a 100644 --- a/lib/human.h +++ b/lib/human.h @@ -1,7 +1,7 @@ /* human.h -- print human readable file size - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free - Software Foundation, Inc. + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 + Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,12 +29,11 @@ # include # include -# if HAVE_INTTYPES_H -# include -# else -# if HAVE_STDINT_H -# include -# endif +# if HAVE_STDINT_H +# include +# endif +# if HAVE_UNISTD_H +# include # endif /* A conservative bound on the maximum length of a human-readable string. diff --git a/lib/lchown.c b/lib/lchown.c index 37320fb84..b04fb3646 100644 --- a/lib/lchown.c +++ b/lib/lchown.c @@ -22,46 +22,31 @@ #include #include #include -#ifndef errno -extern int errno; -#endif -#include "lchown.h" -#ifdef STAT_MACROS_BROKEN -# undef S_ISLNK -#endif - -#ifndef S_ISLNK -# ifdef S_IFLNK -# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -# else -# define S_ISLNK(m) 0 -# endif -#endif +#include "lchown.h" +#include "stat-macros.h" /* Declare chown to avoid a warning. Don't include unistd.h, because it may have a conflicting prototype for lchown. */ int chown (); /* Work just like chown, except when FILE is a symbolic link. - In that case, set errno to ENOSYS and return -1. + In that case, set errno to EOPNOTSUPP and return -1. But if autoconf tests determined that chown modifies symlinks, then just call chown. */ int lchown (const char *file, uid_t uid, gid_t gid) { -#if CHOWN_MODIFIES_SYMLINK - return chown (file, uid, gid); -#else +#if ! CHOWN_MODIFIES_SYMLINK struct stat stats; if (lstat (file, &stats) == 0 && S_ISLNK (stats.st_mode)) { - errno = ENOSYS; + errno = EOPNOTSUPP; return -1; } +#endif return chown (file, uid, gid); -#endif } diff --git a/lib/lchown.h b/lib/lchown.h index 46fa0ede0..d4824b171 100644 --- a/lib/lchown.h +++ b/lib/lchown.h @@ -1,9 +1,9 @@ -/* Some systems don't have ENOSYS. */ -#ifndef ENOSYS +/* Some systems don't have EOPNOTSUPP. */ +#ifndef EOPNOTSUPP # ifdef ENOTSUP -# define ENOSYS ENOTSUP +# define EOPNOTSUPP ENOTSUP # else /* Some systems don't have ENOTSUP either. */ -# define ENOSYS EINVAL +# define EOPNOTSUPP EINVAL # endif #endif diff --git a/lib/makepath.c b/lib/makepath.c index 422bcda82..1bc12c310 100644 --- a/lib/makepath.c +++ b/lib/makepath.c @@ -1,6 +1,6 @@ /* makepath.c -- Ensure that a directory path exists. - Copyright (C) 1990, 1997, 1998, 1999, 2000, 2002, 2003 Free + Copyright (C) 1990, 1997, 1998, 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -34,53 +34,10 @@ # include #endif -#if STAT_MACROS_BROKEN -# undef S_ISDIR -#endif - -#if !defined S_ISDIR && defined S_IFDIR -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif - -#ifndef S_IRWXUGO -# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) -#endif - #include - #include - -#ifndef errno -extern int errno; -#endif - #include -#ifndef S_ISUID -# define S_ISUID 04000 -#endif -#ifndef S_ISGID -# define S_ISGID 02000 -#endif -#ifndef S_ISVTX -# define S_ISVTX 01000 -#endif -#ifndef S_IRUSR -# define S_IRUSR 0200 -#endif -#ifndef S_IWUSR -# define S_IWUSR 0200 -#endif -#ifndef S_IXUSR -# define S_IXUSR 0100 -#endif - -#ifndef S_IRWXU -# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) -#endif - -#define WX_USR (S_IWUSR | S_IXUSR) - #include "gettext.h" #define _(msgid) gettext (msgid) @@ -88,6 +45,9 @@ extern int errno; #include "dirname.h" #include "error.h" #include "quote.h" +#include "stat-macros.h" + +#define WX_USR (S_IWUSR | S_IXUSR) #define CLEANUP_CWD \ do \ @@ -119,18 +79,19 @@ extern int errno; while (0) /* Attempt to create directory DIR (aka DIRPATH) with the specified MODE. - If CREATED_DIR_P is non-NULL, set *CREATED_DIR_P to non-zero if this - function creates DIR and to zero otherwise. Give a diagnostic and - return non-zero if DIR cannot be created or cannot be determined to + If CREATED_DIR_P is non-NULL, set *CREATED_DIR_P if this + function creates DIR and clear it otherwise. Give a diagnostic and + return false if DIR cannot be created or cannot be determined to exist already. Use DIRPATH in any diagnostic, not DIR. - Note that if DIR already exists, this function returns zero - (indicating success) and sets *CREATED_DIR_P to zero. */ + Note that if DIR already exists, this function returns true + (indicating success) and clears *CREATED_DIR_P. */ -int -make_dir (const char *dir, const char *dirpath, mode_t mode, int *created_dir_p) +bool +make_dir (const char *dir, const char *dirpath, mode_t mode, + bool *created_dir_p) { - int fail = 0; - int created_dir; + bool ok = true; + bool created_dir; created_dir = (mkdir (dir, mode) == 0); @@ -151,12 +112,12 @@ make_dir (const char *dir, const char *dirpath, mode_t mode, int *created_dir_p) { error (0, saved_errno, _("cannot create directory %s"), quote (dirpath)); - fail = 1; + ok = false; } else if (!S_ISDIR (stats.st_mode)) { error (0, 0, _("%s exists but is not a directory"), quote (dirpath)); - fail = 1; + ok = false; } else { @@ -167,7 +128,7 @@ make_dir (const char *dir, const char *dirpath, mode_t mode, int *created_dir_p) if (created_dir_p) *created_dir_p = created_dir; - return fail; + return ok; } /* Ensure that the directory ARGPATH exists. @@ -181,36 +142,36 @@ make_dir (const char *dir, const char *dirpath, mode_t mode, int *created_dir_p) If VERBOSE_FMT_STRING is nonzero, use it as a printf format string for printing a message after successfully making a directory, with the name of the directory that was just made as an argument. - If PRESERVE_EXISTING is non-zero and ARGPATH is an existing directory, + If PRESERVE_EXISTING is true and ARGPATH is an existing directory, then do not attempt to set its permissions and ownership. - Return 0 if ARGPATH exists as a directory with the proper - ownership and permissions when done, otherwise 1. */ + Return true iff ARGPATH exists as a directory with the proper + ownership and permissions when done. */ -int +bool make_path (const char *argpath, - int mode, - int parent_mode, + mode_t mode, + mode_t parent_mode, uid_t owner, gid_t group, - int preserve_existing, + bool preserve_existing, const char *verbose_fmt_string) { struct stat stats; - int retval = 0; + bool retval = true; if (stat (argpath, &stats)) { char *slash; - int tmp_mode; /* Initial perms for leading dirs. */ - int re_protect; /* Should leading dirs be unwritable? */ + mode_t tmp_mode; /* Initial perms for leading dirs. */ + bool re_protect; /* Should leading dirs be unwritable? */ struct ptr_list { char *dirname_end; struct ptr_list *next; }; struct ptr_list *p, *leading_dirs = NULL; - int do_chdir; /* Whether to chdir before each mkdir. */ + bool do_chdir; /* Whether to chdir before each mkdir. */ struct saved_cwd cwd; char *basename_dir; char *dirpath; @@ -231,23 +192,23 @@ make_path (const char *argpath, && (parent_mode & (S_ISUID | S_ISGID | S_ISVTX)) != 0)) { tmp_mode = S_IRWXU; - re_protect = 1; + re_protect = true; } else { tmp_mode = parent_mode; - re_protect = 0; + re_protect = false; } /* If we can record the current working directory, we may be able to do the chdir optimization. */ - do_chdir = !save_cwd (&cwd); + do_chdir = (save_cwd (&cwd) == 0); /* If we've saved the cwd and DIRPATH is an absolute pathname, we must chdir to `/' in order to enable the chdir optimization. So if chdir ("/") fails, turn off the optimization. */ if (do_chdir && *dirpath == '/' && chdir ("/") < 0) - do_chdir = 0; + do_chdir = false; slash = dirpath; @@ -257,8 +218,7 @@ make_path (const char *argpath, while (1) { - int newly_created_dir; - int fail; + bool newly_created_dir; /* slash points to the leftmost unprocessed component of dirpath. */ basename_dir = slash; @@ -273,11 +233,10 @@ make_path (const char *argpath, basename_dir = dirpath; *slash = '\0'; - fail = make_dir (basename_dir, dirpath, tmp_mode, &newly_created_dir); - if (fail) + if (! make_dir (basename_dir, dirpath, tmp_mode, &newly_created_dir)) { CLEANUP; - return 1; + return false; } if (newly_created_dir) @@ -295,7 +254,7 @@ make_path (const char *argpath, error (0, errno, _("cannot change owner and/or group of %s"), quote (dirpath)); CLEANUP; - return 1; + return false; } if (re_protect) @@ -317,7 +276,7 @@ make_path (const char *argpath, error (0, errno, _("cannot chdir to directory %s"), quote (dirpath)); CLEANUP; - return 1; + return false; } *slash++ = '/'; @@ -337,10 +296,10 @@ make_path (const char *argpath, /* We're done making leading directories. Create the final component of the path. */ - if (make_dir (basename_dir, dirpath, mode, NULL)) + if (! make_dir (basename_dir, dirpath, mode, NULL)) { CLEANUP; - return 1; + return false; } if (verbose_fmt_string != NULL) @@ -356,7 +315,7 @@ make_path (const char *argpath, { error (0, errno, _("cannot change owner and/or group of %s"), quote (dirpath)); - retval = 1; + retval = false; } } @@ -370,7 +329,7 @@ make_path (const char *argpath, { error (0, errno, _("cannot change permissions of %s"), quote (dirpath)); - retval = 1; + retval = false; } CLEANUP_CWD; @@ -385,7 +344,7 @@ make_path (const char *argpath, { error (0, errno, _("cannot change permissions of %s"), quote (dirpath)); - retval = 1; + retval = false; } } } @@ -398,7 +357,7 @@ make_path (const char *argpath, if (!S_ISDIR (stats.st_mode)) { error (0, 0, _("%s exists but is not a directory"), quote (dirpath)); - return 1; + return false; } if (!preserve_existing) @@ -418,13 +377,13 @@ make_path (const char *argpath, { error (0, errno, _("cannot change owner and/or group of %s"), quote (dirpath)); - retval = 1; + retval = false; } if (chmod (dirpath, mode)) { error (0, errno, _("cannot change permissions of %s"), quote (dirpath)); - retval = 1; + retval = false; } } } diff --git a/lib/makepath.h b/lib/makepath.h index 7c1bea8f4..67acef95c 100644 --- a/lib/makepath.h +++ b/lib/makepath.h @@ -1,7 +1,7 @@ /* makepath.c -- Ensure that a directory path exists. - Copyright (C) 1994, 1995, 1996, 1997, 2000, 2003 Free Software - Foundation, Inc. + Copyright (C) 1994, 1995, 1996, 1997, 2000, 2003, 2004 Free + Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,17 +19,18 @@ /* Written by David MacKenzie and Jim Meyering. */ +#include #include -int make_path (const char *_argpath, - int _mode, - int _parent_mode, - uid_t _owner, - gid_t _group, - int _preserve_existing, - const char *_verbose_fmt_string); - -int make_dir (const char *dir, - const char *dirpath, - mode_t mode, - int *created_dir_p); +bool make_path (const char *argpath, + mode_t mode, + mode_t parent_mode, + uid_t owner, + gid_t group, + bool preserve_existing, + const char *verbose_fmt_string); + +bool make_dir (const char *dir, + const char *dirpath, + mode_t mode, + bool *created_dir_p); diff --git a/lib/md5.c b/lib/md5.c index 2fc652cea..b938e1ca9 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -1,6 +1,6 @@ /* md5.c - Functions to compute MD5 message digest of files or memory blocks according to the definition of MD5 in RFC 1321 from April 1992. - Copyright (C) 1995, 1996, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 2001, 2003, 2004 Free Software Foundation, Inc. NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. @@ -26,9 +26,7 @@ #include "md5.h" -#include - -#include +#include #include #include "unlocked-io.h" @@ -246,13 +244,8 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) if (len >= 64) { #if !_STRING_ARCH_unaligned -/* To check alignment gcc has an appropriate operator. Other - compilers don't. */ -# if __GNUC__ >= 2 -# define UNALIGNED_P(p) (((md5_uintptr) p) % __alignof__ (md5_uint32) != 0) -# else -# define UNALIGNED_P(p) (((md5_uintptr) p) % sizeof (md5_uint32) != 0) -# endif +# define alignof(type) offsetof (struct { char c; type x; }, x) +# define UNALIGNED_P(p) (((size_t) p) % alignof (md5_uint32) != 0) if (UNALIGNED_P (buffer)) while (len > 64) { diff --git a/lib/md5.h b/lib/md5.h index 2b336073d..661de4bba 100644 --- a/lib/md5.h +++ b/lib/md5.h @@ -1,6 +1,9 @@ /* md5.h - Declaration of functions and data types used for MD5 sum computing library functions. - Copyright (C) 1995, 1996, 1999, 2000, 2003 Free Software Foundation, Inc. + + Copyright (C) 1995, 1996, 1999, 2000, 2003, 2004 Free Software + Foundation, Inc. + NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. @@ -22,42 +25,16 @@ #define _MD5_H 1 #include -#include -/* The following contortions are an attempt to use the C preprocessor - to determine an unsigned integral type that is 32 bits wide. An - alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but - doing that would require that the configure script compile and *run* - the resulting executable. Locally running cross-compiled executables - is usually not possible. */ - -#ifdef _LIBC +#if HAVE_INTTYPES_H +# include +#endif +#if HAVE_STDINT_H || _LIBC # include -typedef uint32_t md5_uint32; -typedef uintptr_t md5_uintptr; -#else -# define UINT_MAX_32_BITS 4294967295U - -# if UINT_MAX == UINT_MAX_32_BITS - typedef unsigned int md5_uint32; -# else -# if USHRT_MAX == UINT_MAX_32_BITS - typedef unsigned short md5_uint32; -# else -# if ULONG_MAX == UINT_MAX_32_BITS - typedef unsigned long md5_uint32; -# else - /* The following line is intended to evoke an error. - Using #error is not portable enough. */ - "Cannot determine unsigned 32-bit data type." -# endif -# endif -# endif -/* We have to make a guess about the integer type equivalent in size - to pointers which should always be correct. */ -typedef unsigned long int md5_uintptr; #endif +typedef uint32_t md5_uint32; + /* Structure to save state of computation between the single steps. */ struct md5_ctx { diff --git a/lib/memchr.c b/lib/memchr.c index ae232ae34..eacb5c935 100644 --- a/lib/memchr.c +++ b/lib/memchr.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003 Free +/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004 Free Software Foundation, Inc. Based on strlen implementation by Torbjorn Granlund (tege@sics.se), @@ -31,6 +31,8 @@ USA. */ #include +#include + #if defined _LIBC # include #else @@ -38,11 +40,7 @@ USA. */ #endif #include -#include - -#define LONG_MAX_32_BITS 2147483647 -#include #if HAVE_BP_SYM_H || defined _LIBC # include #else @@ -60,22 +58,22 @@ __memchr (void const *s, int c_in, size_t n) const unsigned long int *longword_ptr; unsigned long int longword, magic_bits, charmask; unsigned reg_char c; + int i; c = (unsigned char) c_in; /* Handle the first few characters by reading one character at a time. Do this until CHAR_PTR is aligned on a longword boundary. */ for (char_ptr = (const unsigned char *) s; - n > 0 && ((unsigned long int) char_ptr - & (sizeof (longword) - 1)) != 0; + n > 0 && (size_t) char_ptr % sizeof longword != 0; --n, ++char_ptr) if (*char_ptr == c) return (void *) char_ptr; /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ + but the theory applies equally well to any size longwords. */ - longword_ptr = (unsigned long int *) char_ptr; + longword_ptr = (const unsigned long int *) char_ptr; /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits the "holes." Note that there is a hole just to the left of @@ -87,26 +85,28 @@ __memchr (void const *s, int c_in, size_t n) The 1-bits make sure that carries propagate to the next 0-bit. The 0-bits provide holes for carries to fall into. */ - if (sizeof (longword) != 4 && sizeof (longword) != 8) - abort (); - -#if LONG_MAX <= LONG_MAX_32_BITS - magic_bits = 0x7efefeff; -#else - magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff; -#endif + /* Set MAGIC_BITS to be this pattern of 1 and 0 bits. + Set CHARMASK to be a longword, each of whose bytes is C. */ - /* Set up a longword, each of whose bytes is C. */ + magic_bits = 0xfefefefe; charmask = c | (c << 8); charmask |= charmask << 16; -#if LONG_MAX > LONG_MAX_32_BITS +#if 0xffffffffU < ULONG_MAX + magic_bits |= magic_bits << 32; charmask |= charmask << 32; + if (8 < sizeof longword) + for (i = 64; i < sizeof longword * 8; i *= 2) + { + magic_bits |= magic_bits << i; + charmask |= charmask << i; + } #endif + magic_bits = (ULONG_MAX >> 1) & (magic_bits | 1); /* Instead of the traditional loop which tests each character, we will test a longword at a time. The tricky part is testing if *any of the four* bytes in the longword in question are zero. */ - while (n >= sizeof (longword)) + while (n >= sizeof longword) { /* We tentatively exit the loop if adding MAGIC_BITS to LONGWORD fails to change any of the hole bits of LONGWORD. @@ -168,19 +168,21 @@ __memchr (void const *s, int c_in, size_t n) return (void *) &cp[2]; if (cp[3] == c) return (void *) &cp[3]; -#if LONG_MAX > 2147483647 - if (cp[4] == c) + if (4 < sizeof longword && cp[4] == c) return (void *) &cp[4]; - if (cp[5] == c) + if (5 < sizeof longword && cp[5] == c) return (void *) &cp[5]; - if (cp[6] == c) + if (6 < sizeof longword && cp[6] == c) return (void *) &cp[6]; - if (cp[7] == c) + if (7 < sizeof longword && cp[7] == c) return (void *) &cp[7]; -#endif + if (8 < sizeof longword) + for (i = 8; i < sizeof longword; i++) + if (cp[i] == c) + return (void *) &cp[i]; } - n -= sizeof (longword); + n -= sizeof longword; } char_ptr = (const unsigned char *) longword_ptr; diff --git a/lib/memcoll.c b/lib/memcoll.c index 34ae767db..e777e6a5b 100644 --- a/lib/memcoll.c +++ b/lib/memcoll.c @@ -1,5 +1,5 @@ /* Locale-specific memory comparison. - Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,10 +24,6 @@ #include "memcoll.h" #include -#ifndef errno -extern int errno; -#endif - #include /* Compare S1 (with length S1LEN) and S2 (with length S2LEN) according diff --git a/lib/memrchr.c b/lib/memrchr.c index 7d702f35e..e34d65ed0 100644 --- a/lib/memrchr.c +++ b/lib/memrchr.c @@ -1,6 +1,6 @@ /* memrchr -- find the last occurrence of a byte in a memory block - Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003 Free + Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004 Free Software Foundation, Inc. Based on strlen implementation by Torbjorn Granlund (tege@sics.se), @@ -27,10 +27,11 @@ # include #endif -#include #include -#if defined (_LIBC) +#include + +#if defined _LIBC # include #else # define reg_char char @@ -38,10 +39,6 @@ #include -#define LONG_MAX_32_BITS 2147483647 - -#include - #undef __memrchr #undef memrchr @@ -57,22 +54,22 @@ __memrchr (void const *s, int c_in, size_t n) const unsigned long int *longword_ptr; unsigned long int longword, magic_bits, charmask; unsigned reg_char c; + int i; c = (unsigned char) c_in; /* Handle the last few characters by reading one character at a time. Do this until CHAR_PTR is aligned on a longword boundary. */ for (char_ptr = (const unsigned char *) s + n; - n > 0 && ((unsigned long int) char_ptr - & (sizeof (longword) - 1)) != 0; + n > 0 && (size_t) char_ptr % sizeof longword != 0; --n) if (*--char_ptr == c) return (void *) char_ptr; /* All these elucidatory comments refer to 4-byte longwords, - but the theory applies equally well to 8-byte longwords. */ + but the theory applies equally well to any size longwords. */ - longword_ptr = (unsigned long int *) char_ptr; + longword_ptr = (const unsigned long int *) char_ptr; /* Bits 31, 24, 16, and 8 of this number are zero. Call these bits the "holes." Note that there is a hole just to the left of @@ -84,26 +81,28 @@ __memrchr (void const *s, int c_in, size_t n) The 1-bits make sure that carries propagate to the next 0-bit. The 0-bits provide holes for carries to fall into. */ - if (sizeof (longword) != 4 && sizeof (longword) != 8) - abort (); + /* Set MAGIC_BITS to be this pattern of 1 and 0 bits. + Set CHARMASK to be a longword, each of whose bytes is C. */ -#if LONG_MAX <= LONG_MAX_32_BITS - magic_bits = 0x7efefeff; -#else - magic_bits = ((unsigned long int) 0x7efefefe << 32) | 0xfefefeff; -#endif - - /* Set up a longword, each of whose bytes is C. */ + magic_bits = 0xfefefefe; charmask = c | (c << 8); charmask |= charmask << 16; -#if LONG_MAX > LONG_MAX_32_BITS +#if 0xffffffffU < ULONG_MAX + magic_bits |= magic_bits << 32; charmask |= charmask << 32; + if (8 < sizeof longword) + for (i = 64; i < sizeof longword * 8; i *= 2) + { + magic_bits |= magic_bits << i; + charmask |= charmask << i; + } #endif + magic_bits = (ULONG_MAX >> 1) & (magic_bits | 1); /* Instead of the traditional loop which tests each character, we will test a longword at a time. The tricky part is testing if *any of the four* bytes in the longword in question are zero. */ - while (n >= sizeof (longword)) + while (n >= sizeof longword) { /* We tentatively exit the loop if adding MAGIC_BITS to LONGWORD fails to change any of the hole bits of LONGWORD. @@ -157,16 +156,18 @@ __memrchr (void const *s, int c_in, size_t n) const unsigned char *cp = (const unsigned char *) longword_ptr; -#if LONG_MAX > 2147483647 - if (cp[7] == c) + if (8 < sizeof longword) + for (i = sizeof longword - 1; 8 <= i; i--) + if (cp[i] == c) + return (void *) &cp[i]; + if (7 < sizeof longword && cp[7] == c) return (void *) &cp[7]; - if (cp[6] == c) + if (6 < sizeof longword && cp[6] == c) return (void *) &cp[6]; - if (cp[5] == c) + if (5 < sizeof longword && cp[5] == c) return (void *) &cp[5]; - if (cp[4] == c) + if (4 < sizeof longword && cp[4] == c) return (void *) &cp[4]; -#endif if (cp[3] == c) return (void *) &cp[3]; if (cp[2] == c) @@ -177,7 +178,7 @@ __memrchr (void const *s, int c_in, size_t n) return (void *) cp; } - n -= sizeof (longword); + n -= sizeof longword; } char_ptr = (const unsigned char *) longword_ptr; diff --git a/lib/modechange.c b/lib/modechange.c index c9bdbe7bd..b4df3388c 100644 --- a/lib/modechange.c +++ b/lib/modechange.c @@ -1,7 +1,7 @@ /* modechange.c -- file mode manipulation - Copyright (C) 1989, 1990, 1997, 1998, 1999, 2001, 2003 Free Software - Foundation, Inc. + Copyright (C) 1989, 1990, 1997, 1998, 1999, 2001, 2003, 2004 Free + Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ #include "modechange.h" #include #include "xstrtol.h" +#include #include #include @@ -220,12 +221,10 @@ mode_compile (const char *mode_string, unsigned int masked_ops) /* `affected_bits' modified by umask. */ mode_t affected_masked; /* Operators to actually use umask on. */ - unsigned ops_to_mask = 0; + unsigned int ops_to_mask = 0; - int who_specified_p; + bool who_specified_p; - affected_bits = 0; - ops_to_mask = 0; /* Turn on all the bits in `affected_bits' for each group given. */ for (++mode_string;; ++mode_string) switch (*mode_string) @@ -250,10 +249,10 @@ mode_compile (const char *mode_string, unsigned int masked_ops) /* If none specified, affect all bits, except perhaps those set in the umask. */ if (affected_bits) - who_specified_p = 1; + who_specified_p = true; else { - who_specified_p = 0; + who_specified_p = false; affected_bits = CHMOD_MODE_BITS; ops_to_mask = masked_ops; } diff --git a/lib/modechange.h b/lib/modechange.h index be2afa45c..8bf989455 100644 --- a/lib/modechange.h +++ b/lib/modechange.h @@ -1,5 +1,5 @@ /* modechange.h -- definitions for file mode manipulation - Copyright (C) 1989, 1990, 1997, 2003 Free Software Foundation, Inc. + Copyright (C) 1989, 1990, 1997, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,7 +51,7 @@ struct mode_change # define MODE_MEMORY_EXHAUSTED (struct mode_change *) 1 # define MODE_BAD_REFERENCE (struct mode_change *) 2 -struct mode_change *mode_compile (const char *, unsigned); +struct mode_change *mode_compile (const char *, unsigned int); struct mode_change *mode_create_from_ref (const char *); mode_t mode_adjust (mode_t, const struct mode_change *); void mode_free (struct mode_change *); diff --git a/lib/mountlist.c b/lib/mountlist.c index 631be3123..c9c146336 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -1,4 +1,4 @@ -/* mountlist.c -- return a list of mounted filesystems +/* mountlist.c -- return a list of mounted file systems Copyright (C) 1991, 1992, 1997-2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -26,18 +26,11 @@ #include "xalloc.h" -#ifndef SIZE_MAX -# define SIZE_MAX ((size_t) -1) -#endif - #ifndef strstr char *strstr (); #endif #include -#ifndef errno -extern int errno; -#endif #ifdef HAVE_FCNTL_H # include @@ -143,39 +136,15 @@ extern int errno; #include "mountlist.h" #include "unlocked-io.h" -#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */ -/* Return the value of the hexadecimal number represented by CP. - No prefix (like '0x') or suffix (like 'h') is expected to be - part of CP. */ -/* FIXME: this can overflow */ - -static int -xatoi (char *cp) -{ - int val; - - val = 0; - while (*cp) - { - if (*cp >= 'a' && *cp <= 'f') - val = val * 16 + *cp - 'a' + 10; - else if (*cp >= 'A' && *cp <= 'F') - val = val * 16 + *cp - 'A' + 10; - else if (*cp >= '0' && *cp <= '9') - val = val * 16 + *cp - '0'; - else - break; - cp++; - } - return val; -} -#endif /* MOUNTED_GETMNTENT1. */ +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif #if MOUNTED_GETMNTINFO # if ! HAVE_F_FSTYPENAME_IN_STATFS static char * -fstype_to_string (short t) +fstype_to_string (short int t) { switch (t) { @@ -296,13 +265,13 @@ fstype_to_string (int t) } #endif /* MOUNTED_VMOUNT */ -/* Return a list of the currently mounted filesystems, or NULL on error. +/* Return a list of the currently mounted file systems, or NULL on error. Add each entry to the tail of the list so that they stay in order. - If NEED_FS_TYPE is nonzero, ensure that the filesystem type fields in + If NEED_FS_TYPE is true, ensure that the file system type fields in the returned list are valid. Otherwise, they might not be. */ struct mount_entry * -read_filesystem_list (int need_fs_type) +read_file_system_list (bool need_fs_type) { struct mount_entry *mount_list; struct mount_entry *me; @@ -360,12 +329,7 @@ read_filesystem_list (int need_fs_type) me->me_remote = ME_REMOTE (me->me_devname, me->me_type); devopt = strstr (mnt->mnt_opts, "dev="); if (devopt) - { - if (devopt[4] == '0' && (devopt[5] == 'x' || devopt[5] == 'X')) - me->me_dev = xatoi (devopt + 6); - else - me->me_dev = xatoi (devopt + 4); - } + me->me_dev = strtoul (devopt + 4, NULL, 16); else me->me_dev = (dev_t) -1; /* Magic; means not known yet. */ @@ -438,14 +402,14 @@ read_filesystem_list (int need_fs_type) #if defined MOUNTED_FS_STAT_DEV /* BeOS */ { /* The next_dev() and fs_stat_dev() system calls give the list of - all filesystems, including the information returned by statvfs() + all file systems, including the information returned by statvfs() (fs type, total blocks, free blocks etc.), but without the mount - point. But on BeOS all filesystems except / are mounted in the + point. But on BeOS all file systems except / are mounted in the rootfs, directly under /. The directory name of the mount point is often, but not always, identical to the volume name of the device. We therefore get the list of subdirectories of /, and the list - of all filesystems, and match the two lists. */ + of all file systems, and match the two lists. */ DIR *dirp; struct rootdir_entry @@ -744,12 +708,12 @@ read_filesystem_list (int need_fs_type) int n_entries; int i; - /* Ask how many bytes to allocate for the mounted filesystem info. */ + /* Ask how many bytes to allocate for the mounted file system info. */ if (mntctl (MCTL_QUERY, sizeof bufsize, (struct vmount *) &bufsize) != 0) return NULL; entries = xmalloc (bufsize); - /* Get the list of mounted filesystems. */ + /* Get the list of mounted file systems. */ n_entries = mntctl (MCTL_QUERY, bufsize, (struct vmount *) entries); if (n_entries < 0) { diff --git a/lib/mountlist.h b/lib/mountlist.h index 9e550a082..c3694c211 100644 --- a/lib/mountlist.h +++ b/lib/mountlist.h @@ -1,6 +1,6 @@ -/* mountlist.h -- declarations for list of mounted filesystems +/* mountlist.h -- declarations for list of mounted file systems - Copyright (C) 1991, 1992, 1998, 2000, 2001, 2002, 2003 Free + Copyright (C) 1991, 1992, 1998, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include + /* A mount table entry. */ struct mount_entry { @@ -24,13 +26,13 @@ struct mount_entry char *me_mountdir; /* Mount point directory pathname. */ char *me_type; /* "nfs", "4.2", etc. */ dev_t me_dev; /* Device number of me_mountdir. */ - unsigned int me_dummy : 1; /* Nonzero for dummy filesystems. */ + unsigned int me_dummy : 1; /* Nonzero for dummy file systems. */ unsigned int me_remote : 1; /* Nonzero for remote fileystems. */ unsigned int me_type_malloced : 1; /* Nonzero if me_type was malloced. */ struct mount_entry *me_next; }; -struct mount_entry *read_filesystem_list (int need_fs_type); +struct mount_entry *read_file_system_list (bool need_fs_type); #ifndef ME_DUMMY # define ME_DUMMY(Fs_name, Fs_type) \ diff --git a/lib/nanosleep.c b/lib/nanosleep.c index c5451ffc4..2f91c31d8 100644 --- a/lib/nanosleep.c +++ b/lib/nanosleep.c @@ -23,14 +23,12 @@ prototype for rpl_nanosleep. (they'd conflict e.g., on alpha-dec-osf3.2) */ #undef nanosleep +#include #include #include #include #include -#ifndef errno -extern int errno; -#endif #if HAVE_UNISTD_H # include @@ -77,7 +75,7 @@ int rpl_nanosleep (const struct timespec *requested_delay, struct timespec *remaining_delay) { - static int initialized; + static bool initialized; #ifdef SA_NOCLDSTOP struct sigaction oldact, newact; @@ -100,7 +98,7 @@ rpl_nanosleep (const struct timespec *requested_delay, if (signal (SIGCONT, SIG_IGN) != SIG_IGN) signal (SIGCONT, sighandler); #endif - initialized = 1; + initialized = true; } my_usleep (requested_delay); diff --git a/lib/posixtm.c b/lib/posixtm.c index 7ddf182ff..22f636ebb 100644 --- a/lib/posixtm.c +++ b/lib/posixtm.c @@ -1,5 +1,7 @@ /* Parse dates for touch and date. - Copyright (C) 1989, 1990, 1991, 1998, 2000-2003 Free Software Foundation Inc. + + Copyright (C) 1989, 1990, 1991, 1998, 2000, 2001, 2002, 2003, 2004 + Free Software Foundation Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +47,7 @@ POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless it's important to use the locale's definition of `digit' even when the host does not conform to POSIX. */ -#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) +#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9) time_t mktime (); @@ -113,7 +115,7 @@ posix_time_parse (struct tm *tm, const char *s, unsigned int syntax_bits) const char *dot = NULL; int pair[6]; int *p; - unsigned int i; + size_t i; size_t s_len = strlen (s); size_t len = (((syntax_bits & PDS_SECONDS) && (dot = strchr (s, '.'))) @@ -304,7 +306,7 @@ main (void) { printf ("%-15s %2u ", time_str, syntax_bits); if (posixtime (&t, time_str, syntax_bits)) - printf ("%12ld %s", (long) t, ctime (&t)); + printf ("%12ld %s", (long int) t, ctime (&t)); else printf ("%12s %s", "*", "*\n"); } diff --git a/lib/putenv.c b/lib/putenv.c index 87c552281..1c097ccc4 100644 --- a/lib/putenv.c +++ b/lib/putenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1994, 1997, 1998, 2000, 2003 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1994, 1997, 1998, 2000, 2003, 2004 Free Software Foundation, Inc. NOTE: The canonical source of this file is maintained with the GNU C Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. @@ -26,10 +26,7 @@ /* Include errno.h *after* sys/types.h to work around header problems on AIX 3.2.5. */ #include -#if !_LIBC -# if !defined errno -extern int errno; -# endif +#ifndef __set_errno # define __set_errno(ev) ((errno) = (ev)) #endif diff --git a/lib/quotearg.c b/lib/quotearg.c index fe747fb0b..64fa67635 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -192,8 +193,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, size_t len = 0; char const *quote_string = 0; size_t quote_string_len = 0; - int backslash_escapes = 0; - int unibyte_locale = MB_CUR_MAX == 1; + bool backslash_escapes = false; + bool unibyte_locale = MB_CUR_MAX == 1; #define STORE(c) \ do \ @@ -208,13 +209,13 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, { case c_quoting_style: STORE ('"'); - backslash_escapes = 1; + backslash_escapes = true; quote_string = "\""; quote_string_len = 1; break; case escape_quoting_style: - backslash_escapes = 1; + backslash_escapes = true; break; case locale_quoting_style: @@ -239,7 +240,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, char const *right = gettext_quote (N_("'"), quoting_style); for (quote_string = left; *quote_string; quote_string++) STORE (*quote_string); - backslash_escapes = 1; + backslash_escapes = true; quote_string = right; quote_string_len = strlen (quote_string); } @@ -396,12 +397,12 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, /* Length of multibyte sequence found so far. */ size_t m; - int printable; + bool printable; if (unibyte_locale) { m = 1; - printable = isprint (c); + printable = isprint (c) != 0; } else { @@ -409,7 +410,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, memset (&mbstate, 0, sizeof mbstate); m = 0; - printable = 1; + printable = true; if (argsize == SIZE_MAX) argsize = strlen (arg); @@ -422,12 +423,12 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, break; else if (bytes == (size_t) -1) { - printable = 0; + printable = false; break; } else if (bytes == (size_t) -2) { - printable = 0; + printable = false; while (i + m < argsize && arg[i + m]) m++; break; @@ -449,9 +450,9 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, goto use_shell_always_quoting_style; } } - + if (! iswprint (w)) - printable = 0; + printable = false; m += bytes; } } diff --git a/lib/quotearg.h b/lib/quotearg.h index 2bbf38d92..14dc316d7 100644 --- a/lib/quotearg.h +++ b/lib/quotearg.h @@ -29,7 +29,7 @@ enum quoting_style { /* Output names as-is (ls --quoting-style=literal). */ literal_quoting_style, - + /* Quote names for the shell if they contain shell metacharacters or would cause ambiguous output (ls --quoting-style=shell). */ shell_quoting_style, diff --git a/lib/readtokens.c b/lib/readtokens.c index 438441c4e..2ccf6a938 100644 --- a/lib/readtokens.c +++ b/lib/readtokens.c @@ -96,7 +96,10 @@ readtoken (FILE *stream, saved_delim = delim; memset (isdelim, 0, sizeof isdelim); for (j = 0; j < n_delim; j++) - isdelim[(unsigned char) delim[j]] = 1; + { + unsigned char ch = delim[j]; + isdelim[ch] = 1; + } } /* FIXME: don't fool with this caching. Use strchr instead. */ diff --git a/lib/readutmp.c b/lib/readutmp.c index 896e976dc..91d341a96 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -40,28 +40,31 @@ extract_trimmed_name (const STRUCT_UTMP *ut) trimmed_name = xmalloc (sizeof (UT_USER (ut)) + 1); strncpy (trimmed_name, UT_USER (ut), sizeof (UT_USER (ut))); - /* Append a trailing space character. Some systems pad names shorter than - the maximum with spaces, others pad with NULs. Remove any spaces. */ - trimmed_name[sizeof (UT_USER (ut))] = ' '; - p = strchr (trimmed_name, ' '); - if (p != NULL) - *p = '\0'; + /* Append a trailing NUL. Some systems pad names shorter than the + maximum with spaces, others pad with NULs. Remove any trailing + spaces. */ + trimmed_name[sizeof (UT_USER (ut))] = '\0'; + for (p = trimmed_name + strlen (trimmed_name); + trimmed_name < p && p[-1] == ' '; + *--p = '\0') + continue; return trimmed_name; } /* Read the utmp entries corresponding to file FILENAME into freshly- malloc'd storage, set *UTMP_BUF to that pointer, set *N_ENTRIES to the number of entries, and return zero. If there is any error, - return non-zero and don't modify the parameters. */ + return -1, setting errno, and don't modify the parameters. */ #ifdef UTMP_NAME_FUNCTION int -read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf) +read_utmp (const char *filename, size_t *n_entries, STRUCT_UTMP **utmp_buf) { - int n_read; + size_t n_read; + size_t n_alloc = 4; + STRUCT_UTMP *utmp = xmalloc (n_alloc * sizeof *utmp); STRUCT_UTMP *u; - STRUCT_UTMP *utmp = NULL; /* Ignore the return value for now. Solaris' utmpname returns 1 upon success -- which is contrary @@ -74,16 +77,12 @@ read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf) n_read = 0; while ((u = GET_UTMP_ENT ()) != NULL) { - STRUCT_UTMP *p; - ++n_read; - p = (STRUCT_UTMP *) realloc (utmp, n_read * sizeof (STRUCT_UTMP)); - if (p == NULL) + if (n_read == n_alloc) { - free (utmp); - END_UTMP_ENT (); - return 1; + utmp = xnrealloc (utmp, n_alloc, 2 * sizeof *utmp); + n_alloc *= 2; } - utmp = p; + ++n_read; utmp[n_read - 1] = *u; } @@ -98,7 +97,7 @@ read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf) #else int -read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf) +read_utmp (const char *filename, size_t *n_entries, STRUCT_UTMP **utmp_buf) { FILE *utmp; struct stat file_stats; @@ -108,14 +107,14 @@ read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf) utmp = fopen (filename, "r"); if (utmp == NULL) - return 1; + return -1; if (fstat (fileno (utmp), &file_stats) != 0) { int e = errno; fclose (utmp); errno = e; - return 1; + return -1; } size = file_stats.st_size; buf = xmalloc (size); @@ -126,14 +125,14 @@ read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf) free (buf); fclose (utmp); errno = e; - return 1; + return -1; } if (fclose (utmp) != 0) { int e = errno; free (buf); errno = e; - return 1; + return -1; } *n_entries = n_read; diff --git a/lib/readutmp.h b/lib/readutmp.h index be59fe994..100db19c5 100644 --- a/lib/readutmp.h +++ b/lib/readutmp.h @@ -1,7 +1,7 @@ /* Declarations for GNU's read utmp module. Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, - 2001, 2002, 2003 Free Software Foundation, Inc. + 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -116,11 +116,11 @@ # else # if HAVE_STRUCT_UTMP_UT_USER -# define UT_USER(Utmp) Utmp->ut_user +# define UT_USER(Utmp) ((Utmp)->ut_user) # endif # if HAVE_STRUCT_UTMP_UT_NAME # undef UT_USER -# define UT_USER(Utmp) Utmp->ut_name +# define UT_USER(Utmp) ((Utmp)->ut_name) # endif # endif @@ -143,6 +143,8 @@ typedef struct UTMP_STRUCT_NAME STRUCT_UTMP; +enum { UT_USER_SIZE = sizeof UT_USER ((STRUCT_UTMP *) 0) }; + # include # ifdef HAVE_SYS_PARAM_H # include @@ -180,6 +182,6 @@ extern int errno; # endif char *extract_trimmed_name (const STRUCT_UTMP *ut); -int read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf); +int read_utmp (const char *filename, size_t *n_entries, STRUCT_UTMP **utmp_buf); #endif /* __READUTMP_H__ */ diff --git a/lib/rmdir.c b/lib/rmdir.c index 5315711c3..ddb5c30b2 100644 --- a/lib/rmdir.c +++ b/lib/rmdir.c @@ -1,6 +1,6 @@ /* BSD compatible remove directory function for System V - Copyright (C) 1988, 1990, 1999, 2003 Free Software Foundation, Inc. + Copyright (C) 1988, 1990, 1999, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,19 +22,9 @@ #include #include - #include -#ifndef errno -extern int errno; -#endif -#if STAT_MACROS_BROKEN -# undef S_ISDIR -#endif - -#if !defined(S_ISDIR) && defined(S_IFDIR) -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif +#include "stat-macros.h" /* rmdir adapted from GNU tar. */ diff --git a/lib/safe-read.c b/lib/safe-read.c index c21d1cf19..6f8bd780e 100644 --- a/lib/safe-read.c +++ b/lib/safe-read.c @@ -1,5 +1,7 @@ /* An interface to read and write that retries after interrupts. - Copyright (C) 1993, 1994, 1998, 2002-2003 Free Software Foundation, Inc. + + Copyright (C) 1993, 1994, 1998, 2002, 2003, 2004 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,9 +35,6 @@ #endif #include -#ifndef errno -extern int errno; -#endif #ifdef EINTR # define IS_EINTR(x) ((x) == EINTR) @@ -61,22 +60,23 @@ extern int errno; size_t safe_rw (int fd, void const *buf, size_t count) { - ssize_t result; - - /* POSIX limits COUNT to SSIZE_MAX, but we limit it further, requiring - that COUNT <= INT_MAX, to avoid triggering a bug in Tru64 5.1. - When decreasing COUNT, keep the file pointer block-aligned. - Note that in any case, read(write) may succeed, yet read(write) - fewer than COUNT bytes, so the caller must be prepared to handle - partial results. */ - if (count > INT_MAX) - count = INT_MAX & ~8191; + /* Work around a bug in Tru64 5.1. Attempting to read more than + INT_MAX bytes fails with errno == EINVAL. See + . + When decreasing COUNT, keep it block-aligned. */ + enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 }; - do + for (;;) { - result = rw (fd, buf, count); - } - while (result < 0 && IS_EINTR (errno)); + ssize_t result = rw (fd, buf, count); - return (size_t) result; + if (0 <= result) + return result; + else if (IS_EINTR (errno)) + continue; + else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count) + count = BUGGY_READ_MAXIMUM; + else + return result; + } } diff --git a/lib/save-cwd.c b/lib/save-cwd.c index 17d077db8..93b1fe85c 100644 --- a/lib/save-cwd.c +++ b/lib/save-cwd.c @@ -21,6 +21,7 @@ # include "config.h" #endif +#include #include #include @@ -35,9 +36,6 @@ #endif #include -#ifndef errno -extern int errno; -#endif #ifndef O_DIRECTORY # define O_DIRECTORY 0 @@ -66,7 +64,7 @@ extern int errno; int save_cwd (struct saved_cwd *cwd) { - static int have_working_fchdir = 1; + static bool have_working_fchdir = true; cwd->desc = -1; cwd->name = NULL; @@ -80,7 +78,7 @@ save_cwd (struct saved_cwd *cwd) if (cwd->desc < 0) { cwd->name = xgetcwd (); - return cwd->name == NULL; + return cwd->name ? 0 : -1; } # if __sun__ || sun @@ -92,7 +90,7 @@ save_cwd (struct saved_cwd *cwd) { close (cwd->desc); cwd->desc = -1; - have_working_fchdir = 0; + have_working_fchdir = false; } else { @@ -100,13 +98,13 @@ save_cwd (struct saved_cwd *cwd) close (cwd->desc); cwd->desc = -1; errno = saved_errno; - return 1; + return -1; } } # endif /* __sun__ || sun */ #else # define fchdir(x) (abort (), 0) - have_working_fchdir = 0; + have_working_fchdir = false; #endif } @@ -114,22 +112,22 @@ save_cwd (struct saved_cwd *cwd) { cwd->name = xgetcwd (); if (cwd->name == NULL) - return 1; + return -1; } return 0; } /* Change to recorded location, CWD, in directory hierarchy. - Upon failure, return nonzero (errno is set by chdir or fchdir). + Upon failure, return -1 (errno is set by chdir or fchdir). Upon success, return zero. */ int restore_cwd (const struct saved_cwd *cwd) { if (0 <= cwd->desc) - return fchdir (cwd->desc) < 0; + return fchdir (cwd->desc); else - return chdir (cwd->name) < 0; + return chdir (cwd->name); } void diff --git a/lib/savedir.c b/lib/savedir.c index 1cab9b6c5..c92e62ead 100644 --- a/lib/savedir.c +++ b/lib/savedir.c @@ -1,7 +1,7 @@ /* savedir.c -- save the list of files in a directory in a string - Copyright 1990, 1997, 1998, 1999, 2000, 2001, 2003 Free Software - Foundation, Inc. + Copyright 1990, 1997, 1998, 1999, 2000, 2001, 2003, 2004 Free + Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,9 +28,6 @@ #include #include -#ifndef errno -extern int errno; -#endif #if HAVE_DIRENT_H # include @@ -89,7 +86,7 @@ savedir (const char *dir) while ((dp = readdir (dirp)) != NULL) { /* Skip "", ".", and "..". "" is returned by at least one buggy - implementation: Solaris 2.4 readdir on NFS filesystems. */ + implementation: Solaris 2.4 readdir on NFS file systems. */ char const *entry = dp->d_name; if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0') { diff --git a/lib/setenv.c b/lib/setenv.c index c3f9dc4ca..320469b86 100644 --- a/lib/setenv.c +++ b/lib/setenv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992,1995-1999,2000-2003 Free Software Foundation, Inc. +/* Copyright (C) 1992,1995-1999,2000-2004 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -21,10 +21,7 @@ #include #include -#if !_LIBC -# if !defined errno && !defined HAVE_ERRNO_DECL -extern int errno; -# endif +#ifndef __set_errno # define __set_errno(ev) ((errno) = (ev)) #endif diff --git a/lib/sig2str.c b/lib/sig2str.c index f1eec22bf..15d969c86 100644 --- a/lib/sig2str.c +++ b/lib/sig2str.c @@ -1,6 +1,6 @@ /* sig2str.c -- convert between signal names and numbers - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -253,7 +253,7 @@ static struct numname { int num; char const name[8]; } numname_table[] = POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless it's important to use the locale's definition of `digit' even when the host does not conform to POSIX. */ -#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) +#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9) /* Convert the signal name SIGNAME to a signal number. Return the signal number if successful, -1 otherwise. */ @@ -270,7 +270,7 @@ str2signum (char const *signame) } else { - unsigned i; + unsigned int i; for (i = 0; i < NUMNAME_ENTRIES; i++) if (strcmp (numname_table[i].name, signame) == 0) return numname_table[i].num; @@ -315,7 +315,7 @@ str2sig (char const *signame, int *signum) int sig2str (int signum, char *signame) { - unsigned i; + unsigned int i; for (i = 0; i < NUMNAME_ENTRIES; i++) if (numname_table[i].num == signum) { diff --git a/lib/stat.c b/lib/stat.c index f8fc82ebc..df0be3a81 100644 --- a/lib/stat.c +++ b/lib/stat.c @@ -3,7 +3,7 @@ has this bug. Also work around a deficiency in Solaris systems (up to at least Solaris 9) regarding the semantics of `lstat ("symlink/", sbuf).' - Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -27,25 +27,11 @@ #include #include #include -#ifndef errno -extern int errno; -#endif #if defined LSTAT && ! LSTAT_FOLLOWS_SLASHED_SYMLINK # include # include -# ifdef STAT_MACROS_BROKEN -# undef S_ISLNK -# endif - -# ifndef S_ISLNK -# ifdef S_IFLNK -# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -# else -# define S_ISLNK(m) 0 -# endif -# endif - +# include "stat-macros.h" # include "xalloc.h" /* lstat works differently on Linux and Solaris systems. POSIX (see diff --git a/lib/strtoimax.c b/lib/strtoimax.c index 4ce741cfd..a1fd3b152 100644 --- a/lib/strtoimax.c +++ b/lib/strtoimax.c @@ -1,5 +1,7 @@ /* Convert string representation of a number into an intmax_t value. - Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc. + + Copyright (C) 1999, 2001, 2002, 2003, 2004 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,7 +25,8 @@ #if HAVE_INTTYPES_H # include -#elif HAVE_STDINT_H +#endif +#if HAVE_STDINT_H # include #endif @@ -66,14 +69,14 @@ strtoimax (char const *ptr, char **endptr, int base) { #if HAVE_LONG_LONG verify (size_is_that_of_long_or_long_long, - (sizeof (INT) == sizeof (long) - || sizeof (INT) == sizeof (long long))); + (sizeof (INT) == sizeof (long int) + || sizeof (INT) == sizeof (long long int))); - if (sizeof (INT) != sizeof (long)) + if (sizeof (INT) != sizeof (long int)) return strtoll (ptr, endptr, base); #else verify (size_is_that_of_long, - sizeof (INT) == sizeof (long)); + sizeof (INT) == sizeof (long int)); #endif return strtol (ptr, endptr, base); diff --git a/lib/strverscmp.c b/lib/strverscmp.c index df4f5c08a..83b7f90bd 100644 --- a/lib/strverscmp.c +++ b/lib/strverscmp.c @@ -1,5 +1,5 @@ /* Compare strings while treating digits characters numerically. - Copyright (C) 1997, 2000, 2002 Free Software Foundation, Inc. + Copyright (C) 1997, 2000, 2002, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jean-François Bignolles , 1997. @@ -43,7 +43,7 @@ POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless it's important to use the locale's definition of `digit' even when the host does not conform to POSIX. */ -#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) +#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9) #undef __strverscmp #undef strverscmp diff --git a/lib/userspec.c b/lib/userspec.c index a997c6ff4..820c71027 100644 --- a/lib/userspec.c +++ b/lib/userspec.c @@ -27,6 +27,7 @@ #include +#include #include #include #include @@ -44,6 +45,7 @@ # include #endif +#include "inttostr.h" #include "strdup.h" #include "xalloc.h" #include "xstrtol.h" @@ -96,9 +98,9 @@ struct group *getgrgid (); #define V_STRDUP(dest, src) \ do \ { \ - int _len = strlen ((src)); \ - (dest) = (char *) alloca (_len + 1); \ - strcpy (dest, src); \ + size_t size = strlen (src) + 1; \ + (dest) = (char *) alloca (size); \ + memcpy (dest, src, size); \ } \ while (0) @@ -109,19 +111,25 @@ struct group *getgrgid (); POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless it's important to use the locale's definition of `digit' even when the host does not conform to POSIX. */ -#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) +#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9) -/* Return nonzero if STR represents an unsigned decimal integer, - otherwise return 0. */ +#ifdef __DJGPP__ + +/* Return true if STR represents an unsigned decimal integer. */ -static int +static bool is_number (const char *str) { - for (; *str; str++) - if (!ISDIGIT (*str)) - return 0; - return 1; + do + { + if (!ISDIGIT (*str)) + return false; + } + while (*++str); + + return true; } +#endif /* Extract from NAME, which has the form "[user][:.][group]", a USERNAME, UID U, GROUPNAME, and GID G. @@ -209,23 +217,16 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid, pwd = getpwnam (u); if (pwd == NULL) { - - if (!is_number (u)) - error_msg = E_invalid_user; + bool use_login_group = (separator != NULL && g == NULL); + if (use_login_group) + error_msg = E_bad_spec; else { - int use_login_group; - use_login_group = (separator != NULL && g == NULL); - if (use_login_group) - error_msg = E_bad_spec; - else - { - unsigned long int tmp_long; - if (xstrtoul (u, NULL, 0, &tmp_long, NULL) != LONGINT_OK - || tmp_long > MAXUID) - return _(E_invalid_user); - *uid = tmp_long; - } + unsigned long int tmp_long; + if (! (xstrtoul (u, NULL, 10, &tmp_long, "") == LONGINT_OK + && tmp_long <= MAXUID)) + return _(E_invalid_user); + *uid = tmp_long; } } else @@ -239,12 +240,9 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid, grp = getgrgid (pwd->pw_gid); if (grp == NULL) { - /* This is enough room to hold the unsigned decimal - representation of any 32-bit quantity and the trailing - zero byte. */ - char uint_buf[21]; - sprintf (uint_buf, "%u", (unsigned) (pwd->pw_gid)); - V_STRDUP (groupname, uint_buf); + char buf[INT_BUFSIZE_BOUND (uintmax_t)]; + char const *num = umaxtostr (pwd->pw_gid, buf); + V_STRDUP (groupname, num); } else { @@ -262,16 +260,11 @@ parse_user_spec (const char *spec_arg, uid_t *uid, gid_t *gid, grp = getgrnam (g); if (grp == NULL) { - if (!is_number (g)) - error_msg = E_invalid_group; - else - { - unsigned long int tmp_long; - if (xstrtoul (g, NULL, 0, &tmp_long, NULL) != LONGINT_OK - || tmp_long > MAXGID) - return _(E_invalid_group); - *gid = tmp_long; - } + unsigned long int tmp_long; + if (! (xstrtoul (g, NULL, 10, &tmp_long, "") == LONGINT_OK + && tmp_long <= MAXGID)) + return _(E_invalid_group); + *gid = tmp_long; } else *gid = grp->gr_gid; @@ -336,10 +329,10 @@ main (int argc, char **argv) tmp = strdup (argv[i]); e = parse_user_spec (tmp, &uid, &gid, &username, &groupname); free (tmp); - printf ("%s: %u %u %s %s %s\n", + printf ("%s: %lu %lu %s %s %s\n", argv[i], - (unsigned int) uid, - (unsigned int) gid, + (unsigned long int) uid, + (unsigned long int) gid, NULL_CHECK (username), NULL_CHECK (groupname), NULL_CHECK (e)); diff --git a/lib/utime.c b/lib/utime.c index 7b87a969d..05aa3467c 100644 --- a/lib/utime.c +++ b/lib/utime.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc. +/* Copyright (C) 1998, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -34,9 +34,6 @@ #include #include -#ifndef errno -extern int errno; -#endif #include "full-write.h" #include "safe-read.h" diff --git a/lib/version-etc.c b/lib/version-etc.c index 7523b087b..fd71eff93 100644 --- a/lib/version-etc.c +++ b/lib/version-etc.c @@ -46,7 +46,7 @@ version_etc_va (FILE *stream, const char *command_name, const char *package, const char *version, va_list authors) { - unsigned int n_authors; + size_t n_authors; /* Count the number of authors. */ { diff --git a/lib/xgethostname.c b/lib/xgethostname.c index 1f4d728a0..87e0ad926 100644 --- a/lib/xgethostname.c +++ b/lib/xgethostname.c @@ -1,5 +1,7 @@ /* xgethostname.c -- return current hostname with unlimited length - Copyright (C) 1992, 1996, 2000, 2001, 2003 Free Software Foundation, Inc. + + Copyright (C) 1992, 1996, 2000, 2001, 2003, 2004 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,60 +27,56 @@ #include "xgethostname.h" #include -#include - #include -#ifndef errno -extern int errno; + +#if HAVE_UNISTD_H +# include #endif #include "error.h" -#include "exit.h" #include "xalloc.h" #ifndef ENAMETOOLONG -# define ENAMETOOLONG 9999 +# define ENAMETOOLONG 0 #endif -int gethostname (); - #ifndef INITIAL_HOSTNAME_LENGTH # define INITIAL_HOSTNAME_LENGTH 34 #endif /* Return the current hostname in malloc'd storage. If malloc fails, exit. - Upon any other failure, return NULL. */ + Upon any other failure, return NULL and set errno. */ char * xgethostname (void) { - char *hostname; - size_t size; - - size = INITIAL_HOSTNAME_LENGTH; - /* Use size + 1 here rather than size to work around the bug - in SunOS 5.5's gethostname whereby it NUL-terminates HOSTNAME - even when the name is longer than the supplied buffer. */ - hostname = xmalloc (size + 1); + char *hostname = NULL; + size_t size = INITIAL_HOSTNAME_LENGTH; + while (1) { - int k = size - 1; - int err; - + /* Use SIZE_1 here rather than SIZE to work around the bug in + SunOS 5.5's gethostname whereby it NUL-terminates HOSTNAME + even when the name is as long as the supplied buffer. */ + size_t size_1; + + hostname = x2realloc (hostname, &size); + size_1 = size - 1; + hostname[size_1 - 1] = '\0'; errno = 0; - hostname[k] = '\0'; - err = gethostname (hostname, size); - if (err >= 0 && hostname[k] == '\0') - break; - else if (err < 0 && errno != ENAMETOOLONG && errno != 0) + + if (gethostname (hostname, size_1) == 0) + { + if (! hostname[size_1 - 1]) + break; + } + else if (errno != 0 && errno != ENAMETOOLONG && errno != EINVAL) { int saved_errno = errno; free (hostname); errno = saved_errno; return NULL; } - size *= 2; - hostname = xrealloc (hostname, size + 1); } return hostname; diff --git a/lib/xmemcoll.c b/lib/xmemcoll.c index 0e30aef15..433d67f9c 100644 --- a/lib/xmemcoll.c +++ b/lib/xmemcoll.c @@ -1,5 +1,5 @@ /* Locale-specific memory comparison. - Copyright (C) 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,10 +22,6 @@ #endif #include -#ifndef errno -extern int errno; -#endif - #include #include "gettext.h" diff --git a/lib/xreadlink.c b/lib/xreadlink.c index 41f5242ea..2e66c07f2 100644 --- a/lib/xreadlink.c +++ b/lib/xreadlink.c @@ -27,10 +27,6 @@ #include #include -#ifndef errno -extern int errno; -#endif - #include #include #include diff --git a/lib/xstrtod.c b/lib/xstrtod.c index 1a0b4d460..4b5bcc9c5 100644 --- a/lib/xstrtod.c +++ b/lib/xstrtod.c @@ -1,5 +1,6 @@ /* error-checking interface to strtod-like functions - Copyright (C) 1996, 1999, 2000, 2003 Free Software Foundation, Inc. + + Copyright (C) 1996, 1999, 2000, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,36 +35,35 @@ /* An interface to strtod that encapsulates all the error checking one should usually perform. Like strtod, but upon successful - conversion put the result in *RESULT and return zero. Return - non-zero and don't modify *RESULT upon any failure. CONVERT + conversion put the result in *RESULT and return true. Return + false and don't modify *RESULT upon any failure. CONVERT specifies the conversion function, e.g., strtod itself. */ -int +bool xstrtod (char const *str, char const **ptr, double *result, double (*convert) (char const *, char **)) { double val; char *terminator; - int fail; + bool ok = true; - fail = 0; errno = 0; val = convert (str, &terminator); /* Having a non-zero terminator is an error only when PTR is NULL. */ if (terminator == str || (ptr == NULL && *terminator != '\0')) - fail = 1; + ok = false; else { /* Allow underflow (in which case strtod returns zero), but flag overflow as an error. */ if (val != 0.0 && errno == ERANGE) - fail = 1; + ok = false; } if (ptr != NULL) *ptr = terminator; *result = val; - return fail; + return ok; } diff --git a/lib/xstrtod.h b/lib/xstrtod.h index 0a63c1501..f37acc917 100644 --- a/lib/xstrtod.h +++ b/lib/xstrtod.h @@ -1,6 +1,6 @@ /* Error-checking interface to strtod-like functions. - Copyright (C) 1996, 1998, 2003 Free Software Foundation, Inc. + Copyright (C) 1996, 1998, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,7 +21,9 @@ #ifndef XSTRTOD_H # define XSTRTOD_H 1 -int xstrtod (const char *str, const char **ptr, double *result, - double (*convert) (char const *, char **)); +# include + +bool xstrtod (const char *str, const char **ptr, double *result, + double (*convert) (char const *, char **)); #endif /* not XSTRTOD_H */ diff --git a/lib/xstrtoimax.c b/lib/xstrtoimax.c index 2ba136772..2cab528a0 100644 --- a/lib/xstrtoimax.c +++ b/lib/xstrtoimax.c @@ -1,5 +1,5 @@ /* xstrtoimax.c -- A more useful interface to strtoimax. - Copyright (C) 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,11 +21,7 @@ # include #endif -#if HAVE_INTTYPES_H -# include -#elif HAVE_STDINT_H -# include -#endif +#include "xstrtol.h" #define __strtol strtoimax #define __strtol_t intmax_t diff --git a/lib/xstrtol.c b/lib/xstrtol.c index d0aa0a968..906e4a1cc 100644 --- a/lib/xstrtol.c +++ b/lib/xstrtol.c @@ -1,6 +1,6 @@ /* A more useful interface to strtol. - Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2003 Free + Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -37,15 +37,10 @@ #include #include -#include -#include - #include -#ifndef errno -extern int errno; -#endif - #include +#include +#include /* The extra casts work around common compiler bugs. */ #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) @@ -121,9 +116,10 @@ __xstrtol (const char *s, char **ptr, int strtol_base, if (! TYPE_SIGNED (__strtol_t)) { const char *q = s; - while (ISSPACE ((unsigned char) *q)) - ++q; - if (*q == '-') + unsigned char ch = *q; + while (ISSPACE (ch)) + ch = *++q; + if (ch == '-') return LONGINT_INVALID; } diff --git a/lib/xstrtol.h b/lib/xstrtol.h index 5765c88e2..0d6b98482 100644 --- a/lib/xstrtol.h +++ b/lib/xstrtol.h @@ -22,13 +22,11 @@ # include "exitfail.h" -/* Get uintmax_t. */ # if HAVE_INTTYPES_H # include -# else -# if HAVE_STDINT_H -# include -# endif +# endif +# if HAVE_STDINT_H +# include # endif # ifndef _STRTOL_ERROR diff --git a/lib/xstrtoumax.c b/lib/xstrtoumax.c index a8858bf6d..8518ef077 100644 --- a/lib/xstrtoumax.c +++ b/lib/xstrtoumax.c @@ -1,5 +1,5 @@ /* xstrtoumax.c -- A more useful interface to strtoumax. - Copyright (C) 1999, 2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,11 +21,7 @@ # include #endif -#if HAVE_INTTYPES_H -# include -#elif HAVE_STDINT_H -# include -#endif +#include "xstrtol.h" #define __strtol strtoumax #define __strtol_t uintmax_t diff --git a/m4/ChangeLog b/m4/ChangeLog index 098f169d4..62527eb0c 100644 --- a/m4/ChangeLog +++ b/m4/ChangeLog @@ -1,3 +1,12 @@ +2004-08-06 Paul Eggert + + More merge from coreutils. + + * utimens.m4, utimecmp.m4: New files. + * backupfile.m4, euidacces.m4, acl.m4, afs.m4, calloc.m4, dirfd.m4, + fsusage.m4, jm-macros.m4, ls-mntd-fs.m4, md5.m4, mountlist.m4, + prereq.m4, sha.m4: Import changes from coreutils. + 2004-08-02 Simon Josefsson * getsubopt.m4: New file. diff --git a/m4/acl.m4 b/m4/acl.m4 index 9c7d44649..563f18cea 100644 --- a/m4/acl.m4 +++ b/m4/acl.m4 @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Written by Paul Eggert. diff --git a/m4/afs.m4 b/m4/afs.m4 index fa568ba93..05e4a5b29 100644 --- a/m4/afs.m4 +++ b/m4/afs.m4 @@ -1,13 +1,12 @@ -#serial 6 +#serial 7 AC_DEFUN([gl_AFS], [ - AC_MSG_CHECKING(for AFS) - if test -d /afs; then + AC_ARG_WITH(afs, + AC_HELP_STRING([--with-afs], + [support for the Andrew File System [[default=no]]]), + test "$withval" = no || with_afs=yes, with_afs=no) + if test "$with_afs" = yes; then AC_DEFINE(AFS, 1, [Define if you have the Andrew File System.]) - ac_result=yes - else - ac_result=no fi - AC_MSG_RESULT($ac_result) ]) diff --git a/m4/calloc.m4 b/m4/calloc.m4 index fee15ddbc..5d03ed271 100644 --- a/m4/calloc.m4 +++ b/m4/calloc.m4 @@ -1,8 +1,4 @@ -#serial 1 - -# FIXME: remove this whole file once we can depend -# on having the definition from autoconf. -undefine([AC_FUNC_CALLOC]) +#serial 2 # Determine whether calloc (N, S) returns non-NULL when N*S is zero. # If so, define HAVE_CALLOC. Otherwise, define calloc to rpl_calloc diff --git a/m4/dirfd.m4 b/m4/dirfd.m4 index 8e4207578..f84d63fac 100644 --- a/m4/dirfd.m4 +++ b/m4/dirfd.m4 @@ -1,4 +1,4 @@ -#serial 7 +#serial 8 dnl Find out how to get the file descriptor associated with an open DIR*. dnl From Jim Meyering diff --git a/m4/fsusage.m4 b/m4/fsusage.m4 index b0a283b11..a6a87c532 100644 --- a/m4/fsusage.m4 +++ b/m4/fsusage.m4 @@ -1,11 +1,34 @@ -#serial 12 +# fsusage.m4 serial 13 +# Obtaining file system usage information. -# From fileutils/configure.in +# Copyright (C) 1997, 1998, 2000, 2001, 2003, 2004 Free Software +# Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Written by Jim Meyering. AC_DEFUN([gl_FSUSAGE], [ AC_CHECK_HEADERS_ONCE(sys/param.h) - AC_CHECK_HEADERS(sys/mount.h sys/vfs.h sys/fs_types.h) + AC_CHECK_HEADERS_ONCE(sys/vfs.h sys/fs_types.h) + AC_CHECK_HEADERS(sys/mount.h, [], [], + [AC_INCLUDES_DEFAULT + [#if HAVE_SYS_PARAM_H + #include + #endif]]) gl_FILE_SYSTEM_USAGE([gl_cv_fs_space=yes], [gl_cv_fs_space=no]) if test $gl_cv_fs_space = yes; then AC_LIBOBJ(fsusage) @@ -13,7 +36,7 @@ AC_DEFUN([gl_FSUSAGE], fi ]) -# Try to determine how a program can obtain filesystem usage information. +# Try to determine how a program can obtain file system usage information. # If successful, define the appropriate symbol (see fsusage.c) and # execute ACTION-IF-FOUND. Otherwise, execute ACTION-IF-NOT-FOUND. # @@ -22,7 +45,7 @@ AC_DEFUN([gl_FSUSAGE], AC_DEFUN([gl_FILE_SYSTEM_USAGE], [ -echo "checking how to get filesystem space usage..." +echo "checking how to get file system space usage..." ac_fsusage_space=no # Perform only the link test since it seems there are no variants of the @@ -199,7 +222,7 @@ if test $ac_fsusage_space = no; then AC_TRY_CPP([#include ], AC_DEFINE(STAT_READ_FILSYS, 1, - [Define if there is no specific function for reading filesystems usage + [Define if there is no specific function for reading file systems usage information and you have the header file. (SVR2)]) ac_fsusage_space=yes) fi diff --git a/m4/jm-macros.m4 b/m4/jm-macros.m4 index 94c711239..f0dab6bc5 100644 --- a/m4/jm-macros.m4 +++ b/m4/jm-macros.m4 @@ -1,6 +1,25 @@ -#serial 72 -*- autoconf -*- +#serial 75 -*- autoconf -*- -dnl Misc type-related macros for fileutils, sh-utils, textutils. +dnl Misc type-related macros for coreutils. + +# Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004 Free Software +# Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Written by Jim Meyering. AC_DEFUN([gl_MACROS], [ @@ -73,15 +92,16 @@ AC_DEFUN([gl_MACROS], # used by sleep and shred AC_REQUIRE([gl_CLOCK_TIME]) - AC_CHECK_FUNCS(gettimeofday) + AC_CHECK_FUNCS_ONCE(gettimeofday) AC_FUNC_GETTIMEOFDAY_CLOBBER + # used by shred + AC_CHECK_FUNCS_ONCE(directio) AC_REQUIRE([AC_FUNC_CLOSEDIR_VOID]) - AC_CHECK_FUNCS( \ + AC_CHECK_FUNCS_ONCE( \ endgrent \ endpwent \ - fdatasync \ ftruncate \ gethrtime \ hasmntopt \ @@ -100,17 +120,26 @@ AC_DEFUN([gl_MACROS], strrchr \ sysctl \ sysinfo \ + tcgetpgrp \ wcrtomb \ tzset \ ) - # for test.c - AC_CHECK_FUNCS(setreuid setregid) - AC_FUNC_STRTOD + + AC_REQUIRE([cu_PREREQ_STAT_PROG]) AC_REQUIRE([GL_FUNC_GETCWD_PATH_MAX]) AC_REQUIRE([GL_FUNC_READDIR]) + # for dd.c and shred.c + fetish_saved_libs=$LIBS + AC_SEARCH_LIBS([fdatasync], [rt posix4], + [test "$ac_cv_search_fdatasync" = "none required" || + LIB_FDATASYNC=$ac_cv_search_fdatasync]) + AC_SUBST([LIB_FDATASYNC]) + AC_CHECK_FUNCS(fdatasync) + LIBS=$fetish_saved_libs + # See if linking `seq' requires -lm. # It does on nearly every system. The single exception (so far) is # BeOS which has all the math functions in the normal runtime library @@ -146,7 +175,6 @@ AC_DEFUN([gl_MACROS], # If any of these functions don't exist (e.g. DJGPP 2.03), # use the corresponding stub. AC_CHECK_FUNC([fchdir], , [AC_LIBOBJ(fchdir-stub)]) - AC_CHECK_FUNC([fchown], , [AC_LIBOBJ(fchown-stub)]) AC_REQUIRE([gl_FUNC_FREE]) ]) @@ -156,7 +184,7 @@ AC_DEFUN([gl_MACROS], # See the definition of ac_includes_default in `configure'. AC_DEFUN([gl_CHECK_ALL_HEADERS], [ - AC_CHECK_HEADERS( \ + AC_CHECK_HEADERS_ONCE( \ errno.h \ fcntl.h \ float.h \ @@ -177,13 +205,11 @@ AC_DEFUN([gl_CHECK_ALL_HEADERS], sys/fstyp.h \ sys/ioctl.h \ sys/mntent.h \ - sys/mount.h \ sys/param.h \ sys/resource.h \ sys/socket.h \ sys/statfs.h \ sys/statvfs.h \ - sys/sysctl.h \ sys/systeminfo.h \ sys/time.h \ sys/timeb.h \ @@ -193,8 +219,12 @@ AC_DEFUN([gl_CHECK_ALL_HEADERS], termios.h \ unistd.h \ utime.h \ - values.h \ ) + AC_CHECK_HEADERS(sys/mount.h sys/sysctl.h, [], [], + [AC_INCLUDES_DEFAULT + [#if HAVE_SYS_PARAM_H + #include + #endif]]) ]) # This macro must be invoked before any tests that run the compiler. @@ -240,7 +270,6 @@ AC_DEFUN([gl_CHECK_ALL_TYPES], AC_REQUIRE([AC_TYPE_SIZE_T]) AC_REQUIRE([AC_TYPE_UID_T]) AC_CHECK_TYPE(ino_t, unsigned long int) - AC_CHECK_TYPE(uintptr_t, size_t) gt_TYPE_SSIZE_T @@ -249,7 +278,9 @@ AC_DEFUN([gl_CHECK_ALL_TYPES], AC_CHECK_TYPE(major_t, unsigned int) AC_CHECK_TYPE(minor_t, unsigned int) + AC_REQUIRE([gl_AC_TYPE_UINT32_T]) AC_REQUIRE([gl_AC_TYPE_UINTMAX_T]) + AC_REQUIRE([gl_AC_TYPE_UINTPTR_T]) AC_REQUIRE([gl_AC_TYPE_UNSIGNED_LONG_LONG]) AC_REQUIRE([AC_HEADER_MAJOR]) diff --git a/m4/ls-mntd-fs.m4 b/m4/ls-mntd-fs.m4 index a5fe795e7..4c1c701bf 100644 --- a/m4/ls-mntd-fs.m4 +++ b/m4/ls-mntd-fs.m4 @@ -1,13 +1,31 @@ -#serial 15 +#serial 17 +# How to list mounted file systems. + +# Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software +# Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. dnl From Jim Meyering. dnl dnl This is not pretty. I've just taken the autoconf code and wrapped -dnl it in an AC_DEFUN. +dnl it in an AC_DEFUN and made some other fixes. dnl -# gl_LIST_MOUNTED_FILESYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -AC_DEFUN([gl_LIST_MOUNTED_FILESYSTEMS], +# gl_LIST_MOUNTED_FILE_SYSTEMS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +AC_DEFUN([gl_LIST_MOUNTED_FILE_SYSTEMS], [ AC_CHECK_FUNCS(listmntent getmntinfo) AC_CHECK_HEADERS_ONCE(sys/param.h) @@ -16,7 +34,13 @@ AC_CHECK_HEADERS_ONCE(sys/param.h) # NGROUPS (as the array dimension for a struct member) without a definition. AC_CHECK_HEADERS(sys/ucred.h, [], [], [#include ]) -AC_CHECK_HEADERS(mntent.h sys/mount.h sys/fs_types.h) +AC_CHECK_HEADERS(sys/mount.h, [], [], + [AC_INCLUDES_DEFAULT + [#if HAVE_SYS_PARAM_H + #include + #endif]]) + +AC_CHECK_HEADERS(mntent.h sys/fs_types.h) getfsstat_includes="\ $ac_includes_default #if HAVE_SYS_PARAM_H @@ -35,7 +59,7 @@ $ac_includes_default " AC_CHECK_MEMBERS([struct fsstat.f_fstypename],,,[$getfsstat_includes]) -# Determine how to get the list of mounted filesystems. +# Determine how to get the list of mounted file systems. ac_list_mounted_fs= # If the getmntent function is available but not in the standard library, @@ -70,7 +94,7 @@ yes ac_list_mounted_fs=found AC_DEFINE(MOUNTED_LISTMNTENT, 1, [Define if there is a function named listmntent that can be used to - list all mounted filesystems. (UNICOS)]) + list all mounted file systems. (UNICOS)]) fi fi @@ -86,7 +110,7 @@ if test -z "$ac_list_mounted_fs"; then ac_list_mounted_fs=found AC_DEFINE(MOUNTED_VMOUNT, 1, [Define if there is a function named mntctl that can be used to read - the list of mounted filesystems, and there is a system header file + the list of mounted file systems, and there is a system header file that declares `struct vmount.' (AIX)]) fi fi @@ -125,7 +149,7 @@ if test $ac_cv_func_getmntent = yes; then ac_list_mounted_fs=found AC_DEFINE(MOUNTED_GETMNTENT1, 1, [Define if there is a function named getmntent for reading the list - of mounted filesystems, and that function takes a single argument. + of mounted file systems, and that function takes a single argument. (4.3BSD, SunOS, HP-UX, Dynix, Irix)]) fi fi @@ -142,7 +166,7 @@ if test $ac_cv_func_getmntent = yes; then ac_list_mounted_fs=found AC_DEFINE(MOUNTED_GETMNTENT2, 1, [Define if there is a function named getmntent for reading the list of - mounted filesystems, and that function takes two arguments. (SVR4)]) + mounted file systems, and that function takes two arguments. (SVR4)]) fi fi @@ -173,7 +197,7 @@ if test -z "$ac_list_mounted_fs"; then ac_list_mounted_fs=found AC_DEFINE(MOUNTED_GETFSSTAT, 1, [Define if there is a function named getfsstat for reading the - list of mounted filesystems. (DEC Alpha running OSF/1)]) + list of mounted file systems. (DEC Alpha running OSF/1)]) fi fi @@ -192,7 +216,7 @@ if test -z "$ac_list_mounted_fs"; then ac_list_mounted_fs=found AC_DEFINE(MOUNTED_FREAD_FSTYP, 1, [Define if (like SVR2) there is no specific function for reading the - list of mounted filesystems, and your system has these header files: + list of mounted file systems, and your system has these header files: and . (SVR3)]) fi fi @@ -211,7 +235,7 @@ if test -z "$ac_list_mounted_fs"; then ac_list_mounted_fs=found AC_DEFINE(MOUNTED_GETMNTINFO, 1, [Define if there is a function named getmntinfo for reading the - list of mounted filesystems. (4.4BSD, Darwin)]) + list of mounted file systems. (4.4BSD, Darwin)]) fi fi @@ -229,7 +253,7 @@ if test -z "$ac_list_mounted_fs"; then ac_list_mounted_fs=found AC_DEFINE(MOUNTED_GETMNT, 1, [Define if there is a function named getmnt for reading the list of - mounted filesystems. (Ultrix)]) + mounted file systems. (Ultrix)]) fi fi @@ -250,7 +274,7 @@ if test -z "$ac_list_mounted_fs"; then ac_list_mounted_fs=found AC_DEFINE(MOUNTED_FS_STAT_DEV, 1, [Define if there are functions named next_dev and fs_stat_dev for - reading the list of mounted filesystems. (BeOS)]) + reading the list of mounted file systems. (BeOS)]) fi fi @@ -266,13 +290,13 @@ if test -z "$ac_list_mounted_fs"; then ac_list_mounted_fs=found AC_DEFINE(MOUNTED_FREAD, 1, [Define if there is no specific function for reading the list of - mounted filesystems. fread will be used to read /etc/mnttab. + mounted file systems. fread will be used to read /etc/mnttab. (SVR2) ]) fi fi if test -z "$ac_list_mounted_fs"; then - AC_MSG_ERROR([could not determine how to read list of mounted filesystems]) + AC_MSG_ERROR([could not determine how to read list of mounted file systems]) # FIXME -- no need to abort building the whole package # Can't build mountlist.c or anything that needs its functions fi diff --git a/m4/md5.m4 b/m4/md5.m4 index 743099022..ec45b5a21 100644 --- a/m4/md5.m4 +++ b/m4/md5.m4 @@ -1,5 +1,5 @@ -# md5.m4 serial 3 -dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. +# md5.m4 serial 5 +dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program @@ -9,7 +9,9 @@ dnl the same distribution terms as the rest of that program. AC_DEFUN([gl_MD5], [ dnl Prerequisites of lib/md5.h. - AC_REQUIRE([AC_C_INLINE]) + AC_REQUIRE([gl_AC_TYPE_UINT32_T]) - dnl No prerequisites of lib/md5.c. + dnl Prerequisites of lib/md5.c. + AC_REQUIRE([AC_C_BIGENDIAN]) + : ]) diff --git a/m4/mountlist.m4 b/m4/mountlist.m4 index 6eb11077b..8e79285c6 100644 --- a/m4/mountlist.m4 +++ b/m4/mountlist.m4 @@ -1,4 +1,4 @@ -# mountlist.m4 serial 3 +# mountlist.m4 serial 4 dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General @@ -8,18 +8,18 @@ dnl the same distribution terms as the rest of that program. AC_DEFUN([gl_MOUNTLIST], [ - gl_LIST_MOUNTED_FILESYSTEMS([gl_cv_list_mounted_fs=yes], - [gl_cv_list_mounted_fs=no]) + gl_LIST_MOUNTED_FILE_SYSTEMS([gl_cv_list_mounted_fs=yes], + [gl_cv_list_mounted_fs=no]) if test $gl_cv_list_mounted_fs = yes; then AC_LIBOBJ(mountlist) gl_PREREQ_MOUNTLIST_EXTRA fi ]) -# Prerequisites of lib/mountlist.c not done by gl_LIST_MOUNTED_FILESYSTEMS. +# Prerequisites of lib/mountlist.c not done by gl_LIST_MOUNTED_FILE_SYSTEMS. AC_DEFUN([gl_PREREQ_MOUNTLIST_EXTRA], [ - dnl Note gl_LIST_MOUNTED_FILESYSTEMS checks for mntent.h, not sys/mntent.h. + dnl Note gl_LIST_MOUNTED_FILE_SYSTEMS checks for mntent.h, not sys/mntent.h. AC_CHECK_HEADERS_ONCE(fcntl.h unistd.h) AC_CHECK_HEADERS(sys/mntent.h) gl_FSTYPENAME diff --git a/m4/prereq.m4 b/m4/prereq.m4 index e2588a29e..79b7586f7 100644 --- a/m4/prereq.m4 +++ b/m4/prereq.m4 @@ -1,4 +1,4 @@ -#serial 40 +#serial 44 dnl We use gl_ for non Autoconf macros. m4_pattern_forbid([^gl_[ABCDEFGHIJKLMNOPQRSTUVXYZ]])dnl @@ -17,6 +17,7 @@ AC_DEFUN([gl_PREREQ], AC_REQUIRE([gl_FUNC_MKSTEMP]) AC_REQUIRE([gl_ALLOCSA]) AC_REQUIRE([gl_BACKUPFILE]) + AC_REQUIRE([gl_C_STRTOLD]) AC_REQUIRE([gl_CANON_HOST]) AC_REQUIRE([gl_CLOEXEC]) AC_REQUIRE([gl_CLOSEOUT]) @@ -24,6 +25,7 @@ AC_DEFUN([gl_PREREQ], AC_REQUIRE([gl_ERROR]) AC_REQUIRE([gl_EXCLUDE]) AC_REQUIRE([gl_EXITFAIL]) + AC_REQUIRE([gl_FCNTL_SAFER]) AC_REQUIRE([gl_FILEBLOCKS]) AC_REQUIRE([gl_FILEMODE]) AC_REQUIRE([gl_FILE_TYPE]) @@ -31,7 +33,6 @@ AC_DEFUN([gl_PREREQ], AC_REQUIRE([gl_FUNC_ALLOCA]) AC_REQUIRE([gl_FUNC_ATEXIT]) AC_REQUIRE([gl_FUNC_DUP2]) - AC_REQUIRE([gl_FUNC_EUIDACCESS]) AC_REQUIRE([gl_FUNC_FNMATCH_GNU]) AC_REQUIRE([gl_FUNC_GETHOSTNAME]) AC_REQUIRE([AC_FUNC_GETLOADAVG]) @@ -43,6 +44,7 @@ AC_DEFUN([gl_PREREQ], AC_REQUIRE([gl_FUNC_MEMRCHR]) AC_REQUIRE([gl_FUNC_MEMSET]) AC_REQUIRE([gl_FUNC_MKTIME]) + AC_REQUIRE([gl_FUNC_NONREENTRANT_EUIDACCESS]) AC_REQUIRE([gl_FUNC_READLINK]) AC_REQUIRE([gl_FUNC_RMDIR]) AC_REQUIRE([gl_FUNC_RPMATCH]) @@ -68,6 +70,7 @@ AC_DEFUN([gl_PREREQ], AC_REQUIRE([gl_GETNDELIM2]) AC_REQUIRE([gl_GETOPT]) AC_REQUIRE([gl_GETPAGESIZE]) + AC_REQUIRE([gl_GETTIME]) AC_REQUIRE([gl_GETUGROUPS]) AC_REQUIRE([gl_HARD_LOCALE]) AC_REQUIRE([gl_HASH]) @@ -113,6 +116,7 @@ AC_DEFUN([gl_PREREQ], AC_REQUIRE([gl_XSTRTOD]) AC_REQUIRE([gl_XSTRTOL]) AC_REQUIRE([gl_YESNO]) + AC_REQUIRE([AC_FUNC_CALLOC]) AC_REQUIRE([gl_FUNC_GLIBC_UNLOCKED_IO]) AC_REQUIRE([gl_FUNC_GNU_STRFTIME]) AC_REQUIRE([gl_FUNC_LSTAT]) diff --git a/m4/sha.m4 b/m4/sha.m4 index 6eadd2df6..34ef6ac63 100644 --- a/m4/sha.m4 +++ b/m4/sha.m4 @@ -1,5 +1,5 @@ -# sha.m4 serial 2 -dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc. +# sha.m4 serial 3 +dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. dnl This file is free software, distributed under the terms of the GNU dnl General Public License. As a special exception to the GNU General dnl Public License, this file may be distributed as part of a program @@ -8,6 +8,7 @@ dnl the same distribution terms as the rest of that program. AC_DEFUN([gl_SHA], [ - dnl Prerequisites of lib/sha.c. + dnl Prerequisites of lib/sha1.c. + AC_REQUIRE([AC_C_BIGENDIAN]) : ]) diff --git a/modules/canonicalize b/modules/canonicalize index a8d14c171..d7eb429ec 100644 --- a/modules/canonicalize +++ b/modules/canonicalize @@ -17,7 +17,7 @@ configure.ac: AC_FUNC_CANONICALIZE_FILE_NAME Makefile.am: -lib_SOURCES += canonicalize.h canonicalize.c +lib_SOURCES += canonicalize.h canonicalize.c stat-macros.h Include: "canonicalize.h" diff --git a/modules/euidaccess b/modules/euidaccess index 527e4d00e..09a0058af 100644 --- a/modules/euidaccess +++ b/modules/euidaccess @@ -4,6 +4,7 @@ euidaccess() function: check effective user's permissions for a file. Files: lib/euidaccess.h lib/euidaccess.c +lib/stat-macros.h m4/euidaccess.m4 Depends-on: @@ -13,7 +14,7 @@ configure.ac: gl_FUNC_EUIDACCESS Makefile.am: -lib_SOURCES += euidaccess.h +lib_SOURCES += euidaccess.h stat-macros.h Include: "euidaccess.h" diff --git a/modules/filemode b/modules/filemode index 31ae03917..a220b0b37 100644 --- a/modules/filemode +++ b/modules/filemode @@ -5,6 +5,7 @@ file. Files: lib/filemode.h lib/filemode.c +lib/stat-macros.h m4/filemode.m4 Depends-on: @@ -13,7 +14,7 @@ configure.ac: gl_FILEMODE Makefile.am: -lib_SOURCES += filemode.h filemode.c +lib_SOURCES += filemode.h filemode.c stat-macros.h Include: "filemode.h" diff --git a/modules/lchown b/modules/lchown index 438bc8c53..a21ec041a 100644 --- a/modules/lchown +++ b/modules/lchown @@ -4,6 +4,7 @@ lchown() function: change ownership of a file. Files: lib/lchown.h lib/lchown.c +lib/stat-macros.h m4/lchown.m4 Depends-on: @@ -13,7 +14,7 @@ configure.ac: gl_FUNC_LCHOWN Makefile.am: -lib_SOURCES += lchown.h +lib_SOURCES += lchown.h stat-macros.h Include: "lchown.h" diff --git a/modules/makepath b/modules/makepath index 83a9e14ef..944c6cb48 100644 --- a/modules/makepath +++ b/modules/makepath @@ -4,6 +4,7 @@ Ensure that a directory path exists. Files: lib/makepath.h lib/makepath.c +lib/stat-macros.h m4/afs.m4 m4/makepath.m4 @@ -20,7 +21,7 @@ configure.ac: gl_MAKEPATH Makefile.am: -lib_SOURCES += makepath.h makepath.c +lib_SOURCES += makepath.h makepath.c stat-macros.h Include: "makepath.h" diff --git a/modules/rmdir b/modules/rmdir index 01547e4d3..8a3c6baa5 100644 --- a/modules/rmdir +++ b/modules/rmdir @@ -3,6 +3,7 @@ rmdir() function: delete a directory. Files: lib/rmdir.c +lib/stat-macros.h m4/rmdir.m4 Depends-on: @@ -11,6 +12,7 @@ configure.ac: gl_FUNC_RMDIR Makefile.am: +lib_SOURCES += stat-macros.h Include: diff --git a/modules/stat b/modules/stat index c377eb157..002e9e2cc 100644 --- a/modules/stat +++ b/modules/stat @@ -3,6 +3,7 @@ stat() function: return information about a file, following symbolic links. Files: lib/stat.c +lib/stat-macros.h m4/stat.m4 Depends-on: @@ -12,6 +13,7 @@ configure.ac: gl_FUNC_STAT Makefile.am: +lib_SOURCES += stat-macros.h Include: -- 2.11.0