Should I commit the attached patch then?
On Tue, Jun 12, 2001 at 02:35:39PM +1000, Bruce Evans wrote:
For those interested, here's the missing patch.
Index: lib/libc/gen/fts.c
===
RCS file: /home/ncvs/src/lib/libc/gen/fts.c,v
retrieving revision 1.18
diff -u -p -r1.18 fts.c
--- lib/libc/gen/fts.c2001/06/01 21:53:50 1.18
+++ lib/libc/gen/fts.c2001/06/11 18:20:17
@@ -936,7 +936,8 @@ fts_sort(sp, head, nitems)
}
for (ap = sp-fts_array, p = head; p; p = p-fts_link)
*ap++ = p;
- qsort((void *)sp-fts_array, nitems, sizeof(FTSENT *), sp-fts_compar);
+ qsort((void *)sp-fts_array, nitems, sizeof(FTSENT *),
+ (int (*) __P((const void *, const void *)))sp-fts_compar);
for (head = *(ap = sp-fts_array); --nitems; ++ap)
ap[0]-fts_link = ap[1];
ap[0]-fts_link = NULL;
This just hides the bug that fts's comparison function is not suitable
for use by qsort().
Bruce
On Tue, Jun 12, 2001 at 02:38:13PM -0400, Garrett Wollman wrote:
On Tue, 12 Jun 2001 15:53:18 +0300, Ruslan Ermilov [EMAIL PROTECTED] said:
+ qsort((void *)sp-fts_array, nitems, sizeof(FTSENT *),
+ (int (*) __P((const void *, const void *)))sp-fts_compar);
This is wrong. The declaration of the comparison function should be
fixed, rather than papering over the mistake here.
(This is arguably a deficiency in the C standard. qsort() should take
an additional state parameter for the comparison function, but
doesn't.)
--
Ruslan Ermilov Oracle Developer/DBA,
[EMAIL PROTECTED] Sunbay Software AG,
[EMAIL PROTECTED] FreeBSD committer,
+380.652.512.251Simferopol, Ukraine
http://www.FreeBSD.org The Power To Serve
http://www.oracle.com Enabling The Information Age
Index: include/fts.h
===
RCS file: /home/ncvs/src/include/fts.h,v
retrieving revision 1.3
diff -u -p -r1.3 fts.h
--- include/fts.h 1997/05/07 19:59:58 1.3
+++ include/fts.h 2001/06/13 12:17:31
@@ -45,7 +45,8 @@ typedef struct {
int fts_rfd;/* fd for root */
int fts_pathlen;/* sizeof(path) */
int fts_nitems; /* elements in the sort array */
- int (*fts_compar)();/* compare function */
+ int (*fts_compar) /* compare function */
+ __P((const void *, const void *));
#defineFTS_COMFOLLOW 0x001 /* follow command line symlinks */
#defineFTS_LOGICAL 0x002 /* logical walk */
@@ -120,7 +121,7 @@ __BEGIN_DECLS
FTSENT *fts_children __P((FTS *, int));
int fts_close __P((FTS *));
FTS*fts_open __P((char * const *, int,
- int (*)(const FTSENT **, const FTSENT **)));
+ int (*)(const void *, const void *)));
FTSENT *fts_read __P((FTS *));
int fts_set __P((FTS *, FTSENT *, int));
__END_DECLS
Index: lib/libc/gen/fts.3
===
RCS file: /home/ncvs/src/lib/libc/gen/fts.3,v
retrieving revision 1.12
diff -u -p -r1.12 fts.3
--- lib/libc/gen/fts.3 2001/02/01 16:29:34 1.12
+++ lib/libc/gen/fts.3 2001/06/13 12:17:32
@@ -45,7 +45,7 @@
.Fd #include sys/stat.h
.Fd #include fts.h
.Ft FTS *
-.Fn fts_open char * const *path_argv int options int (*compar)(const FTSENT **,
const FTSENT **)
+.Fn fts_open char * const *path_argv int options int (*compar)(const void *,
+const void *)
.Ft FTSENT *
.Fn fts_read FTS *ftsp
.Ft FTSENT *
@@ -462,9 +462,9 @@ The argument
specifies a user-defined function which may be used to order the traversal
of the hierarchy.
It
-takes two pointers to pointers to
-.Fa FTSENT
-structures as arguments and
+takes two pointers as arguments (which need to be cast to
+.Vt FTSENT **
+inside the function's body) and
should return a negative value, zero, or a positive value to indicate
if the file referenced by its first argument comes before, in any order
with respect to, or after, the file referenced by its second argument.
Index: lib/libc/gen/fts.c
===
RCS file: /home/ncvs/src/lib/libc/gen/fts.c,v
retrieving revision 1.18
diff -u -p -r1.18 fts.c
--- lib/libc/gen/fts.c 2001/06/01 21:53:50 1.18
+++ lib/libc/gen/fts.c 2001/06/13 12:17:35
@@ -85,7 +85,7 @@ FTS *
fts_open(argv, options, compar)
char * const *argv;
register int options;
- int (*compar) __P((const FTSENT **, const FTSENT **));
+ int (*compar) __P((const void *, const void *));
{
register FTS *sp;
register FTSENT *p, *root;
Index: bin/cp/cp.c
===
RCS file: /home/ncvs/src/bin/cp/cp.c,v
retrieving revision 1.26
diff -u -p -r1.26 cp.c
--- bin/cp/cp.c 2001/06/11 13:57:54 1.26
+++