summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-11 18:56:41 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-11 20:29:14 +0200
commit3a13c749cd6738e23d99416e22bb5423d474999d (patch)
tree7c0240a56048e8be89103628d90e7212ffbbbf72 /Libraries
parent9e55162e9bf585c5caf1a69efa9a4653766196f6 (diff)
downloadserenity-3a13c749cd6738e23d99416e22bb5423d474999d.zip
LibC: Move stat(), lstat() and fstat() to <sys/stat.h>
Dr. POSIX says that's where they belong.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibC/stat.cpp27
-rw-r--r--Libraries/LibC/sys/stat.h3
-rw-r--r--Libraries/LibC/unistd.cpp28
-rw-r--r--Libraries/LibC/unistd.h3
4 files changed, 30 insertions, 31 deletions
diff --git a/Libraries/LibC/stat.cpp b/Libraries/LibC/stat.cpp
index e1abc7905c..5de2472dfa 100644
--- a/Libraries/LibC/stat.cpp
+++ b/Libraries/LibC/stat.cpp
@@ -69,4 +69,31 @@ int mkfifo(const char* pathname, mode_t mode)
{
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, &params);
+ __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);
+}
}
diff --git a/Libraries/LibC/sys/stat.h b/Libraries/LibC/sys/stat.h
index 61c60b8977..ed6d84458d 100644
--- a/Libraries/LibC/sys/stat.h
+++ b/Libraries/LibC/sys/stat.h
@@ -61,6 +61,9 @@ int chmod(const char* pathname, mode_t);
int fchmod(int fd, mode_t);
int mkdir(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 unsigned int major(dev_t dev) { return (dev & 0xfff00u) >> 8u; }
diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp
index 2332ee1f8d..414f4bedd7 100644
--- a/Libraries/LibC/unistd.cpp
+++ b/Libraries/LibC/unistd.cpp
@@ -297,33 +297,6 @@ int close(int fd)
__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, &params);
- __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)
{
if (!path) {
@@ -750,5 +723,4 @@ int getpagesize()
{
return PAGE_SIZE;
}
-
}
diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h
index d35f8b3db2..a0bee9a3b8 100644
--- a/Libraries/LibC/unistd.h
+++ b/Libraries/LibC/unistd.h
@@ -105,9 +105,6 @@ int chdir(const char* path);
int fchdir(int fd);
char* getcwd(char* buffer, size_t size);
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 usleep(useconds_t);
int gethostname(char*, size_t);