diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h index 2b0ea83e..f621c4e1 100644 --- a/libc/include/fcntl.h +++ b/libc/include/fcntl.h @@ -38,11 +38,7 @@ __BEGIN_DECLS /* TODO: F_RDLCK, F_UNLCK, F_WRLCK missing here */ -/* TODO: AT_FDCWD missing here */ -/* TODO: AT_EACCESS missing here */ -/* TODO: AT_SYMLINK_NOFOLLOW missing here */ /* TODO: AT_SYMLINK_FOLLOW missing here */ -/* TODO: AT_REMOVEDIR missing here */ /* TODO: POSIX_FADV_* missing here */ diff --git a/sortix/include/sortix/fcntl.h b/sortix/include/sortix/fcntl.h index 3d88843d..18c79eba 100644 --- a/sortix/include/sortix/fcntl.h +++ b/sortix/include/sortix/fcntl.h @@ -58,6 +58,7 @@ __BEGIN_DECLS #define AT_REMOVEDIR (1<<0) #define AT_EACCESS (1<<1) #define AT_SYMLINK_NOFOLLOW (1<<2) +#define AT_REMOVEFILE (1<<3) __END_DECLS diff --git a/sortix/io.cpp b/sortix/io.cpp index 30db8f38..66e4b790 100644 --- a/sortix/io.cpp +++ b/sortix/io.cpp @@ -183,6 +183,8 @@ static int sys_access(const char* path, int mode) static int sys_unlinkat(int dirfd, const char* path, int flags) { + if ( !(flags & (AT_REMOVEFILE | AT_REMOVEDIR)) ) + flags |= AT_REMOVEFILE; char* pathcopy = GetStringFromUser(path); if ( !pathcopy ) return -1; @@ -190,11 +192,11 @@ static int sys_unlinkat(int dirfd, const char* path, int flags) const char* relpath = pathcopy; Ref from = PrepareLookup(&relpath, dirfd); if ( !from ) { delete[] pathcopy; return -1; } - int ret; - if ( flags & AT_REMOVEDIR ) - ret = from->rmdir(&ctx, relpath); - else + int ret = -1; + if ( ret < 0 && (flags & AT_REMOVEFILE) ) ret = from->unlink(&ctx, relpath); + if ( ret < 0 && (flags & AT_REMOVEDIR) ) + ret = from->rmdir(&ctx, relpath); delete[] pathcopy; return ret; }