Discussion:
euidaccess: port to native Windows
Bruno Haible
2018-03-20 07:41:25 UTC
Permalink
recutils-1.7.90, when compiled on mingw, produces this build error:

libtool: link: i686-w64-mingw32-gcc -g -O2 -o .libs/recinf.exe recutl.o recinf.o -L/usr/local/mingw32/lib ../lib/.libs/librecutils.a ../src/.libs/librec.a -lintl
../lib/.libs/librecutils.a(euidaccess.o): In function `euidaccess':
/home/bruno/recutils-1.7.90/build-mingw32/lib/../../lib/euidaccess.c:89: undefined reference to `getuid'
/home/bruno/recutils-1.7.90/build-mingw32/lib/../../lib/euidaccess.c:90: undefined reference to `getgid'
/home/bruno/recutils-1.7.90/build-mingw32/lib/../../lib/euidaccess.c:91: undefined reference to `geteuid'
/home/bruno/recutils-1.7.90/build-mingw32/lib/../../lib/euidaccess.c:92: undefined reference to `getegid'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:1771: recinf.exe] Error 1

The cause is the 'euidaccess' module from gnulib. The documentation in
doc/glibc-functions/euidaccess.texi makes it sound like this module
works on mingw and MSVC. This patch fixes it.


2018-03-20 Bruno Haible <***@clisp.org>

euidaccess: Port to native Windows.
* lib/euidaccess.c (euidaccess): On native Windows, just use _access().
* posix-modules (exclude_for_mingw): Remove 'euidaccess'.

diff --git a/lib/euidaccess.c b/lib/euidaccess.c
index aee6935..4f512f5 100644
--- a/lib/euidaccess.c
+++ b/lib/euidaccess.c
@@ -29,8 +29,11 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
-
-#include "root-uid.h"
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# include <io.h>
+#else
+# include "root-uid.h"
+#endif

#if HAVE_LIBGEN_H
# include <libgen.h>
@@ -84,7 +87,9 @@ euidaccess (const char *file, int mode)
return accessx (file, mode, ACC_SELF);
#elif HAVE_EACCESS /* FreeBSD */
return eaccess (file, mode);
-#else /* Mac OS X, NetBSD, OpenBSD, HP-UX, Solaris, Cygwin, mingw, BeOS */
+#elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* mingw */
+ return _access (file, mode);
+#else /* Mac OS X, NetBSD, OpenBSD, HP-UX, Solaris, Cygwin, BeOS */

uid_t uid = getuid ();
gid_t gid = getgid ();
diff --git a/posix-modules b/posix-modules
index 5d16d26..9315e75 100755
--- a/posix-modules
+++ b/posix-modules
@@ -227,7 +227,7 @@ exclude_for_mingw=
# <grp.h> does not exist.
exclude_for_mingw="$exclude_for_mingw pt_chown grantpt posix_openpt-tests posix_openpt"
# The functions getuid, getgid, geteuid, getegid don't exist.
-exclude_for_mingw="$exclude_for_mingw euidaccess faccessat"
+exclude_for_mingw="$exclude_for_mingw faccessat"
exclude_for_mingw="$exclude_for_mingw fchownat-tests fchownat"

# Excludes for MSVC.

Loading...