FLTK logo

[master] a41d8c0 - Fix issue #162

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] a41d8c0 - Fix issue #162 "Greg Ercolano" Nov 22, 2020  
 
commit a41d8c0e60b6964b416c025a56d7568e83ae70da
Author:     Greg Ercolano <erco@seriss.com>
AuthorDate: Sun Nov 22 18:18:02 2020 -0800
Commit:     Greg Ercolano <erco@seriss.com>
CommitDate: Sun Nov 22 18:18:02 2020 -0800

    Fix issue #162

 src/drivers/X11/Fl_X11_System_Driver.cxx | 8 ++++++--
 src/scandir_posix.c                      | 3 ++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git src/drivers/X11/Fl_X11_System_Driver.cxx src/drivers/X11/Fl_X11_System_Driver.cxx
index 88fa416..801189b 100644
--- src/drivers/X11/Fl_X11_System_Driver.cxx
+++ 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 src/scandir_posix.c src/scandir_posix.c
index 9d83966..e83a120 100644
--- src/scandir_posix.c
+++ src/scandir_posix.c
@@ -48,6 +48,7 @@
 #include <stddef.h>           /* For 'offsetof()', 'NULL' and 'size_t' */
 #include <limits.h>           /* For 'INT_MAX' */
 #include <string.h>           /* For 'memcpy()' */
+#include "flstring.h"         /* For 'fl_snprintf()' */
 #if defined(HAVE_PTHREAD) && defined(HAVE_PTHREAD_H)
 #  include <pthread.h>
 #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;
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.