From edacbda68e2b4fcf6f29f472d4c2720d202639dc Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Fri, 5 Nov 2010 01:28:22 +0100 Subject: [PATCH] alphasort(3)/scandir(3): Sync prototypes with POSIX.1-2008. These functions have been added to the latest issue (7) of the OpenGroup specifications. Since our default still is POSIX.1-2001, make them visible if either _POSIX_C_SOURCE >= 200809 is defined or if _POSIX_SOURCE is not defined (which was what we had previously). The latter condition is left in for backwards compatibility and can be removed once we switch to 200809. Also fix some consumers of scandir(3) which we have in base. This fixes the build of devel/libcompizconfig. I've checked this change with 22 out of 114 packages that use scandir(), and aside from some warnings, there were no issues. Reported-by: alexh Dragonfly-bug: Based-on: FreeBSD --- include/dirent.h | 9 +++++---- lib/libc/gen/scandir.3 | 7 +++---- lib/libc/gen/scandir.c | 12 ++++++------ usr.bin/catman/catman.c | 11 ++++++++--- usr.sbin/lpr/common_source/lp.h | 3 +-- usr.sbin/lpr/common_source/rmjob.c | 3 +-- usr.sbin/lpr/lpc/cmds.c | 13 ++++++------- usr.sbin/makewhatis/makewhatis.c | 5 ++--- 8 files changed, 32 insertions(+), 31 deletions(-) diff --git a/include/dirent.h b/include/dirent.h index 0bd09c2e04..21b4d89521 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -32,7 +32,6 @@ * * @(#)dirent.h 8.2 (Berkeley) 7/28/94 * $FreeBSD: src/include/dirent.h,v 1.7 1999/12/29 05:01:20 peter Exp $ - * $DragonFly: src/include/dirent.h,v 1.10 2008/06/05 17:53:10 swildner Exp $ */ #ifndef _DIRENT_H_ @@ -88,6 +87,11 @@ DIR *fdopendir (int); struct dirent *readdir (DIR *); void rewinddir (DIR *); int closedir (DIR *); +#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700 || !defined(_POSIX_SOURCE) +int alphasort (const struct dirent **, const struct dirent **); +int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), + int (*)(const struct dirent **, const struct dirent **)); +#endif #ifndef _POSIX_SOURCE DIR *__opendir2 (const char *, int); DIR *__fdopendir2 (int, int); @@ -96,9 +100,6 @@ struct dirent *_readdir_unlocked(DIR *, int); void seekdir(DIR *, long); void _reclaim_telldir(DIR *); void _seekdir (DIR *, long); -int scandir (const char *, struct dirent ***, - int (*)(struct dirent *), int (*)(const void *, const void *)); -int alphasort (const void *, const void *); int getdents (int, char *, int); int getdirentries (int, char *, int, long *); int readdir_r (DIR *, struct dirent *, struct dirent **); diff --git a/lib/libc/gen/scandir.3 b/lib/libc/gen/scandir.3 index d9d0d48df4..8ed8f43f2d 100644 --- a/lib/libc/gen/scandir.3 +++ b/lib/libc/gen/scandir.3 @@ -31,9 +31,8 @@ .\" .\" @(#)scandir.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD: src/lib/libc/gen/scandir.3,v 1.3.2.5 2003/03/15 15:11:05 trhodes Exp $ -.\" $DragonFly: src/lib/libc/gen/scandir.3,v 1.2 2003/06/17 04:26:42 dillon Exp $ .\" -.Dd June 4, 1993 +.Dd November 4, 2010 .Dt SCANDIR 3 .Os .Sh NAME @@ -46,9 +45,9 @@ .In sys/types.h .In dirent.h .Ft int -.Fn scandir "const char *dirname" "struct dirent ***namelist" "int \\*(lp*select\\*(rp\\*(lpstruct dirent *\\*(rp" "int \\*(lp*compar\\*(rp\\*(lpconst void *, const void *\\*(rp" +.Fn scandir "const char *dirname" "struct dirent ***namelist" "int \\*(lp*select\\*(rp\\*(lpconst struct dirent *\\*(rp" "int \\*(lp*compar\\*(rp\\*(lpconst struct dirent **, const struct dirent **\\*(rp" .Ft int -.Fn alphasort "const void *d1" "const void *d2" +.Fn alphasort "const struct dirent **d1" "const struct dirent **d2" .Sh DESCRIPTION The .Fn scandir diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 4d0ab70766..534d1f3dcb 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -31,7 +31,6 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/scandir.c,v 1.5.6.1 2001/03/05 09:52:13 obrien Exp $ - * $DragonFly: src/lib/libc/gen/scandir.c,v 1.7 2005/08/27 20:23:05 joerg Exp $ * * @(#)scandir.c 8.3 (Berkeley) 1/2/94 */ @@ -54,7 +53,8 @@ int scandir(const char *dirname, struct dirent ***namelist, - int (*select)(struct dirent *), int (*dcomp)(const void *, const void *)) + int (*select)(const struct dirent *), + int (*dcomp)(const struct dirent **, const struct dirent **)) { struct dirent *d, *p, **names = NULL; size_t arraysz, nitems = 0; @@ -112,7 +112,8 @@ scandir(const char *dirname, struct dirent ***namelist, } closedir(dirp); if (nitems && dcomp != NULL) - qsort(names, nitems, sizeof(struct dirent *), dcomp); + qsort(names, nitems, sizeof(struct dirent *), + (int (*)(const void *, const void *))dcomp); *namelist = names; return(nitems); @@ -128,8 +129,7 @@ fail: * Alphabetic order comparison routine for those who want it. */ int -alphasort(const void *d1, const void *d2) +alphasort(const struct dirent **d1, const struct dirent **d2) { - return(strcmp((*(const struct dirent * const *)d1)->d_name, - (*(const struct dirent * const *)d2)->d_name)); + return(strcmp((*d1)->d_name, (*d2)->d_name)); } diff --git a/usr.bin/catman/catman.c b/usr.bin/catman/catman.c index 1a1dd26fe6..6984b00eee 100644 --- a/usr.bin/catman/catman.c +++ b/usr.bin/catman/catman.c @@ -26,7 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/usr.bin/catman/catman.c,v 1.9 2003/06/10 02:18:00 ache Exp $ - * $DragonFly: src/usr.bin/catman/catman.c,v 1.4 2008/11/10 16:10:34 swildner Exp $ */ #include @@ -599,9 +598,15 @@ process_section(char *mandir, char *section) } static int -select_sections(struct dirent *entry) +select_sections(const struct dirent *entry) { - return(directory_type(entry->d_name) == MAN_SECTION_DIR); + char *name; + int ret; + + name = strdup(entry->d_name); + ret = directory_type(name) == MAN_SECTION_DIR; + free(name); + return(ret); } /* diff --git a/usr.sbin/lpr/common_source/lp.h b/usr.sbin/lpr/common_source/lp.h index 3f05730dd6..8c8e919091 100644 --- a/usr.sbin/lpr/common_source/lp.h +++ b/usr.sbin/lpr/common_source/lp.h @@ -32,7 +32,6 @@ * * From: @(#)lp.h 8.2 (Berkeley) 4/28/95 * $FreeBSD: src/usr.sbin/lpr/common_source/lp.h,v 1.9.2.12 2002/07/14 23:56:40 gad Exp $ - * $DragonFly: src/usr.sbin/lpr/common_source/lp.h,v 1.3 2005/08/08 18:58:56 joerg Exp $ */ #include @@ -281,7 +280,7 @@ void inform(const struct printer *_pp, char *_cf); void init_printer(struct printer *_pp); void init_request(struct request *_rp); int inlist(char *_uname, char *_cfile); -int iscf(struct dirent *_d); +int iscf(const struct dirent *_d); int isowner(char *_owner, char *_file); void ldump(const char *_nfile, const char *_datafile, int _copies); void lastprinter(void); diff --git a/usr.sbin/lpr/common_source/rmjob.c b/usr.sbin/lpr/common_source/rmjob.c index 72ed5d28ac..58f6824a65 100644 --- a/usr.sbin/lpr/common_source/rmjob.c +++ b/usr.sbin/lpr/common_source/rmjob.c @@ -32,7 +32,6 @@ * * @(#)rmjob.c 8.2 (Berkeley) 4/28/95 * $FreeBSD: src/usr.sbin/lpr/common_source/rmjob.c,v 1.12.2.5 2001/06/25 01:00:56 gad Exp $ - * $DragonFly: src/usr.sbin/lpr/common_source/rmjob.c,v 1.4 2004/12/18 22:48:03 swildner Exp $ */ #include @@ -378,7 +377,7 @@ rmremote(const struct printer *pp) * Return 1 if the filename begins with 'cf' */ int -iscf(struct dirent *d) +iscf(const struct dirent *d) { return(d->d_name[0] == 'c' && d->d_name[1] == 'f'); } diff --git a/usr.sbin/lpr/lpc/cmds.c b/usr.sbin/lpr/lpc/cmds.c index 471c83ee49..75db5478ac 100644 --- a/usr.sbin/lpr/lpc/cmds.c +++ b/usr.sbin/lpr/lpc/cmds.c @@ -34,7 +34,6 @@ * @(#) Copyright (c) 1983, 1993 The Regents of the University of California. All rights reserved. * @(#)cmds.c 8.2 (Berkeley) 4/28/95 * $FreeBSD: src/usr.sbin/lpr/lpc/cmds.c,v 1.14.2.16 2002/07/25 23:29:39 gad Exp $ - * $DragonFly: src/usr.sbin/lpr/lpc/cmds.c,v 1.4 2004/12/18 22:48:03 swildner Exp $ */ /* @@ -71,9 +70,9 @@ static char *args2line(int argc, char **argv); static int doarg(char *_job); -static int doselect(struct dirent *_d); +static int doselect(const struct dirent *_d); static int kill_qtask(const char *lf); -static int sortq(const void *_a, const void *_b); +static int sortq(const struct dirent **_a, const struct dirent **_b); static int touch(struct jobqueue *_jq); static void unlinkf(char *_name); static void upstat(struct printer *_pp, const char *_msg, int _notify); @@ -445,7 +444,7 @@ static int cln_queuecnt; /* number of queues checked */ static int cln_testonly; /* remove-files vs just-print-info */ static int -doselect(struct dirent *d) +doselect(const struct dirent *d) { int c = d->d_name[0]; @@ -480,14 +479,14 @@ doselect(struct dirent *d) * filenames (they will have datafile names which start with `dfB*'). */ static int -sortq(const void *a, const void *b) +sortq(const struct dirent **a, const struct dirent **b) { const int a_lt_b = -1, a_gt_b = 1, cat_other = 10; const char *fname_a, *fname_b, *jnum_a, *jnum_b; int cat_a, cat_b, ch, res, seq_a, seq_b; - fname_a = (*(const struct dirent * const *)a)->d_name; - fname_b = (*(const struct dirent * const *)b)->d_name; + fname_a = (*a)->d_name; + fname_b = (*b)->d_name; /* * First separate filenames into cagatories. Catagories are diff --git a/usr.sbin/makewhatis/makewhatis.c b/usr.sbin/makewhatis/makewhatis.c index 1295c2676f..574b1b0e72 100644 --- a/usr.sbin/makewhatis/makewhatis.c +++ b/usr.sbin/makewhatis/makewhatis.c @@ -26,7 +26,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/usr.bin/makewhatis/makewhatis.c,v 1.9 2002/09/04 23:29:04 dwmalone Exp $ - * $DragonFly: src/usr.sbin/makewhatis/makewhatis.c,v 1.2 2005/01/16 04:59:53 cpressey Exp $ */ #include @@ -884,9 +883,9 @@ process_section(char *section_dir) * Returns whether the directory entry is a man page section. */ static int -select_sections(struct dirent *entry) +select_sections(const struct dirent *entry) { - char *p = &entry->d_name[3]; + const char *p = &entry->d_name[3]; if (strncmp(entry->d_name, "man", 3) != 0) return(0); -- 2.41.0