On Sat, Jan 17, 2026 at 05:50:44PM +0100, [email protected] wrote:
> On Sat, Jan 17, 2026 at 01:43:52PM +0200, Eli Zaretskii wrote:
> > What is 'glob' used for?
> 
>   xasprintf (&glob_format, "%s/*.cnf", cnf_dir);
> 
>   glob_status = glob (glob_format, 0, 0, &possible_files);
> 
> >  Perhaps it would be possible to write native
> > Windows code to achieve the same, since Windows APIs for finding files
> > by their wildcards do exist.  As long as the code doesn't need any
> > 'glob'-specific features and doesn't use Unix-style wildcards like
> > "*.[ch]", replacing it with Windows native code shouldn't be
> > difficult.
> 
> Given that the use is basic, it should be possible.  But I think that
> using the Gnulib version is the least demanding in term of code, need
> for specific testing, which is why it has my favor.

Here's a patch to use opendir/readdir instead.  I don't think it is
much harder to understand than the code using glob.  (I have tested it,
although there is always a chance there is a bug in my code.)

According to the Gnulib manual, opendir and readdir are only missing on
MSVC 14, which we don't support anyway.

diff --git a/tta/C/convert/html_prepare_converter.c 
b/tta/C/convert/html_prepare_converter.c
index 89adde68de..34112a02fb 100644
--- a/tta/C/convert/html_prepare_converter.c
+++ b/tta/C/convert/html_prepare_converter.c
@@ -22,7 +22,7 @@
 #include <errno.h>
 #include <inttypes.h>
 #include <sys/stat.h>
-#include <glob.h>
+#include <dirent.h>
 /* for euidaccess.  Not portable, use gnulib */
 #include <unistd.h>
 
@@ -1421,30 +1421,39 @@ load_htmlxref_files (CONVERTER *self)
 
                   if (stat (cnf_dir, &finfo) == 0 && S_ISDIR (finfo.st_mode))
                     {
-                      int file_found = 0;
-                      glob_t possible_files;
-                      int glob_status;
-                      char *glob_format;
-
-                      xasprintf (&glob_format, "%s/*.cnf", cnf_dir);
-
-                      glob_status = glob (glob_format, 0, 0, &possible_files);
-
-                      if (!glob_status)
+                      DIR *dir = opendir (cnf_dir);
+                      char *possible_file;
+                      if (dir)
                         {
-                          size_t j;
+                          int file_found = 0;
 
-                          for (j = 0; j < possible_files.gl_pathc; j++)
+                          struct dirent *entry;
+                          while ((entry = readdir (dir)))
                             {
-                              if (possible_files.gl_pathv[j]
-                                  && euidaccess (possible_files.gl_pathv[j],
-                                                 R_OK) == 0)
+#ifdef _DIRENT_HAVE_DTYPE
+                              if (entry->d_type != S_REG
+                                  && entry->d_type != S_UNKNOWN)
+                                continue;
+#endif
+
+                              size_t len = strlen (entry->d_name);
+                              if (len >= 4
+                                  && !memcmp (&entry->d_name[len - 4],
+                                              ".cnf", 4))
                                 {
-                                  add_string (possible_files.gl_pathv[j],
-                                              &htmlxref_files);
-                                  file_found = 1;
+                                  xasprintf (&possible_file, "%s/%s",
+                                             cnf_dir, entry->d_name);
+                                  if (euidaccess (possible_file, R_OK) == 0)
+                                    {
+                                      add_string (possible_file,
+                                                  &htmlxref_files);
+                                      file_found = 1;
+                                    }
+                                  free (possible_file);
                                 }
                             }
+                          (void) closedir (dir);
+
                           if (!deprecated_dir_set && file_found
                               && deprecated_dirs)
                             {
@@ -1457,8 +1466,6 @@ load_htmlxref_files (CONVERTER *self)
                               deprecated_dir_set = 1;
                             }
                         }
-                      globfree (&possible_files);
-                      free (glob_format);
                     }
                   free (cnf_dir);
                 }





Since it's easy not to use 'glob' (as far as I can tell), and we only
use 'glob' in one place, it's a strong argument for not using it.
It's also easy to remove this module now, while it may not be so easy
in the future as people will have forgotten that it isn't needed.

The main advantage is in saving the time taken to run "configure",
although reduced code size and reducing the chance for something
to go wrong later are also advantages.

$ git show 1a5348c9282eda0bfb219a39510b33711d6c56f9 | fgrep "+## begin gnulib 
module"
+## begin gnulib module alloca
+## begin gnulib module assure
+## begin gnulib module at-internal
+## begin gnulib module basename-lgpl
+## begin gnulib module btoc32
+## begin gnulib module btowc
+## begin gnulib module c32_apply_type_test
+## begin gnulib module c32_get_type_test
+## begin gnulib module chdir-long
+## begin gnulib module cloexec
+## begin gnulib module closedir
+## begin gnulib module ctype-h
+## begin gnulib module dirent-h
+## begin gnulib module dirfd
+## begin gnulib module error
+## begin gnulib module error-h
+## begin gnulib module exitfail
+## begin gnulib module fchdir
+## begin gnulib module filenamecat-lgpl
+## begin gnulib module flexmember
+## begin gnulib module fnmatch
+## begin gnulib module fnmatch-h
+## begin gnulib module fstat
+## begin gnulib module fstatat
+## begin gnulib module getcwd-lgpl
+## begin gnulib module getlogin_r
+## begin gnulib module getprogname
+## begin gnulib module glibc-internal/scratch_buffer
+## begin gnulib module glob
+## begin gnulib module glob-h
+## begin gnulib module intprops
+## begin gnulib module isblank
+## begin gnulib module iswctype
+## begin gnulib module libc-config
+## begin gnulib module lstat
+## begin gnulib module mbsrtoc32s
+## begin gnulib module mbsrtowcs
+## begin gnulib module mbtowc
+## begin gnulib module mempcpy
+## begin gnulib module memrchr
+## begin gnulib module open
+## begin gnulib module openat
+## begin gnulib module openat-die
+## begin gnulib module openat-h
+## begin gnulib module opendir
+## begin gnulib module readdir
+## begin gnulib module realloc-posix
+## begin gnulib module save-cwd
+## begin gnulib module strdup-posix
+## begin gnulib module strerror
+## begin gnulib module strerror-override
+## begin gnulib module strnlen1
+## begin gnulib module unistr/u32-chr
+## begin gnulib module unistr/u32-cpy
+## begin gnulib module unistr/u32-pcpy
+## begin gnulib module unistr/u32-strcat
+## begin gnulib module unistr/u32-strlen
+## begin gnulib module verify
+## begin gnulib module wctype
+## begin gnulib module wmemchr
+## begin gnulib module wmempcpy


  • texi... Gavin Smith
    • ... Bruno Haible via Bug reports for the GNU Texinfo documentation system
      • ... Eli Zaretskii
        • ... Bruno Haible via Bug reports for the GNU Texinfo documentation system
          • ... Eli Zaretskii
      • ... Patrice Dumas
        • ... Gavin Smith
          • ... Gavin Smith
            • ... Eli Zaretskii
              • ... pertusus
                • ... Gavin Smith
                • ... pertusus
            • ... Bruno Haible via Bug reports for the GNU Texinfo documentation system
              • ... Gavin Smith
                • ... Patrice Dumas
                • ... Bruno Haible via Bug reports for the GNU Texinfo documentation system
                • ... Gavin Smith
                • ... Bruno Haible via Bug reports for the GNU Texinfo documentation system
                • ... Gavin Smith
                • ... Bruno Haible via Bug reports for the GNU Texinfo documentation system
                • ... Gavin Smith

Reply via email to