mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-28 22:18:29 +00:00
Polyfill Linux unlink() EISDIR on POSIX platforms
This commit is contained in:
parent
9fce2751c8
commit
9634227181
1 changed files with 16 additions and 0 deletions
|
@ -17,13 +17,16 @@
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/calls/calls.h"
|
#include "libc/calls/calls.h"
|
||||||
|
#include "libc/calls/struct/stat.h"
|
||||||
#include "libc/calls/syscall-nt.internal.h"
|
#include "libc/calls/syscall-nt.internal.h"
|
||||||
#include "libc/calls/syscall-sysv.internal.h"
|
#include "libc/calls/syscall-sysv.internal.h"
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
|
#include "libc/errno.h"
|
||||||
#include "libc/intrin/asan.internal.h"
|
#include "libc/intrin/asan.internal.h"
|
||||||
#include "libc/intrin/describeflags.internal.h"
|
#include "libc/intrin/describeflags.internal.h"
|
||||||
#include "libc/intrin/strace.internal.h"
|
#include "libc/intrin/strace.internal.h"
|
||||||
#include "libc/intrin/weaken.h"
|
#include "libc/intrin/weaken.h"
|
||||||
|
#include "libc/sysv/consts/s.h"
|
||||||
#include "libc/sysv/errfuns.h"
|
#include "libc/sysv/errfuns.h"
|
||||||
#include "libc/zipos/zipos.internal.h"
|
#include "libc/zipos/zipos.internal.h"
|
||||||
|
|
||||||
|
@ -40,6 +43,7 @@
|
||||||
*/
|
*/
|
||||||
int unlinkat(int dirfd, const char *path, int flags) {
|
int unlinkat(int dirfd, const char *path, int flags) {
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (IsAsan() && !__asan_is_valid_str(path)) {
|
if (IsAsan() && !__asan_is_valid_str(path)) {
|
||||||
rc = efault();
|
rc = efault();
|
||||||
} else if (_weaken(__zipos_notat) &&
|
} else if (_weaken(__zipos_notat) &&
|
||||||
|
@ -50,6 +54,18 @@ int unlinkat(int dirfd, const char *path, int flags) {
|
||||||
} else {
|
} else {
|
||||||
rc = sys_unlinkat_nt(dirfd, path, flags);
|
rc = sys_unlinkat_nt(dirfd, path, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// POSIX.1 says unlink(directory) raises EPERM but on Linux
|
||||||
|
// it always raises EISDIR, which is so much less ambiguous
|
||||||
|
if (!IsLinux() && rc == -1 && !flags && errno == EPERM) {
|
||||||
|
struct stat st;
|
||||||
|
if (!fstatat(dirfd, path, &st, 0) && S_ISDIR(st.st_mode)) {
|
||||||
|
errno = EISDIR;
|
||||||
|
} else {
|
||||||
|
errno = EPERM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
STRACE("unlinkat(%s, %#s, %#b) → %d% m", DescribeDirfd(dirfd), path, flags,
|
STRACE("unlinkat(%s, %#s, %#b) → %d% m", DescribeDirfd(dirfd), path, flags,
|
||||||
rc);
|
rc);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Add table
Reference in a new issue