texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: * tp/Texinfo/XS/convert/converter.c (create_desti


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/XS/convert/converter.c (create_destination_directory), tp/Texinfo/XS/convert/texinfo.c (txi_general_setup), tp/Texinfo/XS/main/utils.h (S_ISDIR): use stat instead of opendir to check if a directory exists, as some implementations of opendir may not fail even if the directory does not exist. Report from Eli.
Date: Sun, 08 Dec 2024 11:38:28 -0500

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 1482a0de4b * tp/Texinfo/XS/convert/converter.c 
(create_destination_directory), tp/Texinfo/XS/convert/texinfo.c 
(txi_general_setup), tp/Texinfo/XS/main/utils.h (S_ISDIR): use stat instead of 
opendir to check if a directory exists, as some implementations of opendir may 
not fail even if the directory does not exist.  Report from Eli.
1482a0de4b is described below

commit 1482a0de4bf471b384fae893cd22b6e94a2616cb
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Dec 8 17:38:22 2024 +0100

    * tp/Texinfo/XS/convert/converter.c (create_destination_directory),
    tp/Texinfo/XS/convert/texinfo.c (txi_general_setup),
    tp/Texinfo/XS/main/utils.h (S_ISDIR): use stat instead of opendir to
    check if a directory exists, as some implementations of opendir may
    not fail even if the directory does not exist.  Report from Eli.
---
 ChangeLog                         |  8 ++++++++
 tp/Texinfo/XS/convert/converter.c | 15 +++++----------
 tp/Texinfo/XS/convert/texinfo.c   |  9 ++++-----
 tp/Texinfo/XS/main/utils.h        |  5 +++++
 4 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 806c0cb66c..3781f8f50a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-12-08  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/XS/convert/converter.c (create_destination_directory),
+       tp/Texinfo/XS/convert/texinfo.c (txi_general_setup),
+       tp/Texinfo/XS/main/utils.h (S_ISDIR): use stat instead of opendir to
+       check if a directory exists, as some implementations of opendir may
+       not fail even if the directory does not exist.  Report from Eli.
+
 2024-12-08  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/XS/convert/ConvertXS.xs,
diff --git a/tp/Texinfo/XS/convert/converter.c 
b/tp/Texinfo/XS/convert/converter.c
index 8f7ff4e61d..d134874705 100644
--- a/tp/Texinfo/XS/convert/converter.c
+++ b/tp/Texinfo/XS/convert/converter.c
@@ -24,12 +24,9 @@
 #include <inttypes.h>
 #include <unistr.h>
 #include <unictype.h>
-/* for opendir */
-#include <dirent.h>
 #include <errno.h>
-/* mkdir */
+/* mkdir stat */
 #include <sys/stat.h>
-#include <sys/types.h>
 
 #include "html_conversion_data.h"
 #include "text.h"
@@ -862,12 +859,10 @@ create_destination_directory (CONVERTER *self,
 {
   if (destination_directory_path)
     {
-      DIR *dir = opendir (destination_directory_path);
-      if (dir)
-        {
-          closedir (dir);
-        }
-      else if (errno == ENOENT)
+      struct stat finfo;
+
+      if (stat (destination_directory_path, &finfo) != 0
+          || !S_ISDIR (finfo.st_mode))
         {
           int status = mkdir (destination_directory_path, S_IRWXU
                              | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
diff --git a/tp/Texinfo/XS/convert/texinfo.c b/tp/Texinfo/XS/convert/texinfo.c
index 276090fa6f..2705a8b39f 100644
--- a/tp/Texinfo/XS/convert/texinfo.c
+++ b/tp/Texinfo/XS/convert/texinfo.c
@@ -26,7 +26,7 @@
 #include <stddef.h>
 #include <string.h>
 #include <stdio.h>
-#include <dirent.h>
+#include <sys/stat.h>
 
 #include "document_types.h"
 #include "option_types.h"
@@ -57,13 +57,12 @@ txi_general_setup (int texinfo_uninstalled, const char 
*converterdatadir,
   /* code in texinfo.pl */
   if (texinfo_uninstalled)
     {
-      DIR *dir;
+      struct stat finfo;
 
       xasprintf (&locales_dir, "%s/LocaleData", tp_builddir);
-      dir = opendir (locales_dir);
-      if (dir)
+
+      if (stat (locales_dir, &finfo) == 0 && S_ISDIR (finfo.st_mode))
         {
-          closedir (dir);
           configure_output_strings_translations (locales_dir, 0, -1);
         }
       else
diff --git a/tp/Texinfo/XS/main/utils.h b/tp/Texinfo/XS/main/utils.h
index be35e9fe2a..915d0af7b3 100644
--- a/tp/Texinfo/XS/main/utils.h
+++ b/tp/Texinfo/XS/main/utils.h
@@ -35,6 +35,11 @@
    C structure */
 #define pgdt_context_noop(Context,String) String, Context
 
+/* portability definition for platforms that may lack S_ISDIR */
+#if !defined (S_ISDIR) && defined (S_IFDIR)
+#  define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#endif /* !S_ISDIR && S_IFDIR */
+
 extern const char *null_device_names[];
 
 extern const char *whitespace_chars;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]