summaryrefslogtreecommitdiff
path: root/lib/fcntl.in.h
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-12-06 16:43:36 +0100
committerBruno Haible <bruno@clisp.org>2020-12-06 16:43:36 +0100
commit5b6ea85121af42b78348d8b396f84b281aa4998a (patch)
tree1b00bc4f24142e7377576c1176b10437523c7d48 /lib/fcntl.in.h
parent5af457737fb72ec05544a3336ce4b867b744b4d2 (diff)
downloadgnulib-5b6ea85121af42b78348d8b396f84b281aa4998a.tar.gz
Do the Windows oldnames workaround through the C++ GNULIB_NAMESPACE.
Reported by Daniel R. Hurtmans <Daniel.Hurtmans@ulb.ac.be> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00029.html>. * lib/c++defs.h (_GL_CXXALIAS_MDA_CAST): New macro. * lib/fcntl.in.h (creat, open): In C++ mode, when GNULIB_NAMESPACE is defined: 1. Define a symbol in this namespace. 2. Don't redirect using a preprocessor #define. * lib/math.in.h (j0, j1, jn, y0, y1, yn): Likewise. * lib/search.in.h (lfind, lsearch): Likewise. * lib/stdio.in.h (fcloseall, fdopen, fileno, getw, putw, tempnam): Likewise. * lib/stdlib.in.h (ecvt, fcvt, gcvt, mktemp, putenv): Likewise. * lib/string.in.h (memccpy, strdup): Likewise. * lib/sys_stat.in.h (chmod, umask): Likewise. * lib/time.in.h (tzset): Likewise. * lib/unistd.in.h (access, chdir, close, dup, dup2, execl, execle, execlp, execv, execve, execvp, execvpe, getcwd, getpid, isatty, lseek, read, rmdir, swab, unlink, write): Likewise. * lib/utime.in.h (utime): Likewise. * lib/wchar.in.h (wcsdup): Likewise. * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Initialize HAVE_DECL_FCLOSEALL. (gl_STDIO_H): Set HAVE_DECL_FCLOSEALL. * modules/stdio (Makefile.am): Substitute HAVE_DECL_FCLOSEALL. * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize HAVE_DECL_ECVT, HAVE_DECL_FCVT, HAVE_DECL_GCVT. (gl_STDLIB_H): Set HAVE_DECL_ECVT, HAVE_DECL_FCVT, HAVE_DECL_GCVT. * modules/stdlib (Makefile.am): Substitute HAVE_DECL_ECVT, HAVE_DECL_FCVT, HAVE_DECL_GCVT. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize HAVE_DECL_EXECVPE. (gl_UNISTD_H): Set HAVE_DECL_EXECVPE. * modules/unistd (Makefile.am): Substitute HAVE_DECL_EXECVPE. * m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize HAVE_DECL_WCSDUP. (gl_WCHAR_H): Set HAVE_DECL_WCSDUP. * modules/wchar (Makefile.am): Substitute HAVE_DECL_WCSDUP.
Diffstat (limited to 'lib/fcntl.in.h')
-rw-r--r--lib/fcntl.in.h37
1 files changed, 31 insertions, 6 deletions
diff --git a/lib/fcntl.in.h b/lib/fcntl.in.h
index 6f16bc6692..11c9aae9bc 100644
--- a/lib/fcntl.in.h
+++ b/lib/fcntl.in.h
@@ -112,9 +112,21 @@ _GL_CXXALIASWARN (creat);
/* Assume creat is always declared. */
_GL_WARN_ON_USE (creat, "creat is not always POSIX compliant - "
"use gnulib module creat for portability");
-#elif defined _WIN32 && !defined __CYGWIN__
-# undef creat
-# define creat _creat
+#else
+/* On native Windows, map 'creat' to '_creat', so that -loldnames is not
+ required. In C++ with GNULIB_NAMESPACE, avoid differences between
+ platforms by defining GNULIB_NAMESPACE::creat always. */
+# if defined _WIN32 && !defined __CYGWIN__
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef creat
+# define creat _creat
+# endif
+/* Need to cast, because in mingw the last argument is 'int mode'. */
+_GL_CXXALIAS_MDA_CAST (creat, int, (const char *filename, mode_t mode));
+# else
+_GL_CXXALIAS_SYS (creat, int, (const char *filename, mode_t mode));
+# endif
+_GL_CXXALIASWARN (creat);
#endif
#if @GNULIB_FCNTL@
@@ -174,9 +186,22 @@ _GL_CXXALIASWARN (open);
/* Assume open is always declared. */
_GL_WARN_ON_USE (open, "open is not always POSIX compliant - "
"use gnulib module open for portability");
-#elif defined _WIN32 && !defined __CYGWIN__
-# undef open
-# define open _open
+#else
+/* On native Windows, map 'open' to '_open', so that -loldnames is not
+ required. In C++ with GNULIB_NAMESPACE, avoid differences between
+ platforms by defining GNULIB_NAMESPACE::open always. */
+# if defined _WIN32 && !defined __CYGWIN__
+# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+# undef open
+# define open _open
+# endif
+_GL_CXXALIAS_MDA (open, int, (const char *filename, int flags, ...));
+# else
+_GL_CXXALIAS_SYS (open, int, (const char *filename, int flags, ...));
+# endif
+# if !defined __hpux
+_GL_CXXALIASWARN (open);
+# endif
#endif
#if @GNULIB_OPENAT@