diff --git a/src/drivers/X11/Fl_X11_System_Driver.cxx b/src/drivers/X11/Fl_X11_System_Driver.cxx index 88fa416f5..801189b44 100644 --- a/src/drivers/X11/Fl_X11_System_Driver.cxx +++ b/src/drivers/X11/Fl_X11_System_Driver.cxx @@ -481,8 +481,8 @@ int Fl_X11_System_Driver::filename_list(const char *d, fl_utf8to_mb(d, dirlen, dirloc, dirlen + 1); #ifndef HAVE_SCANDIR - // This version is when we define our own scandir - int n = fl_scandir(dirloc, list, 0, sort); + // This version is when we define our own scandir. Note it updates errmsg on errors. + int n = fl_scandir(dirloc, list, 0, sort, errmsg, errmsg_sz); #elif defined(HAVE_SCANDIR_POSIX) // POSIX (2008) defines the comparison function like this: int n = scandir(dirloc, list, 0, (int(*)(const dirent **, const dirent **))sort); @@ -504,7 +504,11 @@ int Fl_X11_System_Driver::filename_list(const char *d, free(dirloc); if (n==-1) { + // Don't write to errmsg if FLTK's fl_scandir() already set it. + // If OS's scandir() was used (HAVE_SCANDIR), we return its error in errmsg here.. +#ifdef HAVE_SCANDIR if (errmsg) fl_snprintf(errmsg, errmsg_sz, "%s", strerror(errno)); +#endif return -1; } diff --git a/src/scandir_posix.c b/src/scandir_posix.c index 9d8396619..e83a12009 100644 --- a/src/scandir_posix.c +++ b/src/scandir_posix.c @@ -48,6 +48,7 @@ #include /* For 'offsetof()', 'NULL' and 'size_t' */ #include /* For 'INT_MAX' */ #include /* For 'memcpy()' */ +#include "flstring.h" /* For 'fl_snprintf()' */ #if defined(HAVE_PTHREAD) && defined(HAVE_PTHREAD_H) # include #endif /* HAVE_PTHREAD */ @@ -137,7 +138,7 @@ int fl_scandir(const char *dir, struct dirent ***namelist, int (*sel)(struct dirent *), int (*compar)(struct dirent **, struct dirent **), - char *errmsg, int errmsg_sz) { + char *errmsg, int errmsg_sz) { int result = -1; DIR *dirp;