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:
@@ -96,7 +96,7 @@ fs_stat_attr(int fd, const char* attribute, struct attr_info* attrInfo)
|
|||||||
int
|
int
|
||||||
fs_open_attr(const char *path, const char *attribute, uint32 type, int openMode)
|
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);
|
RETURN_AND_SET_ERRNO(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,14 +121,14 @@ fs_close_attr(int fd)
|
|||||||
extern "C" DIR*
|
extern "C" DIR*
|
||||||
fs_open_attr_dir(const char* path)
|
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*
|
extern "C" DIR*
|
||||||
fs_lopen_attr_dir(const char* path)
|
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*
|
extern "C" DIR*
|
||||||
@@ -157,4 +157,3 @@ fs_rewind_attr_dir(DIR* dir)
|
|||||||
{
|
{
|
||||||
rewinddir(dir);
|
rewinddir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ dev_t
|
|||||||
dev_for_path(const char *path)
|
dev_for_path(const char *path)
|
||||||
{
|
{
|
||||||
struct stat stat;
|
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)
|
if (status == B_OK)
|
||||||
return stat.st_dev;
|
return stat.st_dev;
|
||||||
|
|
||||||
@@ -65,5 +65,3 @@ fs_stat_dev(dev_t device, fs_info *info)
|
|||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
RETURN_AND_SET_ERRNO(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ opendir(const char* path)
|
|||||||
{
|
{
|
||||||
DIR* dir;
|
DIR* dir;
|
||||||
|
|
||||||
int fd = _kern_open_dir(-1, path);
|
int fd = _kern_open_dir(AT_FDCWD, path);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
__set_errno(fd);
|
__set_errno(fd);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ int
|
|||||||
creat(const char *path, mode_t mode)
|
creat(const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
RETURN_AND_SET_ERRNO_TEST_CANCEL(
|
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
|
// adapt the permissions as required by POSIX
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ open(const char *path, int openMode, ...)
|
|||||||
va_end(args);
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ int
|
|||||||
remove(const char* path)
|
remove(const char* path)
|
||||||
{
|
{
|
||||||
// TODO: find a better way that does not require two syscalls for directories
|
// 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)
|
if (status == B_IS_A_DIRECTORY)
|
||||||
status = _kern_remove_dir(-1, path);
|
status = _kern_remove_dir(AT_FDCWD, path);
|
||||||
|
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
__set_errno(status);
|
__set_errno(status);
|
||||||
@@ -27,4 +27,3 @@ remove(const char* path)
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
int
|
int
|
||||||
rename(const char *from, const char *to)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ chmod(const char *path, mode_t mode)
|
|||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
stat.st_mode = mode;
|
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);
|
B_STAT_MODE);
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
RETURN_AND_SET_ERRNO(status);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
int
|
int
|
||||||
mkdir(const char* path, mode_t mode)
|
mkdir(const char* path, mode_t mode)
|
||||||
{
|
{
|
||||||
RETURN_AND_SET_ERRNO(_kern_create_dir(-1, path, mode & ~__gUmask));
|
return mkdirat(AT_FDCWD, path, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,37 +28,32 @@ int _lstat_beos(const char* path, struct stat_beos* beosStat);
|
|||||||
int
|
int
|
||||||
_stat_current(const char* path, struct stat* stat)
|
_stat_current(const char* path, struct stat* stat)
|
||||||
{
|
{
|
||||||
int status = _kern_read_stat(-1, path, true, stat, sizeof(struct stat));
|
RETURN_AND_SET_ERRNO(_kern_read_stat(AT_FDCWD, path, true,
|
||||||
|
stat, sizeof(struct stat)));
|
||||||
RETURN_AND_SET_ERRNO(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
_fstat_current(int fd, struct stat* stat)
|
_fstat_current(int fd, struct stat* stat)
|
||||||
{
|
{
|
||||||
int status = _kern_read_stat(fd, NULL, false, stat, sizeof(struct stat));
|
RETURN_AND_SET_ERRNO(_kern_read_stat(fd, NULL, false,
|
||||||
|
stat, sizeof(struct stat)));
|
||||||
RETURN_AND_SET_ERRNO(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
_lstat_current(const char* path, struct stat* stat)
|
_lstat_current(const char* path, struct stat* stat)
|
||||||
{
|
{
|
||||||
int status = _kern_read_stat(-1, path, false, stat, sizeof(struct stat));
|
RETURN_AND_SET_ERRNO(_kern_read_stat(AT_FDCWD, path, false,
|
||||||
|
stat, sizeof(struct stat)));
|
||||||
RETURN_AND_SET_ERRNO(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
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,
|
RETURN_AND_SET_ERRNO(_kern_read_stat(fd, path, (flag & AT_SYMLINK_NOFOLLOW) == 0,
|
||||||
st, sizeof(struct stat));
|
stat, sizeof(struct stat)));
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ _utimes(const char* path, const struct timeval times[2], bool traverseLink)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// traverseLeafLink == true
|
// 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);
|
sizeof(struct stat), B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
RETURN_AND_SET_ERRNO(status);
|
||||||
|
|||||||
@@ -15,17 +15,13 @@
|
|||||||
int
|
int
|
||||||
access(const char* path, int accessMode)
|
access(const char* path, int accessMode)
|
||||||
{
|
{
|
||||||
status_t status = _kern_access(-1, path, accessMode, false);
|
return faccessat(AT_FDCWD, path, accessMode, 0);
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
faccessat(int fd, const char* path, int accessMode, int flag)
|
faccessat(int fd, const char* path, int accessMode, int flag)
|
||||||
{
|
{
|
||||||
status_t status = _kern_access(fd, path, accessMode,
|
RETURN_AND_SET_ERRNO(_kern_access(fd, path, accessMode,
|
||||||
(flag & AT_EACCESS) != 0);
|
(flag & AT_EACCESS) != 0));
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,14 +41,14 @@ common_chown(int fd, const char* path, bool followLinks, uid_t owner,
|
|||||||
int
|
int
|
||||||
chown(const char *path, uid_t owner, gid_t group)
|
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
|
int
|
||||||
lchown(const char *path, uid_t owner, gid_t group)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
int
|
int
|
||||||
chdir(const char *path)
|
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
|
int
|
||||||
rmdir(const char *path)
|
rmdir(const char *path)
|
||||||
{
|
{
|
||||||
RETURN_AND_SET_ERRNO(_kern_remove_dir(-1, path));
|
RETURN_AND_SET_ERRNO(_kern_remove_dir(AT_FDCWD, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,9 +46,7 @@ readlinkat(int fd, const char *path, char *buffer, size_t bufferSize)
|
|||||||
int
|
int
|
||||||
symlink(const char *toPath, const char *symlinkPath)
|
symlink(const char *toPath, const char *symlinkPath)
|
||||||
{
|
{
|
||||||
int status = _kern_create_symlink(-1, symlinkPath, toPath, 0);
|
return symlinkat(toPath, AT_FDCWD, symlinkPath);
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -62,9 +60,7 @@ symlinkat(const char *toPath, int fd, const char *symlinkPath)
|
|||||||
int
|
int
|
||||||
unlink(const char *path)
|
unlink(const char *path)
|
||||||
{
|
{
|
||||||
int status = _kern_unlink(-1, path);
|
return unlinkat(AT_FDCWD, path, 0);
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ truncate(const char *path, off_t newSize)
|
|||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
stat.st_size = newSize;
|
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);
|
B_STAT_SIZE);
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
RETURN_AND_SET_ERRNO(status);
|
||||||
|
|||||||
@@ -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;
|
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);
|
B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME);
|
||||||
|
|
||||||
RETURN_AND_SET_ERRNO(status);
|
RETURN_AND_SET_ERRNO(status);
|
||||||
|
|||||||
Reference in New Issue
Block a user