diff --git a/src/system/libroot/os/fs_attr.cpp b/src/system/libroot/os/fs_attr.cpp index cc32dcf997..adf882866f 100644 --- a/src/system/libroot/os/fs_attr.cpp +++ b/src/system/libroot/os/fs_attr.cpp @@ -96,7 +96,7 @@ fs_stat_attr(int fd, const char* attribute, struct attr_info* attrInfo) int fs_open_attr(const char *path, const char *attribute, uint32 type, int openMode) { - status_t status = _kern_open_attr(-1, path, attribute, type, openMode); + status_t status = _kern_open_attr(AT_FDCWD, path, attribute, type, openMode); RETURN_AND_SET_ERRNO(status); } @@ -121,14 +121,14 @@ fs_close_attr(int fd) extern "C" DIR* fs_open_attr_dir(const char* path) { - return open_attr_dir(-1, path, true); + return open_attr_dir(AT_FDCWD, path, true); } extern "C" DIR* fs_lopen_attr_dir(const char* path) { - return open_attr_dir(-1, path, false); + return open_attr_dir(AT_FDCWD, path, false); } extern "C" DIR* @@ -157,4 +157,3 @@ fs_rewind_attr_dir(DIR* dir) { rewinddir(dir); } - diff --git a/src/system/libroot/os/fs_info.cpp b/src/system/libroot/os/fs_info.cpp index 8718ae3e2c..25b0ea528c 100644 --- a/src/system/libroot/os/fs_info.cpp +++ b/src/system/libroot/os/fs_info.cpp @@ -20,7 +20,7 @@ dev_t dev_for_path(const char *path) { struct stat stat; - int status = _kern_read_stat(-1, path, true, &stat, sizeof(struct stat)); + int status = _kern_read_stat(AT_FDCWD, path, true, &stat, sizeof(struct stat)); if (status == B_OK) return stat.st_dev; @@ -65,5 +65,3 @@ fs_stat_dev(dev_t device, fs_info *info) RETURN_AND_SET_ERRNO(status); } - - diff --git a/src/system/libroot/posix/dirent.cpp b/src/system/libroot/posix/dirent.cpp index aa8b882f8a..f7dbc1e7fd 100644 --- a/src/system/libroot/posix/dirent.cpp +++ b/src/system/libroot/posix/dirent.cpp @@ -164,7 +164,7 @@ opendir(const char* path) { DIR* dir; - int fd = _kern_open_dir(-1, path); + int fd = _kern_open_dir(AT_FDCWD, path); if (fd < 0) { __set_errno(fd); return NULL; diff --git a/src/system/libroot/posix/fcntl.cpp b/src/system/libroot/posix/fcntl.cpp index 0bfa7f9977..fc85356e05 100644 --- a/src/system/libroot/posix/fcntl.cpp +++ b/src/system/libroot/posix/fcntl.cpp @@ -23,7 +23,7 @@ int creat(const char *path, mode_t mode) { RETURN_AND_SET_ERRNO_TEST_CANCEL( - _kern_open(-1, path, O_CREAT | O_TRUNC | O_WRONLY, mode & ~__gUmask)); + _kern_open(AT_FDCWD, path, O_CREAT | O_TRUNC | O_WRONLY, mode & ~__gUmask)); // adapt the permissions as required by POSIX } @@ -40,7 +40,7 @@ open(const char *path, int openMode, ...) va_end(args); } - RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_open(-1, path, openMode, perms)); + RETURN_AND_SET_ERRNO_TEST_CANCEL(_kern_open(AT_FDCWD, path, openMode, perms)); } diff --git a/src/system/libroot/posix/stdio/remove.c b/src/system/libroot/posix/stdio/remove.c index 856942d6fd..1e6d757ecb 100644 --- a/src/system/libroot/posix/stdio/remove.c +++ b/src/system/libroot/posix/stdio/remove.c @@ -16,9 +16,9 @@ int remove(const char* path) { // TODO: find a better way that does not require two syscalls for directories - int status = _kern_unlink(-1, path); + int status = _kern_unlink(AT_FDCWD, path); if (status == B_IS_A_DIRECTORY) - status = _kern_remove_dir(-1, path); + status = _kern_remove_dir(AT_FDCWD, path); if (status != B_OK) { __set_errno(status); @@ -27,4 +27,3 @@ remove(const char* path) return status; } - diff --git a/src/system/libroot/posix/stdio/rename.c b/src/system/libroot/posix/stdio/rename.c index 339af4de30..bf15e437d9 100644 --- a/src/system/libroot/posix/stdio/rename.c +++ b/src/system/libroot/posix/stdio/rename.c @@ -15,7 +15,7 @@ int rename(const char *from, const char *to) { - RETURN_AND_SET_ERRNO(_kern_rename(-1, from, -1, to)); + return renameat(AT_FDCWD, from, AT_FDCWD, to); } diff --git a/src/system/libroot/posix/sys/chmod.c b/src/system/libroot/posix/sys/chmod.c index 95305e48b1..73f03673f0 100644 --- a/src/system/libroot/posix/sys/chmod.c +++ b/src/system/libroot/posix/sys/chmod.c @@ -21,7 +21,7 @@ chmod(const char *path, mode_t mode) status_t status; stat.st_mode = mode; - status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat), + status = _kern_write_stat(AT_FDCWD, path, true, &stat, sizeof(struct stat), B_STAT_MODE); RETURN_AND_SET_ERRNO(status); diff --git a/src/system/libroot/posix/sys/mkdir.c b/src/system/libroot/posix/sys/mkdir.c index 5731968910..5f7817511a 100644 --- a/src/system/libroot/posix/sys/mkdir.c +++ b/src/system/libroot/posix/sys/mkdir.c @@ -16,7 +16,7 @@ int mkdir(const char* path, mode_t mode) { - RETURN_AND_SET_ERRNO(_kern_create_dir(-1, path, mode & ~__gUmask)); + return mkdirat(AT_FDCWD, path, mode); } diff --git a/src/system/libroot/posix/sys/stat.c b/src/system/libroot/posix/sys/stat.c index 2fc29662d4..09bd010b45 100644 --- a/src/system/libroot/posix/sys/stat.c +++ b/src/system/libroot/posix/sys/stat.c @@ -28,37 +28,32 @@ int _lstat_beos(const char* path, struct stat_beos* beosStat); int _stat_current(const char* path, struct stat* stat) { - int status = _kern_read_stat(-1, path, true, stat, sizeof(struct stat)); - - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO(_kern_read_stat(AT_FDCWD, path, true, + stat, sizeof(struct stat))); } int _fstat_current(int fd, struct stat* stat) { - int status = _kern_read_stat(fd, NULL, false, stat, sizeof(struct stat)); - - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO(_kern_read_stat(fd, NULL, false, + stat, sizeof(struct stat))); } int _lstat_current(const char* path, struct stat* stat) { - int status = _kern_read_stat(-1, path, false, stat, sizeof(struct stat)); - - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO(_kern_read_stat(AT_FDCWD, path, false, + stat, sizeof(struct stat))); } int -fstatat(int fd, const char *path, struct stat *st, int flag) +fstatat(int fd, const char* path, struct stat* stat, int flag) { - int status = _kern_read_stat(fd, path, (flag & AT_SYMLINK_NOFOLLOW) == 0, - st, sizeof(struct stat)); - - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO(_kern_read_stat(fd, path, (flag & AT_SYMLINK_NOFOLLOW) == 0, + stat, sizeof(struct stat))); } diff --git a/src/system/libroot/posix/sys/utimes.c b/src/system/libroot/posix/sys/utimes.c index feae3bd6bc..d3bd806a1c 100644 --- a/src/system/libroot/posix/sys/utimes.c +++ b/src/system/libroot/posix/sys/utimes.c @@ -39,7 +39,7 @@ _utimes(const char* path, const struct timeval times[2], bool traverseLink) } // traverseLeafLink == true - status = _kern_write_stat(-1, path, traverseLink, &stat, + status = _kern_write_stat(AT_FDCWD, path, traverseLink, &stat, sizeof(struct stat), B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME); RETURN_AND_SET_ERRNO(status); diff --git a/src/system/libroot/posix/unistd/access.c b/src/system/libroot/posix/unistd/access.c index dbc14b917c..5b8e5eb9f9 100644 --- a/src/system/libroot/posix/unistd/access.c +++ b/src/system/libroot/posix/unistd/access.c @@ -15,17 +15,13 @@ int access(const char* path, int accessMode) { - status_t status = _kern_access(-1, path, accessMode, false); - - RETURN_AND_SET_ERRNO(status); + return faccessat(AT_FDCWD, path, accessMode, 0); } int faccessat(int fd, const char* path, int accessMode, int flag) { - status_t status = _kern_access(fd, path, accessMode, - (flag & AT_EACCESS) != 0); - - RETURN_AND_SET_ERRNO(status); + RETURN_AND_SET_ERRNO(_kern_access(fd, path, accessMode, + (flag & AT_EACCESS) != 0)); } diff --git a/src/system/libroot/posix/unistd/chown.c b/src/system/libroot/posix/unistd/chown.c index 69e96a095d..e16484a76e 100644 --- a/src/system/libroot/posix/unistd/chown.c +++ b/src/system/libroot/posix/unistd/chown.c @@ -41,14 +41,14 @@ common_chown(int fd, const char* path, bool followLinks, uid_t owner, int chown(const char *path, uid_t owner, gid_t group) { - return common_chown(-1, path, true, owner, group); + return common_chown(AT_FDCWD, path, true, owner, group); } int lchown(const char *path, uid_t owner, gid_t group) { - return common_chown(-1, path, false, owner, group); + return common_chown(AT_FDCWD, path, false, owner, group); } diff --git a/src/system/libroot/posix/unistd/directory.c b/src/system/libroot/posix/unistd/directory.c index 57d5e5f7eb..8934a443a4 100644 --- a/src/system/libroot/posix/unistd/directory.c +++ b/src/system/libroot/posix/unistd/directory.c @@ -16,7 +16,7 @@ int chdir(const char *path) { - RETURN_AND_SET_ERRNO(_kern_setcwd(-1, path)); + RETURN_AND_SET_ERRNO(_kern_setcwd(AT_FDCWD, path)); } @@ -58,6 +58,6 @@ getcwd(char *buffer, size_t size) int rmdir(const char *path) { - RETURN_AND_SET_ERRNO(_kern_remove_dir(-1, path)); + RETURN_AND_SET_ERRNO(_kern_remove_dir(AT_FDCWD, path)); } diff --git a/src/system/libroot/posix/unistd/link.c b/src/system/libroot/posix/unistd/link.c index 78919280f7..1c395f6f83 100644 --- a/src/system/libroot/posix/unistd/link.c +++ b/src/system/libroot/posix/unistd/link.c @@ -46,9 +46,7 @@ readlinkat(int fd, const char *path, char *buffer, size_t bufferSize) int symlink(const char *toPath, const char *symlinkPath) { - int status = _kern_create_symlink(-1, symlinkPath, toPath, 0); - - RETURN_AND_SET_ERRNO(status); + return symlinkat(toPath, AT_FDCWD, symlinkPath); } @@ -62,9 +60,7 @@ symlinkat(const char *toPath, int fd, const char *symlinkPath) int unlink(const char *path) { - int status = _kern_unlink(-1, path); - - RETURN_AND_SET_ERRNO(status); + return unlinkat(AT_FDCWD, path, 0); } diff --git a/src/system/libroot/posix/unistd/truncate.c b/src/system/libroot/posix/unistd/truncate.c index 3ef0bb087d..ca2d758a05 100644 --- a/src/system/libroot/posix/unistd/truncate.c +++ b/src/system/libroot/posix/unistd/truncate.c @@ -22,7 +22,7 @@ truncate(const char *path, off_t newSize) status_t status; stat.st_size = newSize; - status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat), + status = _kern_write_stat(AT_FDCWD, path, true, &stat, sizeof(struct stat), B_STAT_SIZE); RETURN_AND_SET_ERRNO(status); diff --git a/src/system/libroot/posix/utime.c b/src/system/libroot/posix/utime.c index 1fdfd1725d..5215baad84 100644 --- a/src/system/libroot/posix/utime.c +++ b/src/system/libroot/posix/utime.c @@ -32,7 +32,7 @@ utime(const char *path, const struct utimbuf *times) stat.st_atim.tv_nsec = stat.st_mtim.tv_nsec = (now % 1000000) * 1000; } - status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat), + status = _kern_write_stat(AT_FDCWD, path, true, &stat, sizeof(struct stat), B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME); RETURN_AND_SET_ERRNO(status);