+2019-10-06 Bruno Haible <bruno@clisp.org>
+
+ access tests: Fix test failure when run as root.
+ * tests/test-access.c: Include root-uid.h.
+ (geteuid): Define fallback.
+ (main): Don't expect that writing to a read-only file would fail when
+ running as root. Also, remove the created files at the end.
+ * modules/access-tests (Depends-on): Add root-uid.
+ (configure.ac): Test whether geteuid exists.
+
2019-10-06 Benno Schulenberg <bensberg@telfort.nl> (tiny change)
users.txt: add GNU nano
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include "root-uid.h"
#include "macros.h"
+/* mingw and MSVC 9 lack geteuid, so setup a dummy value. */
+#if !HAVE_GETEUID
+# define geteuid() ROOT_UID
+#endif
+
#define BASE "test-access.t"
int
ASSERT (access (BASE "f2", R_OK) == 0);
- errno = 0;
- ASSERT (access (BASE "f2", W_OK) == -1);
- ASSERT (errno == EACCES);
+ if (geteuid () != ROOT_UID)
+ {
+ errno = 0;
+ ASSERT (access (BASE "f2", W_OK) == -1);
+ ASSERT (errno == EACCES);
+ }
#if defined _WIN32 && !defined __CYGWIN__
/* X_OK works like R_OK. */
#endif
}
+ /* Cleanup. */
+ unlink (BASE "f1");
+ unlink (BASE "f2");
+
return 0;
}