CVS update: /ccvs/lib/
[email protected] 15 May 2005 16:44:07 -0000
| Newsgroups | gmane.comp.version-control.cvs.cvs |
|---|---|
| Message-ID | <[email protected]> |
User: dprice Date: 05/05/15 09:44:07 Modified: /ccvs/lib/ ChangeLog, glob.c, glob_.h Log: * glob_.h, glob.c: More misc cleanup for compatibility with GNULIB & glibc, mostly suggested by Paul Eggert <[email protected]>. Remove casts to and from void * - they are not needed in C89. File Changes: Directory: /ccvs/lib/ ===================== File [changed]: ChangeLog Url: https://ccvs.cvshome.org/source/browse/ccvs/lib/ChangeLog?r1=1.424&r2=1.425 Delta lines: +6 -0 ------------------- --- ChangeLog 13 May 2005 21:26:36 -0000 1.424 +++ ChangeLog 15 May 2005 16:44:04 -0000 1.425 @@ -1,3 +1,9 @@ +2005-05-15 Derek Price <[email protected]> + + * glob_.h, glob.c: More misc cleanup for compatibility with GNULIB & + glibc, mostly suggested by Paul Eggert <[email protected]>. Remove + casts to and from void * - they are not needed in C89. + 2005-05-13 Derek Price <[email protected]> * glob_.h: Enable GNU features by default. Remove copy/pasted getopt File [changed]: glob.c Url: https://ccvs.cvshome.org/source/browse/ccvs/lib/glob.c?r1=1.4&r2=1.5 Delta lines: +45 -64 --------------------- --- glob.c 13 May 2005 21:26:36 -0000 1.4 +++ glob.c 15 May 2005 16:44:04 -0000 1.5 @@ -20,11 +20,6 @@ # include <config.h> #endif -/* Enable GNU extensions in glob.h. */ -#if defined _LIBC && !defined _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif - #include <glob.h> #include <errno.h> @@ -38,15 +33,6 @@ #include <stdio.h> /* Needed on stupid SunOS for assert. */ - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - #if !defined _LIBC || !defined GLOB_ONLY_P #if defined HAVE_UNISTD_H || defined _LIBC # include <unistd.h> @@ -93,8 +79,7 @@ /* When used in the GNU libc the symbol _DIRENT_HAVE_D_TYPE is available if the `d_type' member for `struct dirent' is available. - HAVE_STRUCT_DIRENT_D_TYPE is defined by GNULIB's glob.m4 when the same - member is found. */ + HAVE_STRUCT_DIRENT_D_TYPE plays the same role in GNULIB. */ #if defined _DIRENT_HAVE_D_TYPE || defined HAVE_STRUCT_DIRENT_D_TYPE # define HAVE_D_TYPE 1 @@ -116,11 +101,11 @@ #endif /* HAVE_D_TYPE */ #if _LIBC -# define HAVE_DIRENT64 1 +# define HAVE_STRUCT_DIRENT64 1 #endif /* If the system has the `struct dirent64' type we use it internally. */ -#if defined HAVE_DIRENT64 && !defined COMPILE_GLOB64 +#if defined HAVE_STRUCT_DIRENT64 && !defined COMPILE_GLOB64 # if defined HAVE_DIRENT_H || defined __GNU_LIBRARY__ # define CONVERT_D_NAMLEN(d64, d32) # else @@ -322,7 +307,7 @@ #ifdef __GNUC__ char onealt[strlen (pattern) - 1]; #else - char *onealt = (char *) malloc (strlen (pattern) - 1); + char *onealt = malloc (strlen (pattern) - 1); if (onealt == NULL) { if (!(flags & GLOB_APPEND)) @@ -482,7 +467,7 @@ char *drive_spec; ++dirlen; - drive_spec = (char *) __alloca (dirlen + 1); + drive_spec = __alloca (dirlen + 1); *((char *) mempcpy (drive_spec, pattern, dirlen)) = '\0'; /* For now, disallow wildcards in the drive spec, to prevent infinite recursion in glob. */ @@ -493,7 +478,7 @@ from "d:/", since "d:" and "d:/" are not the same.*/ } #endif - newp = (char *) __alloca (dirlen + 1); + newp = __alloca (dirlen + 1); *((char *) mempcpy (newp, pattern, dirlen)) = '\0'; dirname = newp; ++filename; @@ -523,8 +508,7 @@ else { size_t i; - pglob->gl_pathv = (char **) malloc ((pglob->gl_offs + 1) - * sizeof (char *)); + pglob->gl_pathv = malloc ((pglob->gl_offs + 1) * sizeof (char *)); if (pglob->gl_pathv == NULL) return GLOB_NOSPACE; @@ -561,7 +545,7 @@ /* `sysconf' does not support _SC_LOGIN_NAME_MAX. Try a moderate value. */ buflen = 20; - name = (char *) __alloca (buflen); + name = __alloca (buflen); success = getlogin_r (name, buflen) >= 0; # else @@ -582,7 +566,7 @@ Try a moderate value. */ pwbuflen = 1024; # endif - pwtmpbuf = (char *) __alloca (pwbuflen); + pwtmpbuf = __alloca (pwbuflen); while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p) != 0) @@ -597,7 +581,7 @@ 2 * pwbuflen); # else pwbuflen *= 2; - pwtmpbuf = (char *) __alloca (pwbuflen); + pwtmpbuf = __alloca (pwbuflen); # endif __set_errno (save); } @@ -624,7 +608,7 @@ { char *newp; size_t home_len = strlen (home_dir); - newp = (char *) __alloca (home_len + dirlen); + newp = __alloca (home_len + dirlen); mempcpy (mempcpy (newp, home_dir, home_len), &dirname[1], dirlen); dirname = newp; @@ -642,7 +626,7 @@ else { char *newp; - newp = (char *) __alloca (end_name - dirname); + newp = __alloca (end_name - dirname); *((char *) mempcpy (newp, dirname + 1, end_name - dirname)) = '\0'; user_name = newp; @@ -663,7 +647,7 @@ moderate value. */ buflen = 1024; # endif - pwtmpbuf = (char *) __alloca (buflen); + pwtmpbuf = __alloca (buflen); while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0) { @@ -694,7 +678,7 @@ char *newp; size_t home_len = strlen (home_dir); size_t rest_len = end_name == NULL ? 0 : strlen (end_name); - newp = (char *) __alloca (home_len + rest_len + 1); + newp = __alloca (home_len + rest_len + 1); *((char *) mempcpy (mempcpy (newp, home_dir, home_len), end_name, rest_len)) = '\0'; dirname = newp; @@ -727,8 +711,7 @@ char **new_gl_pathv; new_gl_pathv - = (char **) realloc (pglob->gl_pathv, - (newcount + 1 + 1) * sizeof (char *)); + = realloc (pglob->gl_pathv, (newcount + 1 + 1) * sizeof (char *)); if (new_gl_pathv == NULL) { nospace: @@ -842,9 +825,8 @@ int newcount = pglob->gl_pathc + pglob->gl_offs; char **new_gl_pathv; - new_gl_pathv = (char **) realloc (pglob->gl_pathv, - (newcount + 2) - * sizeof (char *)); + new_gl_pathv = realloc (pglob->gl_pathv, + (newcount + 2) * sizeof (char *)); if (new_gl_pathv == NULL) { globfree (&dirs); @@ -901,7 +883,7 @@ if (!(flags & GLOB_NOSORT)) { /* Sort the vector. */ - qsort ((void *) &pglob->gl_pathv[oldcount], + qsort (&pglob->gl_pathv[oldcount], pglob->gl_pathc + pglob->gl_offs - oldcount, sizeof (char *), collated_compare); } @@ -924,8 +906,8 @@ size_t i; for (i = 0; i < pglob->gl_pathc; ++i) if (pglob->gl_pathv[pglob->gl_offs + i] != NULL) - free ((void *) pglob->gl_pathv[pglob->gl_offs + i]); - free ((void *) pglob->gl_pathv); + free (pglob->gl_pathv[pglob->gl_offs + i]); + free (pglob->gl_pathv); pglob->gl_pathv = NULL; } } @@ -989,20 +971,20 @@ for (i = 0; i < n; ++i) { size_t eltlen = strlen (array[i]) + 1; - char *new = (char *) malloc (dirlen + 1 + eltlen); + char *new = malloc (dirlen + 1 + eltlen); if (new == NULL) { while (i > 0) - free ((void *) array[--i]); + free (array[--i]); return 1; } { - char *endp = (char *) mempcpy (new, dirname, dirlen); + char *endp = mempcpy (new, dirname, dirlen); *endp++ = DIRSEP_CHAR; mempcpy (endp, array[i], eltlen); } - free ((void *) array[i]); + free (array[i]); array[i] = new; } @@ -1060,7 +1042,7 @@ glob_t *pglob, int flags) { size_t fnamelen = strlen (fname); - char *fullname = (char *) __alloca (dirlen + 1 + fnamelen + 1); + char *fullname = __alloca (dirlen + 1 + fnamelen + 1); struct stat st; struct stat64 st64; @@ -1112,7 +1094,7 @@ struct stat st; struct stat64 st64; size_t patlen = strlen (pattern); - char *fullname = (char *) __alloca (dirlen + 1 + patlen + 1); + char *fullname = __alloca (dirlen + 1 + patlen + 1); mempcpy (mempcpy (mempcpy (fullname, directory, dirlen), "/", 1), @@ -1132,8 +1114,8 @@ { /* This is a special case for matching directories like in "*a/". */ - names = (struct globlink *) __alloca (sizeof (struct globlink)); - names->name = (char *) malloc (1); + names = __alloca (sizeof (struct globlink)); + names->name = malloc (1); if (names->name == NULL) goto memory_error; names->name[0] = '\0'; @@ -1145,7 +1127,7 @@ { stream = ((flags & GLOB_ALTDIRFUNC) ? (*pglob->gl_opendir) (directory) - : (void *) opendir (directory)); + : opendir (directory)); if (stream == NULL) { if (errno != ENOTDIR @@ -1170,7 +1152,7 @@ { const char *name; size_t len; -#if defined HAVE_DIRENT64 && !defined COMPILE_GLOB64 +#if defined HAVE_STRUCT_DIRENT64 && !defined COMPILE_GLOB64 struct dirent64 *d; union { @@ -1192,12 +1174,11 @@ d = NULL; } else - d = __readdir64 ((DIR *) stream); + d = __readdir64 (stream); #else struct dirent *d = ((flags & GLOB_ALTDIRFUNC) - ? ((struct dirent *) - (*pglob->gl_readdir) (stream)) - : __readdir ((DIR *) stream)); + ? ((*pglob->gl_readdir) (stream)) + : __readdir (stream)); #endif if (d == NULL) break; @@ -1230,15 +1211,15 @@ continue; { - struct globlink *new = (struct globlink *) + struct globlink *new = __alloca (sizeof (struct globlink)); char *p; len = NAMLEN (d); - new->name = malloc (len + 1 - + ((flags & GLOB_MARK) && isdir)); + new->name = + malloc (len + 1 + ((flags & GLOB_MARK) && isdir)); if (new->name == NULL) goto memory_error; - p = mempcpy ((void *) new->name, name, len); + p = mempcpy (new->name, name, len); if ((flags & GLOB_MARK) && isdir) *p++ = '/'; *p = '\0'; @@ -1256,9 +1237,9 @@ { size_t len = strlen (pattern); nfound = 1; - names = (struct globlink *) __alloca (sizeof (struct globlink)); + names = __alloca (sizeof (struct globlink)); names->next = NULL; - names->name = (char *) malloc (len + 1); + names->name = malloc (len + 1); if (names->name == NULL) goto memory_error; *((char *) mempcpy (names->name, pattern, len)) = '\0'; @@ -1269,7 +1250,7 @@ char **new_gl_pathv; new_gl_pathv - = (char **) realloc (pglob->gl_pathv, + = realloc (pglob->gl_pathv, (pglob->gl_pathc + pglob->gl_offs + nfound + 1) * sizeof (char *)); if (new_gl_pathv == NULL) @@ -1289,7 +1270,7 @@ if (flags & GLOB_ALTDIRFUNC) (*pglob->gl_closedir) (stream); else - closedir ((DIR *) stream); + closedir (stream); } __set_errno (save); @@ -1301,13 +1282,13 @@ if (flags & GLOB_ALTDIRFUNC) (*pglob->gl_closedir) (stream); else - closedir ((DIR *) stream); + closedir (stream); __set_errno (save); } while (names != NULL) { if (names->name != NULL) - free ((void *) names->name); + free (names->name); names = names->next; } return GLOB_NOSPACE; File [changed]: glob_.h Url: https://ccvs.cvshome.org/source/browse/ccvs/lib/glob_.h?r1=1.4&r2=1.5 Delta lines: +3 -15 -------------------- --- glob_.h 13 May 2005 21:26:36 -0000 1.4 +++ glob_.h 15 May 2005 16:44:04 -0000 1.5 @@ -26,7 +26,6 @@ # include <stddef.h> # undef __size_t # define __size_t size_t -# define __USE_GNU #endif __BEGIN_DECLS @@ -34,18 +33,11 @@ /* We need `size_t' for the following definitions. */ #ifdef _LIBC # ifndef __size_t -# if defined __GNUC__ && __GNUC__ >= 2 typedef __SIZE_TYPE__ __size_t; # ifdef __USE_XOPEN typedef __SIZE_TYPE__ size_t; # endif # else -# include <stddef.h> -# ifndef __size_t -# define __size_t size_t -# endif -# endif -# else /* The GNU CC stddef.h version defines __size_t as empty. We need a real definition. */ # undef __size_t @@ -162,11 +154,6 @@ } glob64_t; #endif -#if __USE_FILE_OFFSET64 && __GNUC__ < 2 -# define glob glob64 -# define globfree globfree64 -#endif - #ifdef GLOB_PREFIX # define __GLOB_CONCAT(x, y) x ## y # define __GLOB_XCONCAT(x, y) __GLOB_CONCAT (x, y) @@ -192,7 +179,7 @@ `glob' returns GLOB_ABEND; if it returns zero, the error is ignored. If memory cannot be allocated for PGLOB, GLOB_NOSPACE is returned. Otherwise, `glob' returns zero. */ -#if !defined _LIBC || !defined __USE_FILE_OFFSET64 || __GNUC__ < 2 +#if !defined _LIBC || !defined __USE_FILE_OFFSET64 extern int glob (__const char *__restrict __pattern, int __flags, int (*__errfunc) (__const char *, int), glob_t *__restrict __pglob) __THROW; @@ -207,6 +194,7 @@ extern void __REDIRECT_NTH (globfree, (glob_t *__pglob), globfree64); #endif + #ifdef __USE_LARGEFILE64 extern int glob64 (__const char *__restrict __pattern, int __flags, int (*__errfunc) (__const char *, int),