summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/opendir.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2010-01-05 20:20:31 +0000
committerkib <kib@FreeBSD.org>2010-01-05 20:20:31 +0000
commit95ccd2a39d6e19b8cdffca8356395ffed863a8b6 (patch)
tree881c3065ed089bb80458a62de949dae3a87d4d65 /lib/libc/gen/opendir.c
parentbdeb978682602f230c0327f6bc99de24fce20ec0 (diff)
downloadFreeBSD-src-95ccd2a39d6e19b8cdffca8356395ffed863a8b6.zip
FreeBSD-src-95ccd2a39d6e19b8cdffca8356395ffed863a8b6.tar.gz
Do not rely on behaviour undefined by ANSI C, use thunks to adapt
alphasort-like interface to the comparision function required by qsort() and qsort_r(). For opendir() thunk and alphasort(), comment on why we deviated from POSIX by using strcmp() instead of strcoll(). Requested and reviewed by: bde MFC after: 2 weeks
Diffstat (limited to 'lib/libc/gen/opendir.c')
-rw-r--r--lib/libc/gen/opendir.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c
index 631c4d6..c192ab2 100644
--- a/lib/libc/gen/opendir.c
+++ b/lib/libc/gen/opendir.c
@@ -93,6 +93,18 @@ __opendir2(const char *name, int flags)
}
/*
+ * POSIX 2008 and XSI 7 require alphasort() to call strcoll() for
+ * directory entries ordering. Use local copy that uses strcmp().
+ */
+static int
+opendir_alphasort(const void *p1, const void *p2)
+{
+
+ return (strcmp((*(const struct dirent **)p1)->d_name,
+ (*(const struct dirent **)p2)->d_name));
+}
+
+/*
* Common routine for opendir(3), __opendir2(3) and fdopendir(3).
*/
static DIR *
@@ -240,8 +252,8 @@ __opendir_common(int fd, const char *name, int flags)
/*
* This sort must be stable.
*/
- mergesort(dpv, n, sizeof(*dpv), (int (*)(const
- void *, const void *))alphasort);
+ mergesort(dpv, n, sizeof(*dpv),
+ opendir_alphasort);
dpv[n] = NULL;
xp = NULL;
OpenPOWER on IntegriCloud