Revert "Don’t assume openat"

This reverts commit 3cccf0a910.

This is a change with far-reaching effects on MS-Windows at the least,
where file-related APIs are shadowed to support transparent support
for UTF-8 encoded file names.  Making such changes on a stable branch
for the benefit of a proprietary platform with a 13-year old OS is a
tail wagging the dog.  Please don't do that without discussing first.
This commit is contained in:
Eli Zaretskii 2022-04-17 22:03:52 +03:00
parent 3cccf0a910
commit c2f94f32b5
2 changed files with 13 additions and 19 deletions

View file

@ -1412,7 +1412,8 @@ local_sockname (int s, char sockname[socknamesize], int tmpdirlen,
char *emacsdirend = sockname + tmpdirlen + suffixlen - char *emacsdirend = sockname + tmpdirlen + suffixlen -
strlen(server_name) - 1; strlen(server_name) - 1;
*emacsdirend = '\0'; *emacsdirend = '\0';
int dir = open (sockname, O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); int dir = openat (AT_FDCWD, sockname,
O_PATH | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);
*emacsdirend = '/'; *emacsdirend = '/';
if (dir < 0) if (dir < 0)
return errno; return errno;

View file

@ -2302,20 +2302,6 @@ emacs_fstatat (int dirfd, char const *filename, void *st, int flags)
return r; 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, /* Assuming the directory DIRFD, open FILE for Emacs use,
using open flags OFLAGS and mode MODE. using open flags OFLAGS and mode MODE.
Use binary I/O on systems that care about text vs binary I/O. Use binary I/O on systems that care about text vs binary I/O.
@ -2331,7 +2317,7 @@ emacs_openat (int dirfd, char const *file, int oflags, int mode)
if (! (oflags & O_TEXT)) if (! (oflags & O_TEXT))
oflags |= O_BINARY; oflags |= O_BINARY;
oflags |= O_CLOEXEC; oflags |= O_CLOEXEC;
while ((fd = sys_openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR) while ((fd = openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR)
maybe_quit (); maybe_quit ();
return fd; return fd;
} }
@ -2344,19 +2330,26 @@ emacs_open (char const *file, int oflags, int mode)
/* Same as above, but doesn't allow the user to quit. */ /* Same as above, but doesn't allow the user to quit. */
int static int
emacs_open_noquit (char const *file, int oflags, int mode) emacs_openat_noquit (int dirfd, const char *file, int oflags,
int mode)
{ {
int fd; int fd;
if (! (oflags & O_TEXT)) if (! (oflags & O_TEXT))
oflags |= O_BINARY; oflags |= O_BINARY;
oflags |= O_CLOEXEC; oflags |= O_CLOEXEC;
do do
fd = open (file, oflags, mode); fd = openat (dirfd, file, oflags, mode);
while (fd < 0 && errno == EINTR); while (fd < 0 && errno == EINTR);
return fd; 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. /* Open FILE as a stream for Emacs use, with mode MODE.
Act like emacs_open with respect to threads, signals, and quits. */ Act like emacs_open with respect to threads, signals, and quits. */