summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-04-17 10:41:17 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2022-04-17 10:43:13 -0700
commit3cccf0a9107d585173e527550bbc45253624ca2e (patch)
tree84f2ace0970fde0dc3c9863755eba8379574ffcf /src
parent4641bc1c550a81c71798c0176a6bfc34c8947c74 (diff)
downloademacs-3cccf0a9107d585173e527550bbc45253624ca2e.tar.gz
Don’t assume openat
Use openat only on platforms with O_PATH. This ports to OS X 10.9 and earlier. Problem reported by Keith David Bershatsky in: https://lists.gnu.org/r/emacs-devel/2022-04/msg00805.html * lib-src/emacsclient.c (local_sockname): Use open, not openat. * src/sysdep.c (sys_openat): New static function, which uses openat only if O_PATH is defined. (emacs_openat): Use it instead of openat. (emacs_openat_noquit): Remove. (emacs_open_noquit): Reimplement as per the old emacs_openat_noquit, but use plain 'open'.
Diffstat (limited to 'src')
-rw-r--r--src/sysdep.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index 72be25f6610..f6d139421af 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2302,6 +2302,20 @@ emacs_fstatat (int dirfd, char const *filename, void *st, int flags)
return r;
}
+static int
+sys_openat (int dirfd, char const *file, int oflags, int mode)
+{
+#ifdef O_PATH
+ return openat (dirfd, file, oflags, mode);
+#else
+ /* On platforms without O_PATH, emacs_openat's callers arrange for
+ DIRFD to be AT_FDCWD, so it should be safe to just call 'open'.
+ This ports to old platforms like OS X 10.9 that lack openat. */
+ eassert (dirfd == AT_FDCWD);
+ return open (file, oflags, mode);
+#endif
+}
+
/* Assuming the directory DIRFD, open FILE for Emacs use,
using open flags OFLAGS and mode MODE.
Use binary I/O on systems that care about text vs binary I/O.
@@ -2317,7 +2331,7 @@ emacs_openat (int dirfd, char const *file, int oflags, int mode)
if (! (oflags & O_TEXT))
oflags |= O_BINARY;
oflags |= O_CLOEXEC;
- while ((fd = openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR)
+ while ((fd = sys_openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR)
maybe_quit ();
return fd;
}
@@ -2330,26 +2344,19 @@ emacs_open (char const *file, int oflags, int mode)
/* Same as above, but doesn't allow the user to quit. */
-static int
-emacs_openat_noquit (int dirfd, const char *file, int oflags,
- int mode)
+int
+emacs_open_noquit (char const *file, int oflags, int mode)
{
int fd;
if (! (oflags & O_TEXT))
oflags |= O_BINARY;
oflags |= O_CLOEXEC;
do
- fd = openat (dirfd, file, oflags, mode);
+ fd = open (file, oflags, mode);
while (fd < 0 && errno == EINTR);
return fd;
}
-int
-emacs_open_noquit (char const *file, int oflags, int mode)
-{
- return emacs_openat_noquit (AT_FDCWD, file, oflags, mode);
-}
-
/* Open FILE as a stream for Emacs use, with mode MODE.
Act like emacs_open with respect to threads, signals, and quits. */