Module Name:    src
Committed By:   mrg
Date:           Fri Dec 16 04:45:04 UTC 2016

Modified Files:
        src/include: dirent.h
        src/lib/libc/compat/gen: compat_alphasort.c compat_scandir.c
        src/lib/libc/compat/include: dirent.h
        src/lib/libc/gen: alphasort.c initdir.c scandir.3 scandir.c
        src/usr.sbin/lpr/lpc: cmds.c

Log Message:
scandir/alphasort take "const struct dirent **" not "const void *" in
modern unix.  since we claim to be 'IEEE Std 1003.1-2008', make it so.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/include/dirent.h
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/compat/gen/compat_alphasort.c \
    src/lib/libc/compat/gen/compat_scandir.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/compat/include/dirent.h
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/gen/alphasort.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/gen/initdir.c
cvs rdiff -u -r1.14 -r1.15 src/lib/libc/gen/scandir.3
cvs rdiff -u -r1.27 -r1.28 src/lib/libc/gen/scandir.c
cvs rdiff -u -r1.24 -r1.25 src/usr.sbin/lpr/lpc/cmds.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/include/dirent.h
diff -u src/include/dirent.h:1.35 src/include/dirent.h:1.36
--- src/include/dirent.h:1.35	Mon Jul 30 23:11:13 2012
+++ src/include/dirent.h	Fri Dec 16 04:45:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: dirent.h,v 1.35 2012/07/30 23:11:13 yamt Exp $	*/
+/*	$NetBSD: dirent.h,v 1.36 2016/12/16 04:45:04 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -109,10 +109,12 @@ long telldir(DIR *);
 DIR *fdopendir(int);
 DIR *__opendir2(const char *, int) __RENAME(__opendir230);
 int scandir(const char *, struct dirent ***,
-    int (*)(const struct dirent *), int (*)(const void *, const void *))
+    int (*)(const struct dirent *), int (*)(const struct dirent **,
+    const struct dirent **))
     __RENAME(__scandir30);
 int getdents(int, char *, size_t) __RENAME(__getdents30);
-int alphasort(const void *, const void *) __RENAME(__alphasort30);
+int alphasort(const struct dirent **, const struct dirent **)
+    __RENAME(__alphasort30);
 #endif
 #endif /* defined(_NETBSD_SOURCE) */
 __END_DECLS

Index: src/lib/libc/compat/gen/compat_alphasort.c
diff -u src/lib/libc/compat/gen/compat_alphasort.c:1.1 src/lib/libc/compat/gen/compat_alphasort.c:1.2
--- src/lib/libc/compat/gen/compat_alphasort.c:1.1	Tue Feb 24 18:42:36 2009
+++ src/lib/libc/compat/gen/compat_alphasort.c	Fri Dec 16 04:45:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_alphasort.c,v 1.1 2009/02/24 18:42:36 christos Exp $	*/
+/*	$NetBSD: compat_alphasort.c,v 1.2 2016/12/16 04:45:04 mrg Exp $	*/
 
 #include <sys/stat.h>
 #define __LIBC12_SOURCE__
@@ -16,5 +16,6 @@ __warn_references(alphasort,
 #endif
 
 #define dirent dirent12
+#define ALPHASORTARG void *
 
 #include "gen/alphasort.c"
Index: src/lib/libc/compat/gen/compat_scandir.c
diff -u src/lib/libc/compat/gen/compat_scandir.c:1.1 src/lib/libc/compat/gen/compat_scandir.c:1.2
--- src/lib/libc/compat/gen/compat_scandir.c:1.1	Tue Sep 13 01:44:09 2005
+++ src/lib/libc/compat/gen/compat_scandir.c	Fri Dec 16 04:45:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: compat_scandir.c,v 1.1 2005/09/13 01:44:09 christos Exp $	*/
+/*	$NetBSD: compat_scandir.c,v 1.2 2016/12/16 04:45:04 mrg Exp $	*/
 
 #include <sys/stat.h>
 #define __LIBC12_SOURCE__
@@ -16,5 +16,6 @@ __warn_references(scandir,
 #endif
 
 #define dirent dirent12
+#define COMPARARG void *
 
 #include "gen/scandir.c"

Index: src/lib/libc/compat/include/dirent.h
diff -u src/lib/libc/compat/include/dirent.h:1.7 src/lib/libc/compat/include/dirent.h:1.8
--- src/lib/libc/compat/include/dirent.h:1.7	Tue Feb 24 18:42:36 2009
+++ src/lib/libc/compat/include/dirent.h	Fri Dec 16 04:45:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: dirent.h,v 1.7 2009/02/24 18:42:36 christos Exp $	*/
+/*	$NetBSD: dirent.h,v 1.8 2016/12/16 04:45:04 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -61,13 +61,14 @@ DIR *__opendir230(const char *, int);
 int scandir(const char *, struct dirent12 ***,
     int (*)(const struct dirent12 *), int (*)(const void *, const void *));
 int __scandir30(const char *, struct dirent ***,
-    int (*)(const struct dirent *), int (*)(const void *, const void *));
+    int (*)(const struct dirent *),
+    int (*)(const struct dirent **, const struct dirent **));
 
 int getdents(int, char *, size_t);
 int __getdents30(int, char *, size_t);
 
 int alphasort(const void *, const void *);
-int __alphasort30(const void *, const void *);
+int __alphasort30(const struct dirent **, const struct dirent **);
 
 int getdirentries(int, char *, int, long *);
 

Index: src/lib/libc/gen/alphasort.c
diff -u src/lib/libc/gen/alphasort.c:1.2 src/lib/libc/gen/alphasort.c:1.3
--- src/lib/libc/gen/alphasort.c:1.2	Sun Mar  1 19:59:55 2009
+++ src/lib/libc/gen/alphasort.c	Fri Dec 16 04:45:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: alphasort.c,v 1.2 2009/03/01 19:59:55 christos Exp $	*/
+/*	$NetBSD: alphasort.c,v 1.3 2016/12/16 04:45:04 mrg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)scandir.c	8.3 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: alphasort.c,v 1.2 2009/03/01 19:59:55 christos Exp $");
+__RCSID("$NetBSD: alphasort.c,v 1.3 2016/12/16 04:45:04 mrg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -44,11 +44,15 @@ __RCSID("$NetBSD: alphasort.c,v 1.2 2009
 #include <dirent.h>
 #include <string.h>
 
+#ifndef ALPHASORTARG
+#define ALPHASORTARG struct dirent **
+#endif
+
 /*
  * Alphabetic order comparison routine for those who want it.
  */
 int
-alphasort(const void *d1, const void *d2)
+alphasort(const ALPHASORTARG d1, const ALPHASORTARG d2)
 {
 
 	_DIAGASSERT(d1 != NULL);

Index: src/lib/libc/gen/initdir.c
diff -u src/lib/libc/gen/initdir.c:1.3 src/lib/libc/gen/initdir.c:1.4
--- src/lib/libc/gen/initdir.c:1.3	Tue Mar 13 21:13:36 2012
+++ src/lib/libc/gen/initdir.c	Fri Dec 16 04:45:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: initdir.c,v 1.3 2012/03/13 21:13:36 christos Exp $	*/
+/*	$NetBSD: initdir.c,v 1.4 2016/12/16 04:45:04 mrg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: initdir.c,v 1.3 2012/03/13 21:13:36 christos Exp $");
+__RCSID("$NetBSD: initdir.c,v 1.4 2016/12/16 04:45:04 mrg Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -201,7 +201,8 @@ retry:
 					 * This sort must be stable.
 					 */
 					mergesort(dpv, (size_t)n, sizeof(*dpv),
-					    alphasort);
+					    (int (*)(const void *,
+						     const void *))alphasort);
 
 					dpv[n] = NULL;
 					xp = NULL;

Index: src/lib/libc/gen/scandir.3
diff -u src/lib/libc/gen/scandir.3:1.14 src/lib/libc/gen/scandir.3:1.15
--- src/lib/libc/gen/scandir.3:1.14	Fri Dec 17 19:20:42 2010
+++ src/lib/libc/gen/scandir.3	Fri Dec 16 04:45:04 2016
@@ -1,4 +1,4 @@
-.\"	$NetBSD: scandir.3,v 1.14 2010/12/17 19:20:42 njoly Exp $
+.\"	$NetBSD: scandir.3,v 1.15 2016/12/16 04:45:04 mrg Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)scandir.3	8.1 (Berkeley) 6/4/93
 .\"
-.Dd April 29, 2010
+.Dd December 15, 2016
 .Dt SCANDIR 3
 .Os
 .Sh NAME
@@ -42,9 +42,9 @@
 .In sys/types.h
 .In dirent.h
 .Ft int
-.Fn scandir "const char *dirname" "struct dirent ***namelist" "int \*(lp*select\*(rp\*(lpconst struct 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
@@ -111,3 +111,12 @@ and
 .Fn alphasort
 functions appeared in
 .Bx 4.2 .
+.Pp
+They were changed in
+.Nx 8.0
+to use
+.Dq struct dirent **
+instead of
+.Dq void *
+for the comparision function, including
+.Fn alphasort .

Index: src/lib/libc/gen/scandir.c
diff -u src/lib/libc/gen/scandir.c:1.27 src/lib/libc/gen/scandir.c:1.28
--- src/lib/libc/gen/scandir.c:1.27	Tue Mar 13 21:13:36 2012
+++ src/lib/libc/gen/scandir.c	Fri Dec 16 04:45:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: scandir.c,v 1.27 2012/03/13 21:13:36 christos Exp $	*/
+/*	$NetBSD: scandir.c,v 1.28 2016/12/16 04:45:04 mrg Exp $	*/
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)scandir.c	8.3 (Berkeley) 1/2/94";
 #else
-__RCSID("$NetBSD: scandir.c,v 1.27 2012/03/13 21:13:36 christos Exp $");
+__RCSID("$NetBSD: scandir.c,v 1.28 2016/12/16 04:45:04 mrg Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -82,10 +82,14 @@ dirsize(int fd, size_t olen)
 	return olen + nlen;
 }
 
+#ifndef COMPARARG
+#define COMPARARG struct dirent **
+#endif
+
 int
 scandir(const char *dirname, struct dirent ***namelist,
     int (*selectfn)(const struct dirent *),
-    int (*dcomp)(const void *, const void *))
+    int (*dcomp)(const COMPARARG, const COMPARARG))
 {
 	struct dirent *d, *p, **names, **newnames;
 	size_t nitems, arraysz;
@@ -137,7 +141,8 @@ scandir(const char *dirname, struct dire
 	}
 	(void)closedir(dirp);
 	if (nitems && dcomp != NULL)
-		qsort(names, nitems, sizeof(*names), dcomp);
+		qsort(names, nitems, sizeof(*names),
+		      (int (*)(const void *, const void *))dcomp);
 	*namelist = names;
 	_DIAGASSERT(__type_fit(int, nitems));
 	return (int)nitems;

Index: src/usr.sbin/lpr/lpc/cmds.c
diff -u src/usr.sbin/lpr/lpc/cmds.c:1.24 src/usr.sbin/lpr/lpc/cmds.c:1.25
--- src/usr.sbin/lpr/lpc/cmds.c:1.24	Wed Aug 31 16:24:59 2011
+++ src/usr.sbin/lpr/lpc/cmds.c	Fri Dec 16 04:45:04 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: cmds.c,v 1.24 2011/08/31 16:24:59 plunky Exp $	*/
+/*	$NetBSD: cmds.c,v 1.25 2016/12/16 04:45:04 mrg Exp $	*/
 /*
  * Copyright (c) 1983, 1993
  *	The Regents of the University of California.  All rights reserved.
@@ -36,7 +36,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "@(#)cmds.c	8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: cmds.c,v 1.24 2011/08/31 16:24:59 plunky Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.25 2016/12/16 04:45:04 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -74,7 +74,7 @@ static int	doselect(const struct dirent 
 static void	enablepr(void);
 static void	prstat(void);
 static void	putmsg(int, char **);
-static int	sortq(const void *, const void *);
+static int	sortq(const struct dirent **, const struct dirent **);
 static void	startpr(int);
 static void	stoppr(void);
 static int	touch(struct queue *);
@@ -256,13 +256,10 @@ doselect(const struct dirent *d)
  * by `cf', `tf', or `df', then by the sequence letter A-Z, a-z.
  */
 static int
-sortq(const void *a, const void *b)
+sortq(const struct dirent **d1, const struct dirent **d2)
 {
-	const struct dirent *const *d1, *const *d2;
 	int c1, c2;
 
-	d1 = (const struct dirent *const *)a;
-	d2 = (const struct dirent *const *)b;
 	if ((c1 = strcmp((*d1)->d_name + 3, (*d2)->d_name + 3)) != 0)
 		return(c1);
 	c1 = (*d1)->d_name[0];

Reply via email to