mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
LibC: Move stat(), lstat() and fstat() to <sys/stat.h>
Dr. POSIX says that's where they belong.
This commit is contained in:
parent
9e55162e9b
commit
3a13c749cd
4 changed files with 30 additions and 31 deletions
|
@ -69,4 +69,31 @@ int mkfifo(const char* pathname, mode_t mode)
|
||||||
{
|
{
|
||||||
return mknod(pathname, mode | S_IFIFO, 0);
|
return mknod(pathname, mode | S_IFIFO, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_stat(const char* path, struct stat* statbuf, bool follow_symlinks)
|
||||||
|
{
|
||||||
|
if (!path) {
|
||||||
|
errno = EFAULT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
Syscall::SC_stat_params params { { path, strlen(path) }, statbuf, follow_symlinks };
|
||||||
|
int rc = syscall(SC_stat, ¶ms);
|
||||||
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int lstat(const char* path, struct stat* statbuf)
|
||||||
|
{
|
||||||
|
return do_stat(path, statbuf, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int stat(const char* path, struct stat* statbuf)
|
||||||
|
{
|
||||||
|
return do_stat(path, statbuf, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int fstat(int fd, struct stat* statbuf)
|
||||||
|
{
|
||||||
|
int rc = syscall(SC_fstat, fd, statbuf);
|
||||||
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,9 @@ int chmod(const char* pathname, mode_t);
|
||||||
int fchmod(int fd, mode_t);
|
int fchmod(int fd, mode_t);
|
||||||
int mkdir(const char* pathname, mode_t);
|
int mkdir(const char* pathname, mode_t);
|
||||||
int mkfifo(const char* pathname, mode_t);
|
int mkfifo(const char* pathname, mode_t);
|
||||||
|
int fstat(int fd, struct stat* statbuf);
|
||||||
|
int lstat(const char* path, struct stat* statbuf);
|
||||||
|
int stat(const char* path, struct stat* statbuf);
|
||||||
|
|
||||||
inline dev_t makedev(unsigned int major, unsigned int minor) { return (minor & 0xffu) | (major << 8u) | ((minor & ~0xffu) << 12u); }
|
inline dev_t makedev(unsigned int major, unsigned int minor) { return (minor & 0xffu) | (major << 8u) | ((minor & ~0xffu) << 12u); }
|
||||||
inline unsigned int major(dev_t dev) { return (dev & 0xfff00u) >> 8u; }
|
inline unsigned int major(dev_t dev) { return (dev & 0xfff00u) >> 8u; }
|
||||||
|
|
|
@ -297,33 +297,6 @@ int close(int fd)
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_stat(const char* path, struct stat* statbuf, bool follow_symlinks)
|
|
||||||
{
|
|
||||||
if (!path) {
|
|
||||||
errno = EFAULT;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
Syscall::SC_stat_params params { { path, strlen(path) }, statbuf, follow_symlinks };
|
|
||||||
int rc = syscall(SC_stat, ¶ms);
|
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int lstat(const char* path, struct stat* statbuf)
|
|
||||||
{
|
|
||||||
return do_stat(path, statbuf, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
int stat(const char* path, struct stat* statbuf)
|
|
||||||
{
|
|
||||||
return do_stat(path, statbuf, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
int fstat(int fd, struct stat* statbuf)
|
|
||||||
{
|
|
||||||
int rc = syscall(SC_fstat, fd, statbuf);
|
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int chdir(const char* path)
|
int chdir(const char* path)
|
||||||
{
|
{
|
||||||
if (!path) {
|
if (!path) {
|
||||||
|
@ -750,5 +723,4 @@ int getpagesize()
|
||||||
{
|
{
|
||||||
return PAGE_SIZE;
|
return PAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,9 +105,6 @@ int chdir(const char* path);
|
||||||
int fchdir(int fd);
|
int fchdir(int fd);
|
||||||
char* getcwd(char* buffer, size_t size);
|
char* getcwd(char* buffer, size_t size);
|
||||||
char* getwd(char* buffer);
|
char* getwd(char* buffer);
|
||||||
int fstat(int fd, struct stat* statbuf);
|
|
||||||
int lstat(const char* path, struct stat* statbuf);
|
|
||||||
int stat(const char* path, struct stat* statbuf);
|
|
||||||
int sleep(unsigned seconds);
|
int sleep(unsigned seconds);
|
||||||
int usleep(useconds_t);
|
int usleep(useconds_t);
|
||||||
int gethostname(char*, size_t);
|
int gethostname(char*, size_t);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue