summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-02-28 17:53:51 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-02-28 17:53:51 +0100
commit4567042b5145b097c962499f26511aa5106f0e60 (patch)
tree57268aa9c2d7b455eeecd5e92b5ec58b7c7a3cc6 /src
parentb251f26261309c933a43c863f81227219a9e8355 (diff)
Add Makefile flag to disable version sorting on C libraries without strverscmp
Diffstat (limited to 'src')
-rw-r--r--src/feh.h7
-rw-r--r--src/filelist.c29
2 files changed, 22 insertions, 14 deletions
diff --git a/src/feh.h b/src/feh.h
index 4e7a3ff..3e0cdda 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -27,7 +27,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef FEH_H
#define FEH_H
+/*
+ * strverscmp(3) is a GNU extension. In most supporting C libraries it
+ * requires _GNU_SOURCE to be defined.
+ */
+#ifdef HAVE_VERSCMP
#define _GNU_SOURCE
+#endif
+
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
diff --git a/src/filelist.c b/src/filelist.c
index 159491a..453f795 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -397,20 +397,26 @@ void feh_file_dirname(char *dst, feh_file * f, int maxlen)
dst[n] = '\0';
}
-int feh_cmp_filename(void *file1, void *file2)
+#ifdef HAVE_VERSCMP
+inline int strcmp_or_strverscmp(const char *s1, const char *s2)
{
if (!opt.version_sort)
- return(strcmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
+ return(strcmp(s1, s2));
else
- return(strverscmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
+ return(strverscmp(s1, s2));
+}
+#else
+#define strcmp_or_strverscmp strcmp
+#endif
+
+int feh_cmp_filename(void *file1, void *file2)
+{
+ return(strcmp_or_strverscmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
}
int feh_cmp_name(void *file1, void *file2)
{
- if (!opt.version_sort)
- return(strcmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
- else
- return(strverscmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
+ return(strcmp_or_strverscmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
}
int feh_cmp_dirname(void *file1, void *file2)
@@ -419,13 +425,8 @@ int feh_cmp_dirname(void *file1, void *file2)
int cmp;
feh_file_dirname(dir1, FEH_FILE(file1), PATH_MAX);
feh_file_dirname(dir2, FEH_FILE(file2), PATH_MAX);
- if (!opt.version_sort) {
- if ((cmp = strcmp(dir1, dir2)) != 0)
- return(cmp);
- } else {
- if ((cmp = strverscmp(dir1, dir2)) != 0)
- return(cmp);
- }
+ if ((cmp = strcmp_or_strverscmp(dir1, dir2)) != 0)
+ return(cmp);
return(feh_cmp_name(file1, file2));
}