]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
sys_stat: Fix namespace pollution on native Windows.
authorBruno Haible <bruno@clisp.org>
Mon, 18 Aug 2025 13:44:48 +0000 (15:44 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 18 Aug 2025 13:44:48 +0000 (15:44 +0200)
* lib/issymlink.h: New file, extracted from lib/sys_stat.in.h.
* lib/issymlink.c: Include issymlink.h instead of <sys/stat.h>.
* lib/issymlinkat.c: Likewise.
* modules/issymlink (Files): Add lib/issymlink.h.
(Depends-on): Add extern-inline.
(configure.ac): Use gl_MODULE_INDICATOR.
(Include): Set to "issymlink.h".
* modules/issymlinkat (Files): Add lib/issymlink.h.
(Depends-on): Add extern-inline.
(configure.ac): Use gl_MODULE_INDICATOR.
(Include): Set to "issymlink.h".
* lib/sys_stat.in.h: Don't include <errno.h>, <unistd.h>.
(_GL_ISSYMLINK_INLINE, _GL_ISSYMLINKAT_INLINE): Remove macros.
(issymlink, issymlinkat): Remove functions.
* m4/sys_stat_h.m4 (gl_SYS_STAT_H_REQUIRE_DEFAULTS): Don't initialize
GNULIB_ISSYMLINK, GNULIB_ISSYMLINKAT.
* modules/sys_stat-h (Depends-on): Remove extern-inline.
(Makefile.am): Don't substitute GNULIB_ISSYMLINK, GNULIB_ISSYMLINKAT.
* lib/chown.c: Include issymlink.h.
* lib/lchown.c: Likewise.
* lib/lchmod.c: Likewise.
* lib/fchmodat.c: Likewise.
* lib/rename.c: Likewise.
* lib/renameatu.c: Likewise.
* lib/unlink.c: Likewise.
* lib/unlinkat.c: Likewise.
* lib/utimens.c: Likewise.

18 files changed:
ChangeLog
lib/chown.c
lib/fchmodat.c
lib/issymlink.c
lib/issymlink.h [new file with mode: 0644]
lib/issymlinkat.c
lib/lchmod.c
lib/lchown.c
lib/rename.c
lib/renameatu.c
lib/sys_stat.in.h
lib/unlink.c
lib/unlinkat.c
lib/utimens.c
m4/sys_stat_h.m4
modules/issymlink
modules/issymlinkat
modules/sys_stat-h

index 29897dc8c5735471f0aa81f6df8b60bc0c6adfae..aba1f96a86e2b0d13d528004600b3999ffa5c632 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+2025-08-18  Bruno Haible  <bruno@clisp.org>
+
+       sys_stat: Fix namespace pollution on native Windows.
+       * lib/issymlink.h: New file, extracted from lib/sys_stat.in.h.
+       * lib/issymlink.c: Include issymlink.h instead of <sys/stat.h>.
+       * lib/issymlinkat.c: Likewise.
+       * modules/issymlink (Files): Add lib/issymlink.h.
+       (Depends-on): Add extern-inline.
+       (configure.ac): Use gl_MODULE_INDICATOR.
+       (Include): Set to "issymlink.h".
+       * modules/issymlinkat (Files): Add lib/issymlink.h.
+       (Depends-on): Add extern-inline.
+       (configure.ac): Use gl_MODULE_INDICATOR.
+       (Include): Set to "issymlink.h".
+       * lib/sys_stat.in.h: Don't include <errno.h>, <unistd.h>.
+       (_GL_ISSYMLINK_INLINE, _GL_ISSYMLINKAT_INLINE): Remove macros.
+       (issymlink, issymlinkat): Remove functions.
+       * m4/sys_stat_h.m4 (gl_SYS_STAT_H_REQUIRE_DEFAULTS): Don't initialize
+       GNULIB_ISSYMLINK, GNULIB_ISSYMLINKAT.
+       * modules/sys_stat-h (Depends-on): Remove extern-inline.
+       (Makefile.am): Don't substitute GNULIB_ISSYMLINK, GNULIB_ISSYMLINKAT.
+       * lib/chown.c: Include issymlink.h.
+       * lib/lchown.c: Likewise.
+       * lib/lchmod.c: Likewise.
+       * lib/fchmodat.c: Likewise.
+       * lib/rename.c: Likewise.
+       * lib/renameatu.c: Likewise.
+       * lib/unlink.c: Likewise.
+       * lib/unlinkat.c: Likewise.
+       * lib/utimens.c: Likewise.
+
 2025-08-15  Bruno Haible  <bruno@clisp.org>
 
        Reduce risk of compilation errors within include files.
index 97cacb82daadf8a065b0b042b99930ca4772da52..d2af041e8e64f0d6bf2c14f6a88971ab0364ac6c 100644 (file)
@@ -28,6 +28,8 @@
 #include <string.h>
 #include <sys/stat.h>
 
+#include "issymlink.h"
+
 #if !HAVE_CHOWN
 
 /* Simple stub that always fails with ENOSYS, for mingw.  */
index 57222e58eb65e802e7f76f077adc196d8cb292ff..06a20cc345fc04cfc7bee5e17c95ff594ae88603 100644 (file)
@@ -52,6 +52,8 @@ orig_fchmodat (int dir, char const *file, mode_t mode, int flags)
 
 #include <intprops.h>
 
+#include "issymlink.h"
+
 /* Invoke chmod or lchmod on FILE, using mode MODE, in the directory
    open on descriptor FD.  If possible, do it without changing the
    working directory.  Otherwise, resort to using save_cwd/fchdir,
index fba06fff647f7d7924ddb1212d44f7d475f043c0..dbf56c037c4d04ef382d1696490e944e42f9bd1a 100644 (file)
@@ -17,4 +17,4 @@
 #include <config.h>
 
 #define _GL_ISSYMLINK_INLINE _GL_EXTERN_INLINE
-#include <sys/stat.h>
+#include "issymlink.h"
diff --git a/lib/issymlink.h b/lib/issymlink.h
new file mode 100644 (file)
index 0000000..af6dc96
--- /dev/null
@@ -0,0 +1,103 @@
+/* Test whether a file is a symbolic link.
+   Copyright (C) 2025 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#ifndef _ISSYMLINK_H
+#define _ISSYMLINK_H
+
+/* This file uses _GL_ARG_NONNULL, _GL_INLINE.  */
+#if !_GL_CONFIG_H_INCLUDED
+ #error "Please include config.h first."
+#endif
+
+#include <errno.h>
+#include <unistd.h> /* for readlink, readlinkat */
+
+
+_GL_INLINE_HEADER_BEGIN
+
+#ifndef _GL_ISSYMLINK_INLINE
+# define _GL_ISSYMLINK_INLINE _GL_INLINE
+#endif
+#ifndef _GL_ISSYMLINKAT_INLINE
+# define _GL_ISSYMLINKAT_INLINE _GL_INLINE
+#endif
+
+#if GNULIB_ISSYMLINK
+/* Tests whether FILENAME represents a symbolic link.
+   This function is more reliable than lstat() / fstatat() followed by S_ISLNK,
+   because it avoids possible EOVERFLOW errors.
+   Returns
+     1                      if FILENAME is a symbolic link,
+     0                      if FILENAME exists and is not a symbolic link,
+    -1 with errno set       if determination failed, in particular
+    -1 with errno = ENOENT or ENOTDIR  if FILENAME does not exist.  */
+# ifdef __cplusplus
+extern "C" {
+# endif
+_GL_ISSYMLINK_INLINE int issymlink (const char *filename)
+     _GL_ARG_NONNULL ((1));
+_GL_ISSYMLINK_INLINE int
+issymlink (const char *filename)
+{
+  char linkbuf[1];
+  if (readlink (filename, linkbuf, sizeof (linkbuf)) >= 0)
+    return 1;
+  if (errno == EINVAL)
+    return 0;
+  else
+    return -1;
+}
+# ifdef __cplusplus
+}
+# endif
+#endif
+
+#if GNULIB_ISSYMLINKAT
+/* Tests whether FILENAME represents a symbolic link.
+   This function is more reliable than lstat() / fstatat() followed by S_ISLNK,
+   because it avoids possible EOVERFLOW errors.
+   If FILENAME is a relative file name, it is interpreted as relative to the
+   directory referred to by FD (where FD = AT_FDCWD denotes the current
+   directory).
+   Returns
+     1                      if FILENAME is a symbolic link,
+     0                      if FILENAME exists and is not a symbolic link,
+    -1 with errno set       if determination failed, in particular
+    -1 with errno = ENOENT or ENOTDIR  if FILENAME does not exist.  */
+# ifdef __cplusplus
+extern "C" {
+# endif
+_GL_ISSYMLINKAT_INLINE int issymlinkat (int fd, const char *filename)
+     _GL_ARG_NONNULL ((2));
+_GL_ISSYMLINKAT_INLINE int
+issymlinkat (int fd, const char *filename)
+{
+  char linkbuf[1];
+  if (readlinkat (fd, filename, linkbuf, sizeof (linkbuf)) >= 0)
+    return 1;
+  if (errno == EINVAL)
+    return 0;
+  else
+    return -1;
+}
+# ifdef __cplusplus
+}
+# endif
+#endif
+
+_GL_INLINE_HEADER_END
+
+#endif /* _ISSYMLINK_H */
index 924df455da376a8586269e7154ac55afe3192b71..8286356c8a210bfd0387baa7383f018986f41559 100644 (file)
@@ -17,4 +17,4 @@
 #include <config.h>
 
 #define _GL_ISSYMLINKAT_INLINE _GL_EXTERN_INLINE
-#include <sys/stat.h>
+#include "issymlink.h"
index 4c44ca806383173d45cc02c728e9a59d78edf459..deba4c50f5b3e9d72c871890e494dc916da4304d 100644 (file)
@@ -29,6 +29,7 @@
 #include <unistd.h>
 
 #include <intprops.h>
+#include "issymlink.h"
 
 /* Work like chmod, except when FILE is a symbolic link.
    In that case, on systems where permissions on symbolic links are unsupported
index e5e277101c53ad40f6faf32340912c7089e1558a..efcb23fe74a02c8bb1d7e9f5072cbe0481e5758b 100644 (file)
 
 #include <config.h>
 
+/* Specification.  */
 #include <unistd.h>
 
 #include <errno.h>
 #include <string.h>
 #include <sys/stat.h>
 
+#include "issymlink.h"
+
 #if !HAVE_LCHOWN
 
 /* If the system chown does not follow symlinks, we don't want it
index 7efd64f992e96d00b00bf82406608186dce05d9e..b365fc9b239119f2408cc92e4ac149615b53f328 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <stdio.h>
 
 #undef rename
@@ -273,6 +274,7 @@ rpl_rename (char const *src, char const *dst)
 # include <unistd.h>
 
 # include "dirname.h"
+# include "issymlink.h"
 # include "same-inode.h"
 
 /* Rename the file SRC to DST, fixing any trailing slash bugs.  */
index 64a7f5285a9bd1df40c450c2e04243be0cd1e7c6..89653cb3e85ac961a2b98a5a910b5c8b8e632d8c 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include "renameatu.h"
 
 #include <errno.h>
@@ -29,6 +30,8 @@
 # include <sys/syscall.h>
 #endif
 
+#include "issymlink.h"
+
 static int
 errno_fail (int e)
 {
index 1ffc255134b409a20c41de504464530d8c5ec609..c3c38fd653e0705eeebaea2b7b837924b24a06e7 100644 (file)
@@ -56,7 +56,7 @@
 #define _@GUARD_PREFIX@_SYS_STAT_H
 
 /* This file uses _GL_ATTRIBUTE_NODISCARD, _GL_ATTRIBUTE_NOTHROW,
-   _GL_INLINE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*.  */
+   GNULIB_POSIXCHECK, HAVE_RAW_DECL_*.  */
 #if !_GL_CONFIG_H_INCLUDED
  #error "Please include config.h first."
 #endif
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
 
-_GL_INLINE_HEADER_BEGIN
-
-#ifndef _GL_ISSYMLINK_INLINE
-# define _GL_ISSYMLINK_INLINE _GL_INLINE
-#endif
-#ifndef _GL_ISSYMLINKAT_INLINE
-# define _GL_ISSYMLINKAT_INLINE _GL_INLINE
-#endif
-
-
 /* Before doing "#define mknod rpl_mknod" below, we need to include all
    headers that may declare mknod().  OS/2 kLIBC declares mknod() in
    <unistd.h>, not in <sys/stat.h>.  */
@@ -440,13 +430,6 @@ struct stat
 #endif
 
 
-#if @GNULIB_ISSYMLINK@ || @GNULIB_ISSYMLINKAT@
-/* For the inline definitions of issymlink, issymlinkat below.  */
-# include <errno.h>
-# include <unistd.h> /* for readlink, readlinkat */
-#endif
-
-
 #if @GNULIB_CHMOD@
 # if @REPLACE_CHMOD@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -643,71 +626,6 @@ _GL_WARN_ON_USE (getumask, "getumask is not portable - "
 #endif
 
 
-#if @GNULIB_ISSYMLINK@
-/* Tests whether FILENAME represents a symbolic link.
-   This function is more reliable than lstat() / fstatat() followed by S_ISLNK,
-   because it avoids possible EOVERFLOW errors.
-   Returns
-     1                      if FILENAME is a symbolic link,
-     0                      if FILENAME exists and is not a symbolic link,
-    -1 with errno set       if determination failed, in particular
-    -1 with errno = ENOENT or ENOTDIR  if FILENAME does not exist.  */
-# ifdef __cplusplus
-extern "C" {
-# endif
-_GL_ISSYMLINK_INLINE int issymlink (const char *filename)
-     _GL_ARG_NONNULL ((1));
-_GL_ISSYMLINK_INLINE int
-issymlink (const char *filename)
-{
-  char linkbuf[1];
-  if (readlink (filename, linkbuf, sizeof (linkbuf)) >= 0)
-    return 1;
-  if (errno == EINVAL)
-    return 0;
-  else
-    return -1;
-}
-# ifdef __cplusplus
-}
-# endif
-#endif
-
-
-#if @GNULIB_ISSYMLINKAT@
-/* Tests whether FILENAME represents a symbolic link.
-   This function is more reliable than lstat() / fstatat() followed by S_ISLNK,
-   because it avoids possible EOVERFLOW errors.
-   If FILENAME is a relative file name, it is interpreted as relative to the
-   directory referred to by FD (where FD = AT_FDCWD denotes the current
-   directory).
-   Returns
-     1                      if FILENAME is a symbolic link,
-     0                      if FILENAME exists and is not a symbolic link,
-    -1 with errno set       if determination failed, in particular
-    -1 with errno = ENOENT or ENOTDIR  if FILENAME does not exist.  */
-# ifdef __cplusplus
-extern "C" {
-# endif
-_GL_ISSYMLINKAT_INLINE int issymlinkat (int fd, const char *filename)
-     _GL_ARG_NONNULL ((2));
-_GL_ISSYMLINKAT_INLINE int
-issymlinkat (int fd, const char *filename)
-{
-  char linkbuf[1];
-  if (readlinkat (fd, filename, linkbuf, sizeof (linkbuf)) >= 0)
-    return 1;
-  if (errno == EINVAL)
-    return 0;
-  else
-    return -1;
-}
-# ifdef __cplusplus
-}
-# endif
-#endif
-
-
 #if @GNULIB_LCHMOD@
 /* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
    denotes a symbolic link.  */
@@ -1089,8 +1007,6 @@ _GL_WARN_ON_USE (utimensat, "utimensat is not portable - "
 #endif
 
 
-_GL_INLINE_HEADER_END
-
 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */
 #endif /* _@GUARD_PREFIX@_SYS_STAT_H */
 #endif
index 9963ddf2928ae9745792cbc065e41b0d5b5ae1f5..ae0c7fe5dc7af3c9ec65f07906c305d8b2328702 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <unistd.h>
 
 #include <errno.h>
@@ -25,6 +26,7 @@
 #include <sys/stat.h>
 
 #include "filename.h"
+#include "issymlink.h"
 
 #undef unlink
 #if defined _WIN32 && !defined __CYGWIN__
index 847a379a91359434afaf2c5ab09a76ed56000afc..3cf5fc5ea5a70b8b74f475acc984a1f36f7868c9 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <unistd.h>
 
 #include <errno.h>
@@ -29,6 +30,7 @@
 #include <stdlib.h>
 
 #include "filename.h"
+#include "issymlink.h"
 #include "openat.h"
 
 #if HAVE_UNLINKAT
index 442a1800b98e90ffc15cf60175b618639e09331c..0387e9f10e99575861e5b31cd9dfec811fd37575 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <config.h>
 
+/* Specification.  */
 #define _GL_UTIMENS_INLINE _GL_EXTERN_INLINE
 #include "utimens.h"
 
@@ -32,6 +33,7 @@
 #include <unistd.h>
 #include <utime.h>
 
+#include "issymlink.h"
 #include "stat-time.h"
 #include "timespec.h"
 
index a2dd603d63e0536fa2f4eb827b7a38121766b855..10636923b1707364151a900c76e919bea3a70568 100644 (file)
@@ -1,5 +1,5 @@
 # sys_stat_h.m4
-# serial 43   -*- Autoconf -*-
+# serial 44   -*- Autoconf -*-
 dnl Copyright (C) 2006-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -80,8 +80,6 @@ AC_DEFUN([gl_SYS_STAT_H_REQUIRE_DEFAULTS],
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FSTATAT])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FUTIMENS])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETUMASK])
-    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISSYMLINK])
-    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ISSYMLINKAT])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LCHMOD])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_LSTAT])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MKDIR])
index d7977e89860c6b5987ec1d4e3b5fad2005ee02f4..fcb98927cd1adb7009abd8074e59ef73b9940704 100644 (file)
@@ -2,21 +2,23 @@ Description:
 Test whether a file is a symbolic link.
 
 Files:
+lib/issymlink.h
 lib/issymlink.c
 
 Depends-on:
+extern-inline
 sys_stat-h
 fcntl-h
 readlink
 
 configure.ac:
-gl_SYS_STAT_MODULE_INDICATOR([issymlink])
+gl_MODULE_INDICATOR([issymlink])
 
 Makefile.am:
 lib_SOURCES += issymlink.c
 
 Include:
-<sys/stat.h>
+"issymlink.h"
 
 License:
 LGPLv2+
index 15740ac1befc5291ba5ca0dae80ec645f10bb9a8..5833bafdfb4387c014c82d81e374e3fd8f908275 100644 (file)
@@ -2,21 +2,23 @@ Description:
 Test whether a file is a symbolic link.
 
 Files:
+lib/issymlink.h
 lib/issymlinkat.c
 
 Depends-on:
+extern-inline
 sys_stat-h
 fcntl-h
 readlinkat
 
 configure.ac:
-gl_SYS_STAT_MODULE_INDICATOR([issymlinkat])
+gl_MODULE_INDICATOR([issymlinkat])
 
 Makefile.am:
 lib_SOURCES += issymlinkat.c
 
 Include:
-<sys/stat.h>
+"issymlink.h"
 
 License:
 GPL
index 5257bad1814b71b294fb15c1912e5c84c8bee263..5552db8e0071ea3ba7cb0e49c582aeb00ed23423 100644 (file)
@@ -13,7 +13,6 @@ include_next
 snippet/arg-nonnull
 snippet/c++defs
 snippet/warn-on-use
-extern-inline
 sys_types-h
 time-h
 
@@ -43,8 +42,6 @@ sys/stat.h: sys_stat.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNU
              -e 's/@''GNULIB_FSTATAT''@/$(GNULIB_FSTATAT)/g' \
              -e 's/@''GNULIB_FUTIMENS''@/$(GNULIB_FUTIMENS)/g' \
              -e 's/@''GNULIB_GETUMASK''@/$(GNULIB_GETUMASK)/g' \
-             -e 's/@''GNULIB_ISSYMLINK''@/$(GNULIB_ISSYMLINK)/g' \
-             -e 's/@''GNULIB_ISSYMLINKAT''@/$(GNULIB_ISSYMLINKAT)/g' \
              -e 's/@''GNULIB_LCHMOD''@/$(GNULIB_LCHMOD)/g' \
              -e 's/@''GNULIB_LSTAT''@/$(GNULIB_LSTAT)/g' \
              -e 's/@''GNULIB_MKDIR''@/$(GNULIB_MKDIR)/g' \