about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--include/dirent.h5
-rw-r--r--src/dirent/versionsort.c8
2 files changed, 13 insertions, 0 deletions
diff --git a/include/dirent.h b/include/dirent.h
index cb8cb248..6241220f 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -50,12 +50,17 @@ int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int
 #define DTTOIF(x) ((x)<<12)
 #endif
 
+#ifdef _GNU_SOURCE
+int versionsort(const struct dirent **, const struct dirent **);
+#endif
+
 #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
 #define dirent64 dirent
 #define readdir64 readdir
 #define readdir64_r readdir_r
 #define scandir64 scandir
 #define alphasort64 alphasort
+#define versionsort64 versionsort
 #define off64_t off_t
 #define ino64_t ino_t
 #endif
diff --git a/src/dirent/versionsort.c b/src/dirent/versionsort.c
new file mode 100644
index 00000000..97696105
--- /dev/null
+++ b/src/dirent/versionsort.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include <string.h>
+#include <dirent.h>
+
+int versionsort(const struct dirent **a, const struct dirent **b)
+{
+	return strverscmp((*a)->d_name, (*b)->d_name);
+}