Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src scandir/alphasort take "const struct dirent **" not "const v...



details:   https://anonhg.NetBSD.org/src/rev/5022bba6b625
branches:  trunk
changeset: 819749:5022bba6b625
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Dec 16 04:45:04 2016 +0000

description:
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.

diffstat:

 include/dirent.h                       |   8 +++++---
 lib/libc/compat/gen/compat_alphasort.c |   3 ++-
 lib/libc/compat/gen/compat_scandir.c   |   3 ++-
 lib/libc/compat/include/dirent.h       |   7 ++++---
 lib/libc/gen/alphasort.c               |  10 +++++++---
 lib/libc/gen/initdir.c                 |   7 ++++---
 lib/libc/gen/scandir.3                 |  17 +++++++++++++----
 lib/libc/gen/scandir.c                 |  13 +++++++++----
 usr.sbin/lpr/lpc/cmds.c                |  11 ++++-------
 9 files changed, 50 insertions(+), 29 deletions(-)

diffs (274 lines):

diff -r 7c4c2e663b6c -r 5022bba6b625 include/dirent.h
--- a/include/dirent.h  Fri Dec 16 04:27:03 2016 +0000
+++ b/include/dirent.h  Fri Dec 16 04:45:04 2016 +0000
@@ -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 @@
 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
diff -r 7c4c2e663b6c -r 5022bba6b625 lib/libc/compat/gen/compat_alphasort.c
--- a/lib/libc/compat/gen/compat_alphasort.c    Fri Dec 16 04:27:03 2016 +0000
+++ b/lib/libc/compat/gen/compat_alphasort.c    Fri Dec 16 04:45:04 2016 +0000
@@ -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 @@
 #endif
 
 #define dirent dirent12
+#define ALPHASORTARG void *
 
 #include "gen/alphasort.c"
diff -r 7c4c2e663b6c -r 5022bba6b625 lib/libc/compat/gen/compat_scandir.c
--- a/lib/libc/compat/gen/compat_scandir.c      Fri Dec 16 04:27:03 2016 +0000
+++ b/lib/libc/compat/gen/compat_scandir.c      Fri Dec 16 04:45:04 2016 +0000
@@ -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 @@
 #endif
 
 #define dirent dirent12
+#define COMPARARG void *
 
 #include "gen/scandir.c"
diff -r 7c4c2e663b6c -r 5022bba6b625 lib/libc/compat/include/dirent.h
--- a/lib/libc/compat/include/dirent.h  Fri Dec 16 04:27:03 2016 +0000
+++ b/lib/libc/compat/include/dirent.h  Fri Dec 16 04:45:04 2016 +0000
@@ -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 @@
 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 *);
 
diff -r 7c4c2e663b6c -r 5022bba6b625 lib/libc/gen/alphasort.c
--- a/lib/libc/gen/alphasort.c  Fri Dec 16 04:27:03 2016 +0000
+++ b/lib/libc/gen/alphasort.c  Fri Dec 16 04:45:04 2016 +0000
@@ -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 @@
 #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);
diff -r 7c4c2e663b6c -r 5022bba6b625 lib/libc/gen/initdir.c
--- a/lib/libc/gen/initdir.c    Fri Dec 16 04:27:03 2016 +0000
+++ b/lib/libc/gen/initdir.c    Fri Dec 16 04:45:04 2016 +0000
@@ -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 @@
                                         * This sort must be stable.
                                         */
                                        mergesort(dpv, (size_t)n, sizeof(*dpv),
-                                           alphasort);
+                                           (int (*)(const void *,
+                                                    const void *))alphasort);
 
                                        dpv[n] = NULL;
                                        xp = NULL;
diff -r 7c4c2e663b6c -r 5022bba6b625 lib/libc/gen/scandir.3
--- a/lib/libc/gen/scandir.3    Fri Dec 16 04:27:03 2016 +0000
+++ b/lib/libc/gen/scandir.3    Fri Dec 16 04:45:04 2016 +0000
@@ -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 @@
 .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 .
diff -r 7c4c2e663b6c -r 5022bba6b625 lib/libc/gen/scandir.c
--- a/lib/libc/gen/scandir.c    Fri Dec 16 04:27:03 2016 +0000
+++ b/lib/libc/gen/scandir.c    Fri Dec 16 04:45:04 2016 +0000
@@ -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 @@
        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 @@
        }
        (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;
diff -r 7c4c2e663b6c -r 5022bba6b625 usr.sbin/lpr/lpc/cmds.c
--- a/usr.sbin/lpr/lpc/cmds.c   Fri Dec 16 04:27:03 2016 +0000
+++ b/usr.sbin/lpr/lpc/cmds.c   Fri Dec 16 04:45:04 2016 +0000
@@ -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 @@
 #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 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 @@
  * 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];



Home | Main Index | Thread Index | Old Index