<fts.h>: fix fts_compar declaration for C23.
In C23, `void foo()` means `void foo(void)`, not `void foo(...)`.
Bug: http://b/395885866
(cherry picked from https://android-review.googlesource.com/q/commit:903b30650eac60523b4b6f7d16cfd851a402c423)
Merged-In: I10da57db60d1921f930e78db3a792aceeae04e5e
Change-Id: I10da57db60d1921f930e78db3a792aceeae04e5e
diff --git a/libc/bionic/fts.c b/libc/bionic/fts.c
index c36835e..072d297 100644
--- a/libc/bionic/fts.c
+++ b/libc/bionic/fts.c
@@ -892,7 +892,9 @@
}
for (ap = sp->fts_array, p = head; p; p = p->fts_link)
*ap++ = p;
- qsort(sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar);
+ // The cast here is to cast away the nullability.
+ // fts_compar is nullable, but we only enter this function if it's non-null.
+ qsort(sp->fts_array, nitems, sizeof(FTSENT *), (int (*)(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;
diff --git a/libc/include/fts.h b/libc/include/fts.h
index aabe2db..ac3ecc8 100644
--- a/libc/include/fts.h
+++ b/libc/include/fts.h
@@ -38,32 +38,6 @@
#include <sys/cdefs.h>
#include <sys/types.h>
-typedef struct {
- struct _ftsent * _Nullable fts_cur; /* current node */
- struct _ftsent * _Nullable fts_child; /* linked list of children */
- struct _ftsent * _Nullable * _Nullable fts_array; /* sort array */
- dev_t fts_dev; /* starting device # */
- char * _Nullable fts_path; /* path for this descent */
- int fts_rfd; /* fd for root */
- size_t fts_pathlen; /* sizeof(path) */
- int fts_nitems; /* elements in the sort array */
- int (* _Nullable fts_compar)(); /* compare function */
-
-#define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */
-#define FTS_LOGICAL 0x0002 /* logical walk */
-#define FTS_NOCHDIR 0x0004 /* don't change directories */
-#define FTS_NOSTAT 0x0008 /* don't get stat info */
-#define FTS_PHYSICAL 0x0010 /* physical walk */
-#define FTS_SEEDOT 0x0020 /* return dot and dot-dot */
-#define FTS_XDEV 0x0040 /* don't cross devices */
-#define FTS_OPTIONMASK 0x00ff /* valid user option mask */
-
-#define FTS_NAMEONLY 0x1000 /* (private) child names only */
-#define FTS_STOP 0x2000 /* (private) unrecoverable error */
-#define FTS_FOR_FTW 0x4000 /* (private) fts is being called by ftw/nftw */
- int fts_options; /* fts_open options, global flags */
-} FTS;
-
typedef struct _ftsent {
struct _ftsent * _Nullable fts_cycle; /* cycle node */
struct _ftsent * _Nullable fts_parent; /* parent directory */
@@ -115,6 +89,32 @@
char fts_name[1]; /* file name */
} FTSENT;
+typedef struct {
+ struct _ftsent * _Nullable fts_cur; /* current node */
+ struct _ftsent * _Nullable fts_child; /* linked list of children */
+ struct _ftsent * _Nullable * _Nullable fts_array; /* sort array */
+ dev_t fts_dev; /* starting device # */
+ char * _Nullable fts_path; /* path for this descent */
+ int fts_rfd; /* fd for root */
+ size_t fts_pathlen; /* sizeof(path) */
+ int fts_nitems; /* elements in the sort array */
+ int (* _Nullable fts_compar)(const FTSENT **, const FTSENT **); /* compare function */
+
+#define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */
+#define FTS_LOGICAL 0x0002 /* logical walk */
+#define FTS_NOCHDIR 0x0004 /* don't change directories */
+#define FTS_NOSTAT 0x0008 /* don't get stat info */
+#define FTS_PHYSICAL 0x0010 /* physical walk */
+#define FTS_SEEDOT 0x0020 /* return dot and dot-dot */
+#define FTS_XDEV 0x0040 /* don't cross devices */
+#define FTS_OPTIONMASK 0x00ff /* valid user option mask */
+
+#define FTS_NAMEONLY 0x1000 /* (private) child names only */
+#define FTS_STOP 0x2000 /* (private) unrecoverable error */
+#define FTS_FOR_FTW 0x4000 /* (private) fts is being called by ftw/nftw */
+ int fts_options; /* fts_open options, global flags */
+} FTS;
+
__BEGIN_DECLS
FTSENT* _Nullable fts_children(FTS* _Nonnull __fts, int __options);