| 1 |
# chmod.m4 serial 2 |
| 2 |
dnl Copyright (C) 2004-2023 Free Software Foundation, Inc. |
| 3 |
dnl This file is free software; the Free Software Foundation |
| 4 |
dnl gives unlimited permission to copy and/or distribute it, |
| 5 |
dnl with or without modifications, as long as this notice is preserved. |
| 6 |
|
| 7 |
dnl From Bruno Haible. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_CHMOD], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 13 |
AC_CACHE_CHECK([whether chmod works], |
| 14 |
[gl_cv_func_chmod_works], |
| 15 |
[AC_RUN_IFELSE( |
| 16 |
[AC_LANG_PROGRAM( |
| 17 |
[ |
| 18 |
AC_INCLUDES_DEFAULT[ |
| 19 |
#if defined _WIN32 && !defined __CYGWIN__ |
| 20 |
#include <io.h> |
| 21 |
#endif |
| 22 |
#include <errno.h> |
| 23 |
#include <fcntl.h> |
| 24 |
#ifndef S_IRUSR |
| 25 |
#define S_IRUSR 0400 |
| 26 |
#endif |
| 27 |
#ifndef S_IWUSR |
| 28 |
#define S_IWUSR 0200 |
| 29 |
#endif |
| 30 |
#ifndef S_IRWXU |
| 31 |
#define S_IRWXU 0700 |
| 32 |
#endif |
| 33 |
#ifndef S_IRWXG |
| 34 |
#define S_IRWXG 0070 |
| 35 |
#endif |
| 36 |
#ifndef S_IRWXO |
| 37 |
#define S_IRWXO 0007 |
| 38 |
#endif |
| 39 |
]GL_MDA_DEFINES], |
| 40 |
[[ |
| 41 |
int permissive = S_IRWXU | S_IRWXG | S_IRWXO; |
| 42 |
int desired = S_IRUSR | S_IWUSR; |
| 43 |
int result = 0; |
| 44 |
#define file "conftest.chmod" |
| 45 |
if (open (file, O_CREAT | O_WRONLY | O_TRUNC, permissive) < 0) |
| 46 |
return 1; |
| 47 |
/* Test whether chmod rejects a trailing slash on a non-directory, |
| 48 |
with error ENOTDIR. |
| 49 |
This test fails on AIX 7.2, IRIX 6.5 (no error) and |
| 50 |
native Windows (error EINVAL). */ |
| 51 |
errno = 0; |
| 52 |
if (chmod (file "/", desired) == 0) |
| 53 |
result |= 2; |
| 54 |
else if (errno != ENOTDIR) |
| 55 |
result |= 4; |
| 56 |
return result; |
| 57 |
]])], |
| 58 |
[gl_cv_func_chmod_works=yes], |
| 59 |
[gl_cv_func_chmod_works=no], |
| 60 |
[case "$host_os" in |
| 61 |
# Guess no on AIX, IRIX, native Windows. |
| 62 |
aix* | irix* | mingw*) |
| 63 |
gl_cv_func_chmod_works="guessing no" ;; |
| 64 |
# Guess yes on glibc, musl libc, macOS, FreeBSD, NetBSD, OpenBSD, Solaris, Haiku, Cygwin. |
| 65 |
*-gnu* | gnu* | *-musl* | darwin* | freebsd* | midnightbsd* | netbsd* | openbsd* | solaris* | haiku* | cygwin*) |
| 66 |
gl_cv_func_chmod_works="guessing yes" ;; |
| 67 |
# Guess yes on systems that emulate the Linux system calls. |
| 68 |
midipix*) |
| 69 |
gl_cv_func_chmod_works="guessing yes" ;; |
| 70 |
# If we don't know, obey --enable-cross-guesses. |
| 71 |
*) |
| 72 |
gl_cv_func_chmod_works="$gl_cross_guess_normal" ;; |
| 73 |
esac |
| 74 |
]) |
| 75 |
rm -f conftest.chmod |
| 76 |
]) |
| 77 |
case "$gl_cv_func_chmod_works" in |
| 78 |
*yes) ;; |
| 79 |
*) REPLACE_CHMOD=1 ;; |
| 80 |
esac |
| 81 |
]) |
| 82 |
|
| 83 |
# Prerequisites of lib/chmod.c. |
| 84 |
AC_DEFUN([gl_PREREQ_CHMOD], |
| 85 |
[ |
| 86 |
: |
| 87 |
]) |