aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2012-10-19 09:52:02 -0700
committerPaul Eggert2012-10-19 09:52:02 -0700
commite752e0b0a2622d8d0ba518bf81f6fa652d926e67 (patch)
tree3b7cfbf8aa3ecaa587cd6fbc2d17b64d055d2b07
parent6ec83f926d5ff699901fb530162d7f1bdfa85808 (diff)
downloademacs-e752e0b0a2622d8d0ba518bf81f6fa652d926e67.tar.gz
emacs-e752e0b0a2622d8d0ba518bf81f6fa652d926e67.zip
Use faccessat, not access, when checking file permissions.
* .bzrignore: Add lib/fcntl.h. * configure.ac (euidaccess): Remove check; gnulib does this for us now. (gl_FCNTL_O_FLAGS): Define a dummy version. * lib/at-func.c, lib/euidaccess.c, lib/faccessat.c, lib/fcntl.in.h: * lib/getgroups.c, lib/group-member.c, lib/root-uid.h: * lib/xalloc-oversized.h, m4/euidaccess.m4, m4/faccessat.m4: * m4/fcntl_h.m4, m4/getgroups.m4, m4/group-member.m4: New files, from gnulib. * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. * admin/merge-gnulib (GNULIB_MODULES): Add faccessat. (GNULIB_TOOL_FLAGS): Avoid at-internal, fchdir, malloc-posix, openat-die, openat-h, save-cwd. Do not avoid fcntl-h. Omit gnulib's m4/fcntl-o.m4. * nt/inc/ms-w32.h (AT_FDCWD, AT_EACCESS): New symbols. (access): Remove. (faccessat): New macro. * src/Makefile.in (LIB_EACCESS): New macro. (LIBES): Use it. * src/callproc.c (init_callproc): * src/charset.c (init_charset): * src/fileio.c (check_existing, check_executable): * src/lread.c (openp, load_path_check): * src/process.c (allocate_pty): * src/xrdb.c (file_p): Use faccessat, not access or euidaccess. Use symbolic names instead of integers for the flags, as they're portable now. * src/charset.c, src/xrdb.c: Include <fcntl.h>, for the new flags used. * src/fileio.c (Ffile_readable_p): Use faccessat, not stat + open + close. (file_directory_p): New function, which uses 'stat' on most places but 'access' (for efficiency) if WINDOWSNT. * src/fileio.c (Ffile_directory_p, Fset_file_times): * src/xrdb.c (file_p): Use file_directory_p. * src/lisp.h (file_directory_p): New decl. * src/lread.c (openp): When opening a file, use fstat rather than stat, as that avoids a permissions race. When not opening a file, use file_directory_p rather than stat. * src/process.c, src/sysdep.c, src/term.c: All uses of '#ifdef O_NONBLOCK' changed to '#if O_NONBLOCK', to accommodate gnulib O_* tyle. * src/w32.c (sys_faccessat): Rename from sys_access and switch to faccessat's API. All uses changed. Fixes: debbugs:12632
-rw-r--r--ChangeLog13
-rw-r--r--admin/ChangeLog8
-rwxr-xr-xadmin/merge-gnulib13
-rw-r--r--configure.ac4
-rw-r--r--lib/gnulib.mk97
-rw-r--r--m4/gnulib-comp.m4105
-rw-r--r--nt/ChangeLog7
-rw-r--r--nt/inc/ms-w32.h7
-rw-r--r--src/ChangeLog29
-rw-r--r--src/Makefile.in3
-rw-r--r--src/callproc.c4
-rw-r--r--src/charset.c3
-rw-r--r--src/conf_post.h4
-rw-r--r--src/fileio.c97
-rw-r--r--src/lisp.h1
-rw-r--r--src/lread.c56
-rw-r--r--src/process.c36
-rw-r--r--src/sysdep.c6
-rw-r--r--src/term.c4
-rw-r--r--src/w32.c18
-rw-r--r--src/xrdb.c8
21 files changed, 377 insertions, 146 deletions
diff --git a/ChangeLog b/ChangeLog
index 81eddade0a0..c7fcd319af2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
12012-10-19 Paul Eggert <eggert@cs.ucla.edu>
2
3 Use faccessat, not access, when checking file permissions (Bug#12632).
4 * .bzrignore: Add lib/fcntl.h.
5 * configure.ac (euidaccess): Remove check; gnulib does this for us now.
6 (gl_FCNTL_O_FLAGS): Define a dummy version.
7 * lib/at-func.c, lib/euidaccess.c, lib/faccessat.c, lib/fcntl.in.h:
8 * lib/getgroups.c, lib/group-member.c, lib/root-uid.h:
9 * lib/xalloc-oversized.h, m4/euidaccess.m4, m4/faccessat.m4:
10 * m4/fcntl_h.m4, m4/getgroups.m4, m4/group-member.m4:
11 New files, from gnulib.
12 * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate.
13
12012-10-18 Stefan Monnier <monnier@iro.umontreal.ca> 142012-10-18 Stefan Monnier <monnier@iro.umontreal.ca>
2 15
3 * Makefile.in ($(MAKEFILE_NAME)): Depend on src/lisp.mk as well. 16 * Makefile.in ($(MAKEFILE_NAME)): Depend on src/lisp.mk as well.
diff --git a/admin/ChangeLog b/admin/ChangeLog
index e21293d618d..6d08bf7c37e 100644
--- a/admin/ChangeLog
+++ b/admin/ChangeLog
@@ -1,3 +1,11 @@
12012-10-19 Paul Eggert <eggert@cs.ucla.edu>
2
3 Use faccessat, not access, when checking file permissions (Bug#12632).
4 * merge-gnulib (GNULIB_MODULES): Add faccessat.
5 (GNULIB_TOOL_FLAGS): Avoid at-internal, fchdir, malloc-posix,
6 openat-die, openat-h, save-cwd. Do not avoid fcntl-h.
7 Omit gnulib's m4/fcntl-o.m4.
8
12012-10-12 Kenichi Handa <handa@gnu.org> 92012-10-12 Kenichi Handa <handa@gnu.org>
2 10
3 * charsets/Makefile (JISC6226.map): Add missing mappings. 11 * charsets/Makefile (JISC6226.map): Add missing mappings.
diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index 7fc0b5f4844..3c4d8e8058d 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -28,7 +28,7 @@ GNULIB_URL=git://git.savannah.gnu.org/gnulib.git
28GNULIB_MODULES=' 28GNULIB_MODULES='
29 alloca-opt c-ctype c-strcase 29 alloca-opt c-ctype c-strcase
30 careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 30 careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512
31 dtoastr dtotimespec dup2 environ execinfo 31 dtoastr dtotimespec dup2 environ execinfo faccessat
32 filemode getloadavg getopt-gnu gettime gettimeofday 32 filemode getloadavg getopt-gnu gettime gettimeofday
33 ignore-value intprops largefile lstat 33 ignore-value intprops largefile lstat
34 manywarnings mktime pselect pthread_sigmask readlink 34 manywarnings mktime pselect pthread_sigmask readlink
@@ -39,9 +39,12 @@ GNULIB_MODULES='
39' 39'
40 40
41GNULIB_TOOL_FLAGS=' 41GNULIB_TOOL_FLAGS='
42 --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat 42 --avoid=at-internal
43 --avoid=msvc-inval --avoid=msvc-nothrow 43 --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat
44 --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types 44 --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow
45 --avoid=openat-die --avoid=openat-h
46 --avoid=raise
47 --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types
45 --avoid=threadlib 48 --avoid=threadlib
46 --conditional-dependencies --import --no-changelog --no-vc-files 49 --conditional-dependencies --import --no-changelog --no-vc-files
47 --makefile-name=gnulib.mk 50 --makefile-name=gnulib.mk
@@ -85,7 +88,7 @@ test -x "$gnulib_srcdir"/gnulib-tool || {
85} 88}
86 89
87"$gnulib_srcdir"/gnulib-tool --dir="$src" $GNULIB_TOOL_FLAGS $GNULIB_MODULES && 90"$gnulib_srcdir"/gnulib-tool --dir="$src" $GNULIB_TOOL_FLAGS $GNULIB_MODULES &&
88rm -- "$src"m4/gnulib-cache.m4 "$src"m4/warn-on-use.m4 && 91rm -- "$src"m4/fcntl-o.m4 "$src"m4/gnulib-cache.m4 "$src"m4/warn-on-use.m4 &&
89cp -- "$gnulib_srcdir"/build-aux/texinfo.tex "$src"doc/misc && 92cp -- "$gnulib_srcdir"/build-aux/texinfo.tex "$src"doc/misc &&
90cp -- "$gnulib_srcdir"/build-aux/move-if-change "$src"build-aux && 93cp -- "$gnulib_srcdir"/build-aux/move-if-change "$src"build-aux &&
91autoreconf -i -I m4 -- ${src:+"$src"} 94autoreconf -i -I m4 -- ${src:+"$src"}
diff --git a/configure.ac b/configure.ac
index 5520dd6a903..6b4c757ced5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -572,6 +572,8 @@ else
572 test "x$NON_GCC_TEST_OPTIONS" != x && CC="$CC $NON_GCC_TEST_OPTIONS" 572 test "x$NON_GCC_TEST_OPTIONS" != x && CC="$CC $NON_GCC_TEST_OPTIONS"
573fi 573fi
574 574
575# Avoid gnulib's tests for O_NOATIME and O_NOFOLLOW, as we don't use them.
576AC_DEFUN([gl_FCNTL_O_FLAGS])
575# Avoid gnulib's threadlib module, as we do threads our own way. 577# Avoid gnulib's threadlib module, as we do threads our own way.
576AC_DEFUN([gl_THREADLIB]) 578AC_DEFUN([gl_THREADLIB])
577 579
@@ -2872,7 +2874,7 @@ AC_SUBST(BLESSMAIL_TARGET)
2872AC_CHECK_FUNCS(gethostname \ 2874AC_CHECK_FUNCS(gethostname \
2873closedir getrusage get_current_dir_name \ 2875closedir getrusage get_current_dir_name \
2874lrand48 setsid \ 2876lrand48 setsid \
2875fpathconf select euidaccess getpagesize setlocale \ 2877fpathconf select getpagesize setlocale \
2876utimes getrlimit setrlimit setpgid getcwd shutdown getaddrinfo \ 2878utimes getrlimit setrlimit setpgid getcwd shutdown getaddrinfo \
2877__fpending strsignal setitimer \ 2879__fpending strsignal setitimer \
2878sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ 2880sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index 23749331a83..d2562a4dae1 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -21,7 +21,7 @@
21# the same distribution terms as the rest of that program. 21# the same distribution terms as the rest of that program.
22# 22#
23# Generated by gnulib-tool. 23# Generated by gnulib-tool.
24# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=errno --avoid=fcntl --avoid=fcntl-h --avoid=fstat --avoid=msvc-inval --avoid=msvc-nothrow --avoid=raise --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub utimens warnings 24# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=at-internal --avoid=errno --avoid=fchdir --avoid=fcntl --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=openat-die --avoid=openat-h --avoid=raise --avoid=save-cwd --avoid=select --avoid=sigprocmask --avoid=sys_types --avoid=threadlib --makefile-name=gnulib.mk --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt c-ctype c-strcase careadlinkat crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat filemode getloadavg getopt-gnu gettime gettimeofday ignore-value intprops largefile lstat manywarnings mktime pselect pthread_sigmask readlink socklen stat-time stdalign stdarg stdbool stdio strftime strtoimax strtoumax symlink sys_stat sys_time time timer-time timespec-add timespec-sub utimens warnings
25 25
26 26
27MOSTLYCLEANFILES += core *.stackdump 27MOSTLYCLEANFILES += core *.stackdump
@@ -150,6 +150,17 @@ EXTRA_libgnu_a_SOURCES += dup2.c
150 150
151## end gnulib module dup2 151## end gnulib module dup2
152 152
153## begin gnulib module euidaccess
154
155if gl_GNULIB_ENABLED_euidaccess
156
157endif
158EXTRA_DIST += euidaccess.c
159
160EXTRA_libgnu_a_SOURCES += euidaccess.c
161
162## end gnulib module euidaccess
163
153## begin gnulib module execinfo 164## begin gnulib module execinfo
154 165
155BUILT_SOURCES += $(EXECINFO_H) 166BUILT_SOURCES += $(EXECINFO_H)
@@ -175,6 +186,50 @@ EXTRA_libgnu_a_SOURCES += execinfo.c
175 186
176## end gnulib module execinfo 187## end gnulib module execinfo
177 188
189## begin gnulib module faccessat
190
191
192EXTRA_DIST += at-func.c faccessat.c
193
194EXTRA_libgnu_a_SOURCES += at-func.c faccessat.c
195
196## end gnulib module faccessat
197
198## begin gnulib module fcntl-h
199
200BUILT_SOURCES += fcntl.h
201
202# We need the following in order to create <fcntl.h> when the system
203# doesn't have one that works with the given compiler.
204fcntl.h: fcntl.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
205 $(AM_V_GEN)rm -f $@-t $@ && \
206 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
207 sed -e 's|@''GUARD_PREFIX''@|GL|g' \
208 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
209 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
210 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
211 -e 's|@''NEXT_FCNTL_H''@|$(NEXT_FCNTL_H)|g' \
212 -e 's/@''GNULIB_FCNTL''@/$(GNULIB_FCNTL)/g' \
213 -e 's/@''GNULIB_NONBLOCKING''@/$(GNULIB_NONBLOCKING)/g' \
214 -e 's/@''GNULIB_OPEN''@/$(GNULIB_OPEN)/g' \
215 -e 's/@''GNULIB_OPENAT''@/$(GNULIB_OPENAT)/g' \
216 -e 's|@''HAVE_FCNTL''@|$(HAVE_FCNTL)|g' \
217 -e 's|@''HAVE_OPENAT''@|$(HAVE_OPENAT)|g' \
218 -e 's|@''REPLACE_FCNTL''@|$(REPLACE_FCNTL)|g' \
219 -e 's|@''REPLACE_OPEN''@|$(REPLACE_OPEN)|g' \
220 -e 's|@''REPLACE_OPENAT''@|$(REPLACE_OPENAT)|g' \
221 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
222 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
223 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
224 < $(srcdir)/fcntl.in.h; \
225 } > $@-t && \
226 mv $@-t $@
227MOSTLYCLEANFILES += fcntl.h fcntl.h-t
228
229EXTRA_DIST += fcntl.in.h
230
231## end gnulib module fcntl-h
232
178## begin gnulib module filemode 233## begin gnulib module filemode
179 234
180libgnu_a_SOURCES += filemode.c 235libgnu_a_SOURCES += filemode.c
@@ -183,6 +238,17 @@ EXTRA_DIST += filemode.h
183 238
184## end gnulib module filemode 239## end gnulib module filemode
185 240
241## begin gnulib module getgroups
242
243if gl_GNULIB_ENABLED_getgroups
244
245endif
246EXTRA_DIST += getgroups.c
247
248EXTRA_libgnu_a_SOURCES += getgroups.c
249
250## end gnulib module getgroups
251
186## begin gnulib module getloadavg 252## begin gnulib module getloadavg
187 253
188 254
@@ -242,6 +308,17 @@ EXTRA_libgnu_a_SOURCES += gettimeofday.c
242 308
243## end gnulib module gettimeofday 309## end gnulib module gettimeofday
244 310
311## begin gnulib module group-member
312
313if gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1
314
315endif
316EXTRA_DIST += group-member.c
317
318EXTRA_libgnu_a_SOURCES += group-member.c
319
320## end gnulib module group-member
321
245## begin gnulib module ignore-value 322## begin gnulib module ignore-value
246 323
247 324
@@ -354,6 +431,15 @@ EXTRA_libgnu_a_SOURCES += readlink.c
354 431
355## end gnulib module readlink 432## end gnulib module readlink
356 433
434## begin gnulib module root-uid
435
436if gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c
437
438endif
439EXTRA_DIST += root-uid.h
440
441## end gnulib module root-uid
442
357## begin gnulib module signal-h 443## begin gnulib module signal-h
358 444
359BUILT_SOURCES += signal.h 445BUILT_SOURCES += signal.h
@@ -1312,6 +1398,15 @@ EXTRA_DIST += verify.h
1312 1398
1313## end gnulib module verify 1399## end gnulib module verify
1314 1400
1401## begin gnulib module xalloc-oversized
1402
1403if gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec
1404
1405endif
1406EXTRA_DIST += xalloc-oversized.h
1407
1408## end gnulib module xalloc-oversized
1409
1315 1410
1316mostlyclean-local: mostlyclean-generic 1411mostlyclean-local: mostlyclean-generic
1317 @for dir in '' $(MOSTLYCLEANDIRS); do \ 1412 @for dir in '' $(MOSTLYCLEANDIRS); do \
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index de2355d87c3..9b2dcee1cfa 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -53,17 +53,22 @@ AC_DEFUN([gl_EARLY],
53 # Code from module dtotimespec: 53 # Code from module dtotimespec:
54 # Code from module dup2: 54 # Code from module dup2:
55 # Code from module environ: 55 # Code from module environ:
56 # Code from module euidaccess:
56 # Code from module execinfo: 57 # Code from module execinfo:
57 # Code from module extensions: 58 # Code from module extensions:
58 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 59 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
59 # Code from module extern-inline: 60 # Code from module extern-inline:
61 # Code from module faccessat:
62 # Code from module fcntl-h:
60 # Code from module filemode: 63 # Code from module filemode:
64 # Code from module getgroups:
61 # Code from module getloadavg: 65 # Code from module getloadavg:
62 # Code from module getopt-gnu: 66 # Code from module getopt-gnu:
63 # Code from module getopt-posix: 67 # Code from module getopt-posix:
64 # Code from module gettext-h: 68 # Code from module gettext-h:
65 # Code from module gettime: 69 # Code from module gettime:
66 # Code from module gettimeofday: 70 # Code from module gettimeofday:
71 # Code from module group-member:
67 # Code from module ignore-value: 72 # Code from module ignore-value:
68 # Code from module include_next: 73 # Code from module include_next:
69 # Code from module intprops: 74 # Code from module intprops:
@@ -79,6 +84,7 @@ AC_DEFUN([gl_EARLY],
79 # Code from module pselect: 84 # Code from module pselect:
80 # Code from module pthread_sigmask: 85 # Code from module pthread_sigmask:
81 # Code from module readlink: 86 # Code from module readlink:
87 # Code from module root-uid:
82 # Code from module signal-h: 88 # Code from module signal-h:
83 # Code from module snippet/_Noreturn: 89 # Code from module snippet/_Noreturn:
84 # Code from module snippet/arg-nonnull: 90 # Code from module snippet/arg-nonnull:
@@ -120,6 +126,7 @@ AC_DEFUN([gl_EARLY],
120 # Code from module utimens: 126 # Code from module utimens:
121 # Code from module verify: 127 # Code from module verify:
122 # Code from module warnings: 128 # Code from module warnings:
129 # Code from module xalloc-oversized:
123]) 130])
124 131
125# This macro should be invoked from ./configure.ac, in the section 132# This macro should be invoked from ./configure.ac, in the section
@@ -156,6 +163,14 @@ AC_DEFUN([gl_INIT],
156 gl_UNISTD_MODULE_INDICATOR([environ]) 163 gl_UNISTD_MODULE_INDICATOR([environ])
157 gl_EXECINFO_H 164 gl_EXECINFO_H
158 AC_REQUIRE([gl_EXTERN_INLINE]) 165 AC_REQUIRE([gl_EXTERN_INLINE])
166 gl_FUNC_FACCESSAT
167 if test $HAVE_FACCESSAT = 0; then
168 AC_LIBOBJ([faccessat])
169 gl_PREREQ_FACCESSAT
170 fi
171 gl_MODULE_INDICATOR([faccessat])
172 gl_UNISTD_MODULE_INDICATOR([faccessat])
173 gl_FCNTL_H
159 gl_FILEMODE 174 gl_FILEMODE
160 gl_GETLOADAVG 175 gl_GETLOADAVG
161 if test $HAVE_GETLOADAVG = 0; then 176 if test $HAVE_GETLOADAVG = 0; then
@@ -269,18 +284,53 @@ AC_DEFUN([gl_INIT],
269 gl_UNISTD_H 284 gl_UNISTD_H
270 gl_UTIMENS 285 gl_UTIMENS
271 gl_gnulib_enabled_dosname=false 286 gl_gnulib_enabled_dosname=false
287 gl_gnulib_enabled_euidaccess=false
288 gl_gnulib_enabled_getgroups=false
272 gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=false 289 gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=false
290 gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=false
273 gl_gnulib_enabled_pathmax=false 291 gl_gnulib_enabled_pathmax=false
292 gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=false
274 gl_gnulib_enabled_stat=false 293 gl_gnulib_enabled_stat=false
275 gl_gnulib_enabled_strtoll=false 294 gl_gnulib_enabled_strtoll=false
276 gl_gnulib_enabled_strtoull=false 295 gl_gnulib_enabled_strtoull=false
277 gl_gnulib_enabled_verify=false 296 gl_gnulib_enabled_verify=false
297 gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=false
278 func_gl_gnulib_m4code_dosname () 298 func_gl_gnulib_m4code_dosname ()
279 { 299 {
280 if ! $gl_gnulib_enabled_dosname; then 300 if ! $gl_gnulib_enabled_dosname; then
281 gl_gnulib_enabled_dosname=true 301 gl_gnulib_enabled_dosname=true
282 fi 302 fi
283 } 303 }
304 func_gl_gnulib_m4code_euidaccess ()
305 {
306 if ! $gl_gnulib_enabled_euidaccess; then
307 gl_FUNC_EUIDACCESS
308 if test $HAVE_EUIDACCESS = 0; then
309 AC_LIBOBJ([euidaccess])
310 gl_PREREQ_EUIDACCESS
311 fi
312 gl_UNISTD_MODULE_INDICATOR([euidaccess])
313 gl_gnulib_enabled_euidaccess=true
314 if test $HAVE_EUIDACCESS = 0; then
315 func_gl_gnulib_m4code_a9786850e999ae65a836a6041e8e5ed1
316 fi
317 func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c
318 if test $HAVE_EUIDACCESS = 0; then
319 func_gl_gnulib_m4code_stat
320 fi
321 fi
322 }
323 func_gl_gnulib_m4code_getgroups ()
324 {
325 if ! $gl_gnulib_enabled_getgroups; then
326 gl_FUNC_GETGROUPS
327 if test $HAVE_GETGROUPS = 0 || test $REPLACE_GETGROUPS = 1; then
328 AC_LIBOBJ([getgroups])
329 fi
330 gl_UNISTD_MODULE_INDICATOR([getgroups])
331 gl_gnulib_enabled_getgroups=true
332 fi
333 }
284 func_gl_gnulib_m4code_be453cec5eecf5731a274f2de7f2db36 () 334 func_gl_gnulib_m4code_be453cec5eecf5731a274f2de7f2db36 ()
285 { 335 {
286 if ! $gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36; then 336 if ! $gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36; then
@@ -289,6 +339,24 @@ AC_DEFUN([gl_INIT],
289 gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=true 339 gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36=true
290 fi 340 fi
291 } 341 }
342 func_gl_gnulib_m4code_a9786850e999ae65a836a6041e8e5ed1 ()
343 {
344 if ! $gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1; then
345 gl_FUNC_GROUP_MEMBER
346 if test $HAVE_GROUP_MEMBER = 0; then
347 AC_LIBOBJ([group-member])
348 gl_PREREQ_GROUP_MEMBER
349 fi
350 gl_UNISTD_MODULE_INDICATOR([group-member])
351 gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1=true
352 if test $HAVE_GROUP_MEMBER = 0; then
353 func_gl_gnulib_m4code_getgroups
354 fi
355 if test $HAVE_GROUP_MEMBER = 0; then
356 func_gl_gnulib_m4code_682e609604ccaac6be382e4ee3a4eaec
357 fi
358 fi
359 }
292 func_gl_gnulib_m4code_pathmax () 360 func_gl_gnulib_m4code_pathmax ()
293 { 361 {
294 if ! $gl_gnulib_enabled_pathmax; then 362 if ! $gl_gnulib_enabled_pathmax; then
@@ -296,6 +364,12 @@ AC_DEFUN([gl_INIT],
296 gl_gnulib_enabled_pathmax=true 364 gl_gnulib_enabled_pathmax=true
297 fi 365 fi
298 } 366 }
367 func_gl_gnulib_m4code_6099e9737f757db36c47fa9d9f02e88c ()
368 {
369 if ! $gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c; then
370 gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c=true
371 fi
372 }
299 func_gl_gnulib_m4code_stat () 373 func_gl_gnulib_m4code_stat ()
300 { 374 {
301 if ! $gl_gnulib_enabled_stat; then 375 if ! $gl_gnulib_enabled_stat; then
@@ -347,6 +421,18 @@ AC_DEFUN([gl_INIT],
347 gl_gnulib_enabled_verify=true 421 gl_gnulib_enabled_verify=true
348 fi 422 fi
349 } 423 }
424 func_gl_gnulib_m4code_682e609604ccaac6be382e4ee3a4eaec ()
425 {
426 if ! $gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec; then
427 gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec=true
428 fi
429 }
430 if test $HAVE_FACCESSAT = 0; then
431 func_gl_gnulib_m4code_dosname
432 fi
433 if test $HAVE_FACCESSAT = 0; then
434 func_gl_gnulib_m4code_euidaccess
435 fi
350 if test $REPLACE_GETOPT = 1; then 436 if test $REPLACE_GETOPT = 1; then
351 func_gl_gnulib_m4code_be453cec5eecf5731a274f2de7f2db36 437 func_gl_gnulib_m4code_be453cec5eecf5731a274f2de7f2db36
352 fi 438 fi
@@ -373,12 +459,17 @@ AC_DEFUN([gl_INIT],
373 fi 459 fi
374 m4_pattern_allow([^gl_GNULIB_ENABLED_]) 460 m4_pattern_allow([^gl_GNULIB_ENABLED_])
375 AM_CONDITIONAL([gl_GNULIB_ENABLED_dosname], [$gl_gnulib_enabled_dosname]) 461 AM_CONDITIONAL([gl_GNULIB_ENABLED_dosname], [$gl_gnulib_enabled_dosname])
462 AM_CONDITIONAL([gl_GNULIB_ENABLED_euidaccess], [$gl_gnulib_enabled_euidaccess])
463 AM_CONDITIONAL([gl_GNULIB_ENABLED_getgroups], [$gl_gnulib_enabled_getgroups])
376 AM_CONDITIONAL([gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36], [$gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36]) 464 AM_CONDITIONAL([gl_GNULIB_ENABLED_be453cec5eecf5731a274f2de7f2db36], [$gl_gnulib_enabled_be453cec5eecf5731a274f2de7f2db36])
465 AM_CONDITIONAL([gl_GNULIB_ENABLED_a9786850e999ae65a836a6041e8e5ed1], [$gl_gnulib_enabled_a9786850e999ae65a836a6041e8e5ed1])
377 AM_CONDITIONAL([gl_GNULIB_ENABLED_pathmax], [$gl_gnulib_enabled_pathmax]) 466 AM_CONDITIONAL([gl_GNULIB_ENABLED_pathmax], [$gl_gnulib_enabled_pathmax])
467 AM_CONDITIONAL([gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c], [$gl_gnulib_enabled_6099e9737f757db36c47fa9d9f02e88c])
378 AM_CONDITIONAL([gl_GNULIB_ENABLED_stat], [$gl_gnulib_enabled_stat]) 468 AM_CONDITIONAL([gl_GNULIB_ENABLED_stat], [$gl_gnulib_enabled_stat])
379 AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll]) 469 AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoll], [$gl_gnulib_enabled_strtoll])
380 AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoull], [$gl_gnulib_enabled_strtoull]) 470 AM_CONDITIONAL([gl_GNULIB_ENABLED_strtoull], [$gl_gnulib_enabled_strtoull])
381 AM_CONDITIONAL([gl_GNULIB_ENABLED_verify], [$gl_gnulib_enabled_verify]) 471 AM_CONDITIONAL([gl_GNULIB_ENABLED_verify], [$gl_gnulib_enabled_verify])
472 AM_CONDITIONAL([gl_GNULIB_ENABLED_682e609604ccaac6be382e4ee3a4eaec], [$gl_gnulib_enabled_682e609604ccaac6be382e4ee3a4eaec])
382 # End of code from modules 473 # End of code from modules
383 m4_ifval(gl_LIBSOURCES_LIST, [ 474 m4_ifval(gl_LIBSOURCES_LIST, [
384 m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ || 475 m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
@@ -527,6 +618,7 @@ AC_DEFUN([gl_FILE_LIST], [
527 lib/alloca.in.h 618 lib/alloca.in.h
528 lib/allocator.c 619 lib/allocator.c
529 lib/allocator.h 620 lib/allocator.h
621 lib/at-func.c
530 lib/c-ctype.c 622 lib/c-ctype.c
531 lib/c-ctype.h 623 lib/c-ctype.h
532 lib/c-strcase.h 624 lib/c-strcase.h
@@ -538,12 +630,16 @@ AC_DEFUN([gl_FILE_LIST], [
538 lib/dtoastr.c 630 lib/dtoastr.c
539 lib/dtotimespec.c 631 lib/dtotimespec.c
540 lib/dup2.c 632 lib/dup2.c
633 lib/euidaccess.c
541 lib/execinfo.c 634 lib/execinfo.c
542 lib/execinfo.in.h 635 lib/execinfo.in.h
636 lib/faccessat.c
637 lib/fcntl.in.h
543 lib/filemode.c 638 lib/filemode.c
544 lib/filemode.h 639 lib/filemode.h
545 lib/ftoastr.c 640 lib/ftoastr.c
546 lib/ftoastr.h 641 lib/ftoastr.h
642 lib/getgroups.c
547 lib/getloadavg.c 643 lib/getloadavg.c
548 lib/getopt.c 644 lib/getopt.c
549 lib/getopt.in.h 645 lib/getopt.in.h
@@ -552,6 +648,7 @@ AC_DEFUN([gl_FILE_LIST], [
552 lib/gettext.h 648 lib/gettext.h
553 lib/gettime.c 649 lib/gettime.c
554 lib/gettimeofday.c 650 lib/gettimeofday.c
651 lib/group-member.c
555 lib/ignore-value.h 652 lib/ignore-value.h
556 lib/intprops.h 653 lib/intprops.h
557 lib/inttypes.in.h 654 lib/inttypes.in.h
@@ -564,6 +661,7 @@ AC_DEFUN([gl_FILE_LIST], [
564 lib/pselect.c 661 lib/pselect.c
565 lib/pthread_sigmask.c 662 lib/pthread_sigmask.c
566 lib/readlink.c 663 lib/readlink.c
664 lib/root-uid.h
567 lib/sha1.c 665 lib/sha1.c
568 lib/sha1.h 666 lib/sha1.h
569 lib/sha256.c 667 lib/sha256.c
@@ -605,21 +703,28 @@ AC_DEFUN([gl_FILE_LIST], [
605 lib/utimens.c 703 lib/utimens.c
606 lib/utimens.h 704 lib/utimens.h
607 lib/verify.h 705 lib/verify.h
706 lib/xalloc-oversized.h
608 m4/00gnulib.m4 707 m4/00gnulib.m4
609 m4/alloca.m4 708 m4/alloca.m4
610 m4/c-strtod.m4 709 m4/c-strtod.m4
611 m4/clock_time.m4 710 m4/clock_time.m4
612 m4/dup2.m4 711 m4/dup2.m4
613 m4/environ.m4 712 m4/environ.m4
713 m4/euidaccess.m4
614 m4/execinfo.m4 714 m4/execinfo.m4
615 m4/extensions.m4 715 m4/extensions.m4
616 m4/extern-inline.m4 716 m4/extern-inline.m4
717 m4/faccessat.m4
718 m4/fcntl-o.m4
719 m4/fcntl_h.m4
617 m4/filemode.m4 720 m4/filemode.m4
721 m4/getgroups.m4
618 m4/getloadavg.m4 722 m4/getloadavg.m4
619 m4/getopt.m4 723 m4/getopt.m4
620 m4/gettime.m4 724 m4/gettime.m4
621 m4/gettimeofday.m4 725 m4/gettimeofday.m4
622 m4/gnulib-common.m4 726 m4/gnulib-common.m4
727 m4/group-member.m4
623 m4/include_next.m4 728 m4/include_next.m4
624 m4/inttypes.m4 729 m4/inttypes.m4
625 m4/largefile.m4 730 m4/largefile.m4
diff --git a/nt/ChangeLog b/nt/ChangeLog
index 94d2ce18551..f64cafe2e16 100644
--- a/nt/ChangeLog
+++ b/nt/ChangeLog
@@ -1,3 +1,10 @@
12012-10-19 Paul Eggert <eggert@cs.ucla.edu>
2
3 Use faccessat, not access, when checking file permissions (Bug#12632).
4 * inc/ms-w32.h (AT_FDCWD, AT_EACCESS): New symbols.
5 (access): Remove.
6 (faccessat): New macro.
7
12012-10-17 Eli Zaretskii <eliz@gnu.org> 82012-10-17 Eli Zaretskii <eliz@gnu.org>
2 9
3 * inc/pwd.h (getuid, geteuid): Add prototypes. 10 * inc/pwd.h (getuid, geteuid): Add prototypes.
diff --git a/nt/inc/ms-w32.h b/nt/inc/ms-w32.h
index dd2ae781cb8..0f6b51d3915 100644
--- a/nt/inc/ms-w32.h
+++ b/nt/inc/ms-w32.h
@@ -124,6 +124,10 @@ extern char *getenv ();
124#define MAXPATHLEN _MAX_PATH 124#define MAXPATHLEN _MAX_PATH
125#endif 125#endif
126 126
127/* Use values compatible with gnulib, as there's no reason to differ. */
128#define AT_FDCWD (-3041965)
129#define AT_EACCESS 4
130
127#ifdef HAVE_NTGUI 131#ifdef HAVE_NTGUI
128#define HAVE_WINDOW_SYSTEM 1 132#define HAVE_WINDOW_SYSTEM 1
129#define HAVE_MENUS 1 133#define HAVE_MENUS 1
@@ -145,8 +149,6 @@ extern char *getenv ();
145#endif 149#endif
146 150
147/* Calls that are emulated or shadowed. */ 151/* Calls that are emulated or shadowed. */
148#undef access
149#define access sys_access
150#undef chdir 152#undef chdir
151#define chdir sys_chdir 153#define chdir sys_chdir
152#undef chmod 154#undef chmod
@@ -161,6 +163,7 @@ extern char *getenv ();
161#define dup sys_dup 163#define dup sys_dup
162#undef dup2 164#undef dup2
163#define dup2 sys_dup2 165#define dup2 sys_dup2
166#define faccessat sys_faccessat
164#define fopen sys_fopen 167#define fopen sys_fopen
165#define link sys_link 168#define link sys_link
166#define localtime sys_localtime 169#define localtime sys_localtime
diff --git a/src/ChangeLog b/src/ChangeLog
index 5a1b4a5d8ee..ee18650e992 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,32 @@
12012-10-19 Paul Eggert <eggert@cs.ucla.edu>
2
3 Use faccessat, not access, when checking file permissions (Bug#12632).
4 * Makefile.in (LIB_EACCESS): New macro.
5 (LIBES): Use it.
6 * callproc.c (init_callproc):
7 * charset.c (init_charset):
8 * fileio.c (check_existing, check_executable):
9 * lread.c (openp, load_path_check):
10 * process.c (allocate_pty):
11 * xrdb.c (file_p):
12 Use faccessat, not access or euidaccess. Use symbolic names
13 instead of integers for the flags, as they're portable now.
14 * charset.c, xrdb.c: Include <fcntl.h>, for the new flags used.
15 * fileio.c (Ffile_readable_p):
16 Use faccessat, not stat + open + close.
17 (file_directory_p): New function, which uses 'stat' on most places
18 but 'access' (for efficiency) if WINDOWSNT.
19 * fileio.c (Ffile_directory_p, Fset_file_times):
20 * xrdb.c (file_p): Use file_directory_p.
21 * lisp.h (file_directory_p): New decl.
22 * lread.c (openp): When opening a file, use fstat rather than
23 stat, as that avoids a permissions race. When not opening a file,
24 use file_directory_p rather than stat.
25 * process.c, sysdep.c, term.c: All uses of '#ifdef O_NONBLOCK'
26 changed to '#if O_NONBLOCK', to accommodate gnulib O_* style.
27 * w32.c (sys_faccessat): Rename from sys_access and switch to
28 faccessat's API. All uses changed.
29
12012-10-19 Kazuhiro Ito <kzhr@d1.dion.ne.jp> (tiny change) 302012-10-19 Kazuhiro Ito <kzhr@d1.dion.ne.jp> (tiny change)
2 31
3 * font.c (Ffont_at): Fix previous change. 32 * font.c (Ffont_at): Fix previous change.
diff --git a/src/Makefile.in b/src/Makefile.in
index c24e421bbbc..d034ad04796 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -150,6 +150,7 @@ M17N_FLT_CFLAGS = @M17N_FLT_CFLAGS@
150M17N_FLT_LIBS = @M17N_FLT_LIBS@ 150M17N_FLT_LIBS = @M17N_FLT_LIBS@
151 151
152LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@ 152LIB_CLOCK_GETTIME=@LIB_CLOCK_GETTIME@
153LIB_EACCESS=@LIB_EACCESS@
153LIB_TIMER_TIME=@LIB_TIMER_TIME@ 154LIB_TIMER_TIME=@LIB_TIMER_TIME@
154 155
155DBUS_CFLAGS = @DBUS_CFLAGS@ 156DBUS_CFLAGS = @DBUS_CFLAGS@
@@ -392,7 +393,7 @@ otherobj= $(TERMCAP_OBJ) $(PRE_ALLOC_OBJ) $(GMALLOC_OBJ) $(RALLOC_OBJ) \
392LIBES = $(LIBS) $(W32_LIBS) $(LIBX_BASE) $(LIBIMAGE) \ 393LIBES = $(LIBS) $(W32_LIBS) $(LIBX_BASE) $(LIBIMAGE) \
393 $(LIBX_OTHER) $(LIBSOUND) \ 394 $(LIBX_OTHER) $(LIBSOUND) \
394 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \ 395 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_CLOCK_GETTIME) \
395 $(LIB_TIMER_TIME) $(DBUS_LIBS) \ 396 $(LIB_EACCESS) $(LIB_TIMER_TIME) $(DBUS_LIBS) \
396 $(LIB_EXECINFO) \ 397 $(LIB_EXECINFO) \
397 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \ 398 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) \
398 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \ 399 $(LIBS_TERMCAP) $(GETLOADAVG_LIBS) $(SETTINGS_LIBS) $(LIBSELINUX_LIBS) \
diff --git a/src/callproc.c b/src/callproc.c
index b33882e54c2..5a9b32f08c3 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1597,13 +1597,13 @@ init_callproc (void)
1597#endif 1597#endif
1598 { 1598 {
1599 tempdir = Fdirectory_file_name (Vexec_directory); 1599 tempdir = Fdirectory_file_name (Vexec_directory);
1600 if (access (SSDATA (tempdir), 0) < 0) 1600 if (faccessat (AT_FDCWD, SSDATA (tempdir), F_OK, AT_EACCESS) != 0)
1601 dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n", 1601 dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n",
1602 Vexec_directory); 1602 Vexec_directory);
1603 } 1603 }
1604 1604
1605 tempdir = Fdirectory_file_name (Vdata_directory); 1605 tempdir = Fdirectory_file_name (Vdata_directory);
1606 if (access (SSDATA (tempdir), 0) < 0) 1606 if (faccessat (AT_FDCWD, SSDATA (tempdir), F_OK, AT_EACCESS) != 0)
1607 dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n", 1607 dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n",
1608 Vdata_directory); 1608 Vdata_directory);
1609 1609
diff --git a/src/charset.c b/src/charset.c
index 6b999824dab..fe068e1d3bc 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -28,6 +28,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
28 28
29#define CHARSET_INLINE EXTERN_INLINE 29#define CHARSET_INLINE EXTERN_INLINE
30 30
31#include <fcntl.h>
31#include <stdio.h> 32#include <stdio.h>
32#include <unistd.h> 33#include <unistd.h>
33#include <limits.h> 34#include <limits.h>
@@ -2293,7 +2294,7 @@ init_charset (void)
2293{ 2294{
2294 Lisp_Object tempdir; 2295 Lisp_Object tempdir;
2295 tempdir = Fexpand_file_name (build_string ("charsets"), Vdata_directory); 2296 tempdir = Fexpand_file_name (build_string ("charsets"), Vdata_directory);
2296 if (access (SSDATA (tempdir), 0) < 0) 2297 if (faccessat (AT_FDCWD, SSDATA (tempdir), F_OK, AT_EACCESS) != 0)
2297 { 2298 {
2298 /* This used to be non-fatal (dir_warning), but it should not 2299 /* This used to be non-fatal (dir_warning), but it should not
2299 happen, and if it does sooner or later it will cause some 2300 happen, and if it does sooner or later it will cause some
diff --git a/src/conf_post.h b/src/conf_post.h
index aa008107ba6..eade536e6e1 100644
--- a/src/conf_post.h
+++ b/src/conf_post.h
@@ -169,6 +169,10 @@ extern void _DebPrint (const char *fmt, ...);
169#endif 169#endif
170#endif 170#endif
171 171
172/* Tell gnulib to omit support for openat-related functions having a
173 first argument other than AT_FDCWD. */
174#define GNULIB_SUPPORT_ONLY_AT_FDCWD
175
172#include <string.h> 176#include <string.h>
173#include <stdlib.h> 177#include <stdlib.h>
174 178
diff --git a/src/fileio.c b/src/fileio.c
index d47d7dd9e0b..3accb58a3eb 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2425,15 +2425,7 @@ On Unix, this is a name starting with a `/' or a `~'. */)
2425bool 2425bool
2426check_existing (const char *filename) 2426check_existing (const char *filename)
2427{ 2427{
2428#ifdef DOS_NT 2428 return faccessat (AT_FDCWD, filename, F_OK, AT_EACCESS) == 0;
2429 /* The full emulation of Posix 'stat' is too expensive on
2430 DOS/Windows, when all we want to know is whether the file exists.
2431 So we use 'access' instead, which is much more lightweight. */
2432 return (access (filename, F_OK) >= 0);
2433#else
2434 struct stat st;
2435 return (stat (filename, &st) >= 0);
2436#endif
2437} 2429}
2438 2430
2439/* Return true if file FILENAME exists and can be executed. */ 2431/* Return true if file FILENAME exists and can be executed. */
@@ -2441,21 +2433,7 @@ check_existing (const char *filename)
2441static bool 2433static bool
2442check_executable (char *filename) 2434check_executable (char *filename)
2443{ 2435{
2444#ifdef DOS_NT 2436 return faccessat (AT_FDCWD, filename, X_OK, AT_EACCESS) == 0;
2445 struct stat st;
2446 if (stat (filename, &st) < 0)
2447 return 0;
2448 return ((st.st_mode & S_IEXEC) != 0);
2449#else /* not DOS_NT */
2450#ifdef HAVE_EUIDACCESS
2451 return (euidaccess (filename, 1) >= 0);
2452#else
2453 /* Access isn't quite right because it uses the real uid
2454 and we really want to test with the effective uid.
2455 But Unix doesn't give us a right way to do it. */
2456 return (access (filename, 1) >= 0);
2457#endif
2458#endif /* not DOS_NT */
2459} 2437}
2460 2438
2461/* Return true if file FILENAME exists and can be written. */ 2439/* Return true if file FILENAME exists and can be written. */
@@ -2464,15 +2442,16 @@ static bool
2464check_writable (const char *filename) 2442check_writable (const char *filename)
2465{ 2443{
2466#ifdef MSDOS 2444#ifdef MSDOS
2445 /* FIXME: an faccessat implementation should be added to the
2446 DOS/Windows ports and this #ifdef branch should be removed. */
2467 struct stat st; 2447 struct stat st;
2468 if (stat (filename, &st) < 0) 2448 if (stat (filename, &st) < 0)
2469 return 0; 2449 return 0;
2470 return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode)); 2450 return (st.st_mode & S_IWRITE || S_ISDIR (st.st_mode));
2471#else /* not MSDOS */ 2451#else /* not MSDOS */
2472#ifdef HAVE_EUIDACCESS 2452 bool res = faccessat (AT_FDCWD, filename, W_OK, AT_EACCESS) == 0;
2473 bool res = (euidaccess (filename, 2) >= 0);
2474#ifdef CYGWIN 2453#ifdef CYGWIN
2475 /* euidaccess may have returned failure because Cygwin couldn't 2454 /* faccessat may have returned failure because Cygwin couldn't
2476 determine the file's UID or GID; if so, we return success. */ 2455 determine the file's UID or GID; if so, we return success. */
2477 if (!res) 2456 if (!res)
2478 { 2457 {
@@ -2483,14 +2462,6 @@ check_writable (const char *filename)
2483 } 2462 }
2484#endif /* CYGWIN */ 2463#endif /* CYGWIN */
2485 return res; 2464 return res;
2486#else /* not HAVE_EUIDACCESS */
2487 /* Access isn't quite right because it uses the real uid
2488 and we really want to test with the effective uid.
2489 But Unix doesn't give us a right way to do it.
2490 Opening with O_WRONLY could work for an ordinary file,
2491 but would lose for directories. */
2492 return (access (filename, 2) >= 0);
2493#endif /* not HAVE_EUIDACCESS */
2494#endif /* not MSDOS */ 2465#endif /* not MSDOS */
2495} 2466}
2496 2467
@@ -2547,9 +2518,6 @@ See also `file-exists-p' and `file-attributes'. */)
2547{ 2518{
2548 Lisp_Object absname; 2519 Lisp_Object absname;
2549 Lisp_Object handler; 2520 Lisp_Object handler;
2550 int desc;
2551 int flags;
2552 struct stat statbuf;
2553 2521
2554 CHECK_STRING (filename); 2522 CHECK_STRING (filename);
2555 absname = Fexpand_file_name (filename, Qnil); 2523 absname = Fexpand_file_name (filename, Qnil);
@@ -2561,31 +2529,8 @@ See also `file-exists-p' and `file-attributes'. */)
2561 return call2 (handler, Qfile_readable_p, absname); 2529 return call2 (handler, Qfile_readable_p, absname);
2562 2530
2563 absname = ENCODE_FILE (absname); 2531 absname = ENCODE_FILE (absname);
2564 2532 return (faccessat (AT_FDCWD, SSDATA (absname), R_OK, AT_EACCESS) == 0
2565#if defined (DOS_NT) || defined (macintosh) 2533 ? Qt : Qnil);
2566 /* Under MS-DOS, Windows, and Macintosh, open does not work for
2567 directories. */
2568 if (access (SDATA (absname), 0) == 0)
2569 return Qt;
2570 return Qnil;
2571#else /* not DOS_NT and not macintosh */
2572 flags = O_RDONLY;
2573#ifdef O_NONBLOCK
2574 /* Opening a fifo without O_NONBLOCK can wait.
2575 We don't want to wait. But we don't want to mess wth O_NONBLOCK
2576 except in the case of a fifo, on a system which handles it. */
2577 desc = stat (SSDATA (absname), &statbuf);
2578 if (desc < 0)
2579 return Qnil;
2580 if (S_ISFIFO (statbuf.st_mode))
2581 flags |= O_NONBLOCK;
2582#endif
2583 desc = emacs_open (SSDATA (absname), flags, 0);
2584 if (desc < 0)
2585 return Qnil;
2586 emacs_close (desc);
2587 return Qt;
2588#endif /* not DOS_NT and not macintosh */
2589} 2534}
2590 2535
2591/* Having this before file-symlink-p mysteriously caused it to be forgotten 2536/* Having this before file-symlink-p mysteriously caused it to be forgotten
@@ -2622,7 +2567,7 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0,
2622 /* The read-only attribute of the parent directory doesn't affect 2567 /* The read-only attribute of the parent directory doesn't affect
2623 whether a file or directory can be created within it. Some day we 2568 whether a file or directory can be created within it. Some day we
2624 should check ACLs though, which do affect this. */ 2569 should check ACLs though, which do affect this. */
2625 return (access (SDATA (dir), D_OK) < 0) ? Qnil : Qt; 2570 return file_directory_p (SDATA (dir)) ? Qt : Qnil;
2626#else 2571#else
2627 return (check_writable (!NILP (dir) ? SSDATA (dir) : "") 2572 return (check_writable (!NILP (dir) ? SSDATA (dir) : "")
2628 ? Qt : Qnil); 2573 ? Qt : Qnil);
@@ -2703,8 +2648,7 @@ Symbolic links to directories count as directories.
2703See `file-symlink-p' to distinguish symlinks. */) 2648See `file-symlink-p' to distinguish symlinks. */)
2704 (Lisp_Object filename) 2649 (Lisp_Object filename)
2705{ 2650{
2706 register Lisp_Object absname; 2651 Lisp_Object absname;
2707 struct stat st;
2708 Lisp_Object handler; 2652 Lisp_Object handler;
2709 2653
2710 absname = expand_and_dir_to_file (filename, BVAR (current_buffer, directory)); 2654 absname = expand_and_dir_to_file (filename, BVAR (current_buffer, directory));
@@ -2717,9 +2661,20 @@ See `file-symlink-p' to distinguish symlinks. */)
2717 2661
2718 absname = ENCODE_FILE (absname); 2662 absname = ENCODE_FILE (absname);
2719 2663
2720 if (stat (SSDATA (absname), &st) < 0) 2664 return file_directory_p (SSDATA (absname)) ? Qt : Qnil;
2721 return Qnil; 2665}
2722 return S_ISDIR (st.st_mode) ? Qt : Qnil; 2666
2667/* Return true if FILE is a directory or a symlink to a directory. */
2668bool
2669file_directory_p (char const *file)
2670{
2671#ifdef WINDOWSNT
2672 /* This is cheaper than 'stat'. */
2673 return faccessat (AT_FDCWD, file, D_OK, AT_EACCESS) == 0;
2674#else
2675 struct stat st;
2676 return stat (file, &st) == 0 && S_ISDIR (st.st_mode);
2677#endif
2723} 2678}
2724 2679
2725DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p, 2680DEFUN ("file-accessible-directory-p", Ffile_accessible_directory_p,
@@ -3044,10 +2999,8 @@ Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of
3044 if (set_file_times (-1, SSDATA (encoded_absname), t, t)) 2999 if (set_file_times (-1, SSDATA (encoded_absname), t, t))
3045 { 3000 {
3046#ifdef MSDOS 3001#ifdef MSDOS
3047 struct stat st;
3048
3049 /* Setting times on a directory always fails. */ 3002 /* Setting times on a directory always fails. */
3050 if (stat (SSDATA (encoded_absname), &st) == 0 && S_ISDIR (st.st_mode)) 3003 if (file_directory_p (SSDATA (encoded_absname)))
3051 return Qnil; 3004 return Qnil;
3052#endif 3005#endif
3053 report_file_error ("Setting file times", Fcons (absname, Qnil)); 3006 report_file_error ("Setting file times", Fcons (absname, Qnil));
diff --git a/src/lisp.h b/src/lisp.h
index 01f6ca5e57c..897757cf462 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3178,6 +3178,7 @@ extern Lisp_Object close_file_unwind (Lisp_Object);
3178extern Lisp_Object restore_point_unwind (Lisp_Object); 3178extern Lisp_Object restore_point_unwind (Lisp_Object);
3179extern _Noreturn void report_file_error (const char *, Lisp_Object); 3179extern _Noreturn void report_file_error (const char *, Lisp_Object);
3180extern void internal_delete_file (Lisp_Object); 3180extern void internal_delete_file (Lisp_Object);
3181extern bool file_directory_p (const char *);
3181extern void syms_of_fileio (void); 3182extern void syms_of_fileio (void);
3182extern Lisp_Object make_temp_name (Lisp_Object, bool); 3183extern Lisp_Object make_temp_name (Lisp_Object, bool);
3183extern Lisp_Object Qdelete_file; 3184extern Lisp_Object Qdelete_file;
diff --git a/src/lread.c b/src/lread.c
index 6d4c0d990af..dedce50de2a 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1404,7 +1404,7 @@ Returns the file's name in absolute form, or nil if not found.
1404If SUFFIXES is non-nil, it should be a list of suffixes to append to 1404If SUFFIXES is non-nil, it should be a list of suffixes to append to
1405file name when searching. 1405file name when searching.
1406If non-nil, PREDICATE is used instead of `file-readable-p'. 1406If non-nil, PREDICATE is used instead of `file-readable-p'.
1407PREDICATE can also be an integer to pass to the access(2) function, 1407PREDICATE can also be an integer to pass to the faccessat(2) function,
1408in which case file-name-handlers are ignored. 1408in which case file-name-handlers are ignored.
1409This function will normally skip directories, so if you want it to find 1409This function will normally skip directories, so if you want it to find
1410directories, make sure the PREDICATE function returns `dir-ok' for them. */) 1410directories, make sure the PREDICATE function returns `dir-ok' for them. */)
@@ -1442,7 +1442,6 @@ static Lisp_Object Qdir_ok;
1442int 1442int
1443openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate) 1443openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate)
1444{ 1444{
1445 int fd;
1446 ptrdiff_t fn_size = 100; 1445 ptrdiff_t fn_size = 100;
1447 char buf[100]; 1446 char buf[100];
1448 char *fn = buf; 1447 char *fn = buf;
@@ -1497,7 +1496,6 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1497 { 1496 {
1498 ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail)); 1497 ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail));
1499 Lisp_Object handler; 1498 Lisp_Object handler;
1500 bool exists;
1501 1499
1502 /* Concatenate path element/specified name with the suffix. 1500 /* Concatenate path element/specified name with the suffix.
1503 If the directory starts with /:, remove that. */ 1501 If the directory starts with /:, remove that. */
@@ -1521,6 +1519,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1521 handler = Ffind_file_name_handler (string, Qfile_exists_p); 1519 handler = Ffind_file_name_handler (string, Qfile_exists_p);
1522 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) 1520 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
1523 { 1521 {
1522 bool exists;
1524 if (NILP (predicate)) 1523 if (NILP (predicate))
1525 exists = !NILP (Ffile_readable_p (string)); 1524 exists = !NILP (Ffile_readable_p (string));
1526 else 1525 else
@@ -1542,37 +1541,40 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1542 } 1541 }
1543 else 1542 else
1544 { 1543 {
1545#ifndef WINDOWSNT 1544 int fd;
1546 struct stat st;
1547#endif
1548 const char *pfn; 1545 const char *pfn;
1549 1546
1550 encoded_fn = ENCODE_FILE (string); 1547 encoded_fn = ENCODE_FILE (string);
1551 pfn = SSDATA (encoded_fn); 1548 pfn = SSDATA (encoded_fn);
1552#ifdef WINDOWSNT
1553 exists = access (pfn, F_OK) == 0 && access (pfn, D_OK) < 0;
1554#else
1555 exists = (stat (pfn, &st) == 0 && ! S_ISDIR (st.st_mode));
1556#endif
1557 if (exists)
1558 {
1559 /* Check that we can access or open it. */
1560 if (NATNUMP (predicate))
1561 fd = (((XFASTINT (predicate) & ~INT_MAX) == 0
1562 && access (pfn, XFASTINT (predicate)) == 0)
1563 ? 1 : -1);
1564 else
1565 fd = emacs_open (pfn, O_RDONLY, 0);
1566 1549
1567 if (fd >= 0) 1550 /* Check that we can access or open it. */
1551 if (NATNUMP (predicate))
1552 fd = (((XFASTINT (predicate) & ~INT_MAX) == 0
1553 && (faccessat (AT_FDCWD, pfn, XFASTINT (predicate),
1554 AT_EACCESS)
1555 == 0)
1556 && ! file_directory_p (pfn))
1557 ? 1 : -1);
1558 else
1559 {
1560 struct stat st;
1561 fd = emacs_open (pfn, O_RDONLY, 0);
1562 if (0 <= fd
1563 && (fstat (fd, &st) != 0 || S_ISDIR (st.st_mode)))
1568 { 1564 {
1569 /* We succeeded; return this descriptor and filename. */ 1565 emacs_close (fd);
1570 if (storeptr) 1566 fd = -1;
1571 *storeptr = string;
1572 UNGCPRO;
1573 return fd;
1574 } 1567 }
1575 } 1568 }
1569
1570 if (fd >= 0)
1571 {
1572 /* We succeeded; return this descriptor and filename. */
1573 if (storeptr)
1574 *storeptr = string;
1575 UNGCPRO;
1576 return fd;
1577 }
1576 } 1578 }
1577 } 1579 }
1578 if (absolute) 1580 if (absolute)
@@ -4088,7 +4090,7 @@ load_path_check (void)
4088 if (STRINGP (dirfile)) 4090 if (STRINGP (dirfile))
4089 { 4091 {
4090 dirfile = Fdirectory_file_name (dirfile); 4092 dirfile = Fdirectory_file_name (dirfile);
4091 if (access (SSDATA (dirfile), 0) < 0) 4093 if (faccessat (AT_FDCWD, SSDATA (dirfile), F_OK, AT_EACCESS) != 0)
4092 dir_warning ("Warning: Lisp directory `%s' does not exist.\n", 4094 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4093 XCAR (path_tail)); 4095 XCAR (path_tail));
4094 } 4096 }
diff --git a/src/process.c b/src/process.c
index 307e82819d6..572ab83de09 100644
--- a/src/process.c
+++ b/src/process.c
@@ -204,7 +204,7 @@ static EMACS_INT update_tick;
204#ifndef NON_BLOCKING_CONNECT 204#ifndef NON_BLOCKING_CONNECT
205#ifdef HAVE_SELECT 205#ifdef HAVE_SELECT
206#if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) 206#if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX)
207#if defined (O_NONBLOCK) || defined (O_NDELAY) 207#if O_NONBLOCK || O_NDELAY
208#if defined (EWOULDBLOCK) || defined (EINPROGRESS) 208#if defined (EWOULDBLOCK) || defined (EINPROGRESS)
209#define NON_BLOCKING_CONNECT 209#define NON_BLOCKING_CONNECT
210#endif /* EWOULDBLOCK || EINPROGRESS */ 210#endif /* EWOULDBLOCK || EINPROGRESS */
@@ -651,7 +651,7 @@ allocate_pty (void)
651 PTY_OPEN; 651 PTY_OPEN;
652#else /* no PTY_OPEN */ 652#else /* no PTY_OPEN */
653 { 653 {
654# ifdef O_NONBLOCK 654# if O_NONBLOCK
655 fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0); 655 fd = emacs_open (pty_name, O_RDWR | O_NONBLOCK, 0);
656# else 656# else
657 fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0); 657 fd = emacs_open (pty_name, O_RDWR | O_NDELAY, 0);
@@ -668,7 +668,7 @@ allocate_pty (void)
668#else 668#else
669 sprintf (pty_name, "/dev/tty%c%x", c, i); 669 sprintf (pty_name, "/dev/tty%c%x", c, i);
670#endif /* no PTY_TTY_NAME_SPRINTF */ 670#endif /* no PTY_TTY_NAME_SPRINTF */
671 if (access (pty_name, 6) != 0) 671 if (faccessat (AT_FDCWD, pty_name, R_OK | W_OK, AT_EACCESS) != 0)
672 { 672 {
673 emacs_close (fd); 673 emacs_close (fd);
674# ifndef __sgi 674# ifndef __sgi
@@ -1621,7 +1621,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1621#if ! defined (USG) || defined (USG_SUBTTY_WORKS) 1621#if ! defined (USG) || defined (USG_SUBTTY_WORKS)
1622 /* On most USG systems it does not work to open the pty's tty here, 1622 /* On most USG systems it does not work to open the pty's tty here,
1623 then close it and reopen it in the child. */ 1623 then close it and reopen it in the child. */
1624#ifdef O_NOCTTY 1624#if O_NOCTTY
1625 /* Don't let this terminal become our controlling terminal 1625 /* Don't let this terminal become our controlling terminal
1626 (in case we don't have one). */ 1626 (in case we don't have one). */
1627 forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); 1627 forkout = forkin = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0);
@@ -1675,11 +1675,11 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1675 } 1675 }
1676#endif 1676#endif
1677 1677
1678#ifdef O_NONBLOCK 1678#if O_NONBLOCK
1679 fcntl (inchannel, F_SETFL, O_NONBLOCK); 1679 fcntl (inchannel, F_SETFL, O_NONBLOCK);
1680 fcntl (outchannel, F_SETFL, O_NONBLOCK); 1680 fcntl (outchannel, F_SETFL, O_NONBLOCK);
1681#else 1681#else
1682#ifdef O_NDELAY 1682#if O_NDELAY
1683 fcntl (inchannel, F_SETFL, O_NDELAY); 1683 fcntl (inchannel, F_SETFL, O_NDELAY);
1684 fcntl (outchannel, F_SETFL, O_NDELAY); 1684 fcntl (outchannel, F_SETFL, O_NDELAY);
1685#endif 1685#endif
@@ -1967,7 +1967,7 @@ create_pty (Lisp_Object process)
1967#if ! defined (USG) || defined (USG_SUBTTY_WORKS) 1967#if ! defined (USG) || defined (USG_SUBTTY_WORKS)
1968 /* On most USG systems it does not work to open the pty's tty here, 1968 /* On most USG systems it does not work to open the pty's tty here,
1969 then close it and reopen it in the child. */ 1969 then close it and reopen it in the child. */
1970#ifdef O_NOCTTY 1970#if O_NOCTTY
1971 /* Don't let this terminal become our controlling terminal 1971 /* Don't let this terminal become our controlling terminal
1972 (in case we don't have one). */ 1972 (in case we don't have one). */
1973 int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0); 1973 int forkout = emacs_open (pty_name, O_RDWR | O_NOCTTY, 0);
@@ -1987,11 +1987,11 @@ create_pty (Lisp_Object process)
1987 } 1987 }
1988#endif /* HAVE_PTYS */ 1988#endif /* HAVE_PTYS */
1989 1989
1990#ifdef O_NONBLOCK 1990#if O_NONBLOCK
1991 fcntl (inchannel, F_SETFL, O_NONBLOCK); 1991 fcntl (inchannel, F_SETFL, O_NONBLOCK);
1992 fcntl (outchannel, F_SETFL, O_NONBLOCK); 1992 fcntl (outchannel, F_SETFL, O_NONBLOCK);
1993#else 1993#else
1994#ifdef O_NDELAY 1994#if O_NDELAY
1995 fcntl (inchannel, F_SETFL, O_NDELAY); 1995 fcntl (inchannel, F_SETFL, O_NDELAY);
1996 fcntl (outchannel, F_SETFL, O_NDELAY); 1996 fcntl (outchannel, F_SETFL, O_NDELAY);
1997#endif 1997#endif
@@ -2951,7 +2951,7 @@ usage: (make-network-process &rest ARGS) */)
2951 { 2951 {
2952 /* Don't support network sockets when non-blocking mode is 2952 /* Don't support network sockets when non-blocking mode is
2953 not available, since a blocked Emacs is not useful. */ 2953 not available, since a blocked Emacs is not useful. */
2954#if !defined (O_NONBLOCK) && !defined (O_NDELAY) 2954#if !O_NONBLOCK && !O_NDELAY
2955 error ("Network servers not supported"); 2955 error ("Network servers not supported");
2956#else 2956#else
2957 is_server = 1; 2957 is_server = 1;
@@ -3217,7 +3217,7 @@ usage: (make-network-process &rest ARGS) */)
3217#ifdef NON_BLOCKING_CONNECT 3217#ifdef NON_BLOCKING_CONNECT
3218 if (is_non_blocking_client) 3218 if (is_non_blocking_client)
3219 { 3219 {
3220#ifdef O_NONBLOCK 3220#if O_NONBLOCK
3221 ret = fcntl (s, F_SETFL, O_NONBLOCK); 3221 ret = fcntl (s, F_SETFL, O_NONBLOCK);
3222#else 3222#else
3223 ret = fcntl (s, F_SETFL, O_NDELAY); 3223 ret = fcntl (s, F_SETFL, O_NDELAY);
@@ -3434,10 +3434,10 @@ usage: (make-network-process &rest ARGS) */)
3434 3434
3435 chan_process[inch] = proc; 3435 chan_process[inch] = proc;
3436 3436
3437#ifdef O_NONBLOCK 3437#if O_NONBLOCK
3438 fcntl (inch, F_SETFL, O_NONBLOCK); 3438 fcntl (inch, F_SETFL, O_NONBLOCK);
3439#else 3439#else
3440#ifdef O_NDELAY 3440#if O_NDELAY
3441 fcntl (inch, F_SETFL, O_NDELAY); 3441 fcntl (inch, F_SETFL, O_NDELAY);
3442#endif 3442#endif
3443#endif 3443#endif
@@ -4169,10 +4169,10 @@ server_accept_connection (Lisp_Object server, int channel)
4169 4169
4170 chan_process[s] = proc; 4170 chan_process[s] = proc;
4171 4171
4172#ifdef O_NONBLOCK 4172#if O_NONBLOCK
4173 fcntl (s, F_SETFL, O_NONBLOCK); 4173 fcntl (s, F_SETFL, O_NONBLOCK);
4174#else 4174#else
4175#ifdef O_NDELAY 4175#if O_NDELAY
4176 fcntl (s, F_SETFL, O_NDELAY); 4176 fcntl (s, F_SETFL, O_NDELAY);
4177#endif 4177#endif
4178#endif 4178#endif
@@ -4873,11 +4873,11 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd,
4873#endif 4873#endif
4874 /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK, 4874 /* ISC 4.1 defines both EWOULDBLOCK and O_NONBLOCK,
4875 and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */ 4875 and Emacs uses O_NONBLOCK, so what we get is EAGAIN. */
4876#ifdef O_NONBLOCK 4876#if O_NONBLOCK
4877 else if (nread == -1 && errno == EAGAIN) 4877 else if (nread == -1 && errno == EAGAIN)
4878 ; 4878 ;
4879#else 4879#else
4880#ifdef O_NDELAY 4880#if O_NDELAY
4881 else if (nread == -1 && errno == EAGAIN) 4881 else if (nread == -1 && errno == EAGAIN)
4882 ; 4882 ;
4883 /* Note that we cannot distinguish between no input 4883 /* Note that we cannot distinguish between no input
@@ -7363,7 +7363,7 @@ init_process_emacs (void)
7363#ifdef HAVE_GETSOCKNAME 7363#ifdef HAVE_GETSOCKNAME
7364 ADD_SUBFEATURE (QCservice, Qt); 7364 ADD_SUBFEATURE (QCservice, Qt);
7365#endif 7365#endif
7366#if defined (O_NONBLOCK) || defined (O_NDELAY) 7366#if O_NONBLOCK || O_NDELAY
7367 ADD_SUBFEATURE (QCserver, Qt); 7367 ADD_SUBFEATURE (QCserver, Qt);
7368#endif 7368#endif
7369 7369
diff --git a/src/sysdep.c b/src/sysdep.c
index 35beeaa7202..8a31957d182 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1216,7 +1216,7 @@ reset_sys_modes (struct tty_display_info *tty_out)
1216 old_fcntl_owner[fileno (tty_out->input)]); 1216 old_fcntl_owner[fileno (tty_out->input)]);
1217 } 1217 }
1218#endif /* F_SETOWN */ 1218#endif /* F_SETOWN */
1219#ifdef O_NDELAY 1219#if O_NDELAY
1220 fcntl (fileno (tty_out->input), F_SETFL, 1220 fcntl (fileno (tty_out->input), F_SETFL,
1221 fcntl (fileno (tty_out->input), F_GETFL, 0) & ~O_NDELAY); 1221 fcntl (fileno (tty_out->input), F_GETFL, 0) & ~O_NDELAY);
1222#endif 1222#endif
@@ -2312,12 +2312,12 @@ serial_open (char *port)
2312 2312
2313 fd = emacs_open ((char*) port, 2313 fd = emacs_open ((char*) port,
2314 O_RDWR 2314 O_RDWR
2315#ifdef O_NONBLOCK 2315#if O_NONBLOCK
2316 | O_NONBLOCK 2316 | O_NONBLOCK
2317#else 2317#else
2318 | O_NDELAY 2318 | O_NDELAY
2319#endif 2319#endif
2320#ifdef O_NOCTTY 2320#if O_NOCTTY
2321 | O_NOCTTY 2321 | O_NOCTTY
2322#endif 2322#endif
2323 , 0); 2323 , 0);
diff --git a/src/term.c b/src/term.c
index f7c87b7608d..87ce5447b76 100644
--- a/src/term.c
+++ b/src/term.c
@@ -3023,7 +3023,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed)
3023 int fd; 3023 int fd;
3024 FILE *file; 3024 FILE *file;
3025 3025
3026#ifdef O_IGNORE_CTTY 3026#if O_IGNORE_CTTY
3027 if (!ctty) 3027 if (!ctty)
3028 /* Open the terminal device. Don't recognize it as our 3028 /* Open the terminal device. Don't recognize it as our
3029 controlling terminal, and don't make it the controlling tty 3029 controlling terminal, and don't make it the controlling tty
@@ -3054,7 +3054,7 @@ init_tty (const char *name, const char *terminal_type, int must_succeed)
3054 name); 3054 name);
3055 } 3055 }
3056 3056
3057#ifndef O_IGNORE_CTTY 3057#if !O_IGNORE_CTTY
3058 if (!ctty) 3058 if (!ctty)
3059 dissociate_if_controlling_tty (fd); 3059 dissociate_if_controlling_tty (fd);
3060#endif 3060#endif
diff --git a/src/w32.c b/src/w32.c
index 5ac1bc3eb7c..341f4d3fef3 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1597,7 +1597,7 @@ init_environment (char ** argv)
1597 see if it succeeds. But I think that's too much to ask. */ 1597 see if it succeeds. But I think that's too much to ask. */
1598 1598
1599 /* MSVCRT's _access crashes with D_OK. */ 1599 /* MSVCRT's _access crashes with D_OK. */
1600 if (tmp && sys_access (tmp, D_OK) == 0) 1600 if (tmp && sys_faccessat (AT_FDCWD, tmp, D_OK, AT_EACCESS) == 0)
1601 { 1601 {
1602 char * var = alloca (strlen (tmp) + 8); 1602 char * var = alloca (strlen (tmp) + 8);
1603 sprintf (var, "TMPDIR=%s", tmp); 1603 sprintf (var, "TMPDIR=%s", tmp);
@@ -2714,10 +2714,16 @@ logon_network_drive (const char *path)
2714 long file names. */ 2714 long file names. */
2715 2715
2716int 2716int
2717sys_access (const char * path, int mode) 2717sys_faccessat (int dirfd, const char * path, int mode, int flags)
2718{ 2718{
2719 DWORD attributes; 2719 DWORD attributes;
2720 2720
2721 if (dirfd != AT_FDCWD)
2722 {
2723 errno = EINVAL;
2724 return -1;
2725 }
2726
2721 /* MSVCRT implementation of 'access' doesn't recognize D_OK, and its 2727 /* MSVCRT implementation of 'access' doesn't recognize D_OK, and its
2722 newer versions blow up when passed D_OK. */ 2728 newer versions blow up when passed D_OK. */
2723 path = map_w32_filename (path, NULL); 2729 path = map_w32_filename (path, NULL);
@@ -2960,7 +2966,7 @@ sys_mktemp (char * template)
2960 { 2966 {
2961 int save_errno = errno; 2967 int save_errno = errno;
2962 p[0] = first_char[i]; 2968 p[0] = first_char[i];
2963 if (sys_access (template, 0) < 0) 2969 if (sys_faccessat (AT_FDCWD, template, F_OK, AT_EACCESS) < 0)
2964 { 2970 {
2965 errno = save_errno; 2971 errno = save_errno;
2966 return template; 2972 return template;
@@ -4011,7 +4017,7 @@ symlink (char const *filename, char const *linkname)
4011 { 4017 {
4012 /* Non-absolute FILENAME is understood as being relative to 4018 /* Non-absolute FILENAME is understood as being relative to
4013 LINKNAME's directory. We need to prepend that directory to 4019 LINKNAME's directory. We need to prepend that directory to
4014 FILENAME to get correct results from sys_access below, since 4020 FILENAME to get correct results from sys_faccessat below, since
4015 otherwise it will interpret FILENAME relative to the 4021 otherwise it will interpret FILENAME relative to the
4016 directory where the Emacs process runs. Note that 4022 directory where the Emacs process runs. Note that
4017 make-symbolic-link always makes sure LINKNAME is a fully 4023 make-symbolic-link always makes sure LINKNAME is a fully
@@ -4025,10 +4031,10 @@ symlink (char const *filename, char const *linkname)
4025 strncpy (tem, linkfn, p - linkfn); 4031 strncpy (tem, linkfn, p - linkfn);
4026 tem[p - linkfn] = '\0'; 4032 tem[p - linkfn] = '\0';
4027 strcat (tem, filename); 4033 strcat (tem, filename);
4028 dir_access = sys_access (tem, D_OK); 4034 dir_access = sys_faccessat (AT_FDCWD, tem, D_OK, AT_EACCESS);
4029 } 4035 }
4030 else 4036 else
4031 dir_access = sys_access (filename, D_OK); 4037 dir_access = sys_faccessat (AT_FDCWD, filename, D_OK, AT_EACCESS);
4032 4038
4033 /* Since Windows distinguishes between symlinks to directories and 4039 /* Since Windows distinguishes between symlinks to directories and
4034 to files, we provide a kludgy feature: if FILENAME doesn't 4040 to files, we provide a kludgy feature: if FILENAME doesn't
diff --git a/src/xrdb.c b/src/xrdb.c
index 9d056a607e4..982a6e46a13 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -21,6 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 21
22#include <config.h> 22#include <config.h>
23 23
24#include <fcntl.h>
24#include <unistd.h> 25#include <unistd.h>
25#include <errno.h> 26#include <errno.h>
26#include <epaths.h> 27#include <epaths.h>
@@ -261,11 +262,8 @@ gethomedir (void)
261static int 262static int
262file_p (const char *filename) 263file_p (const char *filename)
263{ 264{
264 struct stat status; 265 return (faccessat (AT_FDCWD, filename, R_OK, AT_EACCESS) == 0
265 266 && ! file_directory_p (filename));
266 return (access (filename, 4) == 0 /* exists and is readable */
267 && stat (filename, &status) == 0 /* get the status */
268 && (S_ISDIR (status.st_mode)) == 0); /* not a directory */
269} 267}
270 268
271 269