libroot: Use AT_FDCWD rather than hardcoding -1 in many places.

AT_FDCWD is now -100, not -1, though the kernel accepts any negative
value at the moment.
This commit is contained in:
Augustin Cavalier
2024-09-03 11:19:02 -04:00
parent 90ae97dbac
commit 55e8238c72
16 changed files with 33 additions and 50 deletions
+3 -4
View File
@@ -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);
}
+1 -3
View File
@@ -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);
}
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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));
}
+2 -3
View File
@@ -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;
}
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);
}
+9 -14
View File
@@ -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)));
}
+1 -1
View File
@@ -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);
+3 -7
View File
@@ -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));
}
+2 -2
View File
@@ -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);
}
+2 -2
View File
@@ -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));
}
+2 -6
View File
@@ -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);
}
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);