diff options
| author | Eli Zaretskii | 2022-04-17 22:03:52 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2022-04-17 22:03:52 +0300 |
| commit | c2f94f32b5e8f57e2b4e723c9799cf0e5f5e5bcc (patch) | |
| tree | 656aa67a529748a6ad1b5282c5c7794adfda98c7 /src | |
| parent | 3cccf0a9107d585173e527550bbc45253624ca2e (diff) | |
| download | emacs-c2f94f32b5e8f57e2b4e723c9799cf0e5f5e5bcc.tar.gz emacs-c2f94f32b5e8f57e2b4e723c9799cf0e5f5e5bcc.zip | |
Revert "Don’t assume openat"
This reverts commit 3cccf0a9107d585173e527550bbc45253624ca2e.
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/sysdep.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index f6d139421af..72be25f6610 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -2302,20 +2302,6 @@ emacs_fstatat (int dirfd, char const *filename, void *st, int flags) | |||
| 2302 | return r; | 2302 | return r; |
| 2303 | } | 2303 | } |
| 2304 | 2304 | ||
| 2305 | static int | ||
| 2306 | sys_openat (int dirfd, char const *file, int oflags, int mode) | ||
| 2307 | { | ||
| 2308 | #ifdef O_PATH | ||
| 2309 | return openat (dirfd, file, oflags, mode); | ||
| 2310 | #else | ||
| 2311 | /* On platforms without O_PATH, emacs_openat's callers arrange for | ||
| 2312 | DIRFD to be AT_FDCWD, so it should be safe to just call 'open'. | ||
| 2313 | This ports to old platforms like OS X 10.9 that lack openat. */ | ||
| 2314 | eassert (dirfd == AT_FDCWD); | ||
| 2315 | return open (file, oflags, mode); | ||
| 2316 | #endif | ||
| 2317 | } | ||
| 2318 | |||
| 2319 | /* Assuming the directory DIRFD, open FILE for Emacs use, | 2305 | /* Assuming the directory DIRFD, open FILE for Emacs use, |
| 2320 | using open flags OFLAGS and mode MODE. | 2306 | using open flags OFLAGS and mode MODE. |
| 2321 | Use binary I/O on systems that care about text vs binary I/O. | 2307 | 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) | |||
| 2331 | if (! (oflags & O_TEXT)) | 2317 | if (! (oflags & O_TEXT)) |
| 2332 | oflags |= O_BINARY; | 2318 | oflags |= O_BINARY; |
| 2333 | oflags |= O_CLOEXEC; | 2319 | oflags |= O_CLOEXEC; |
| 2334 | while ((fd = sys_openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR) | 2320 | while ((fd = openat (dirfd, file, oflags, mode)) < 0 && errno == EINTR) |
| 2335 | maybe_quit (); | 2321 | maybe_quit (); |
| 2336 | return fd; | 2322 | return fd; |
| 2337 | } | 2323 | } |
| @@ -2344,19 +2330,26 @@ emacs_open (char const *file, int oflags, int mode) | |||
| 2344 | 2330 | ||
| 2345 | /* Same as above, but doesn't allow the user to quit. */ | 2331 | /* Same as above, but doesn't allow the user to quit. */ |
| 2346 | 2332 | ||
| 2347 | int | 2333 | static int |
| 2348 | emacs_open_noquit (char const *file, int oflags, int mode) | 2334 | emacs_openat_noquit (int dirfd, const char *file, int oflags, |
| 2335 | int mode) | ||
| 2349 | { | 2336 | { |
| 2350 | int fd; | 2337 | int fd; |
| 2351 | if (! (oflags & O_TEXT)) | 2338 | if (! (oflags & O_TEXT)) |
| 2352 | oflags |= O_BINARY; | 2339 | oflags |= O_BINARY; |
| 2353 | oflags |= O_CLOEXEC; | 2340 | oflags |= O_CLOEXEC; |
| 2354 | do | 2341 | do |
| 2355 | fd = open (file, oflags, mode); | 2342 | fd = openat (dirfd, file, oflags, mode); |
| 2356 | while (fd < 0 && errno == EINTR); | 2343 | while (fd < 0 && errno == EINTR); |
| 2357 | return fd; | 2344 | return fd; |
| 2358 | } | 2345 | } |
| 2359 | 2346 | ||
| 2347 | int | ||
| 2348 | emacs_open_noquit (char const *file, int oflags, int mode) | ||
| 2349 | { | ||
| 2350 | return emacs_openat_noquit (AT_FDCWD, file, oflags, mode); | ||
| 2351 | } | ||
| 2352 | |||
| 2360 | /* Open FILE as a stream for Emacs use, with mode MODE. | 2353 | /* Open FILE as a stream for Emacs use, with mode MODE. |
| 2361 | Act like emacs_open with respect to threads, signals, and quits. */ | 2354 | Act like emacs_open with respect to threads, signals, and quits. */ |
| 2362 | 2355 | ||