diff --git a/Kernel/API/POSIX/sys/stat.h b/Kernel/API/POSIX/sys/stat.h new file mode 100644 index 0000000000..31df0e079a --- /dev/null +++ b/Kernel/API/POSIX/sys/stat.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define S_IFMT 0170000 +#define S_IFDIR 0040000 +#define S_IFCHR 0020000 +#define S_IFBLK 0060000 +#define S_IFREG 0100000 +#define S_IFIFO 0010000 +#define S_IFLNK 0120000 +#define S_IFSOCK 0140000 + +#define S_ISUID 04000 +#define S_ISGID 02000 +#define S_ISVTX 01000 +#define S_IRUSR 0400 +#define S_IWUSR 0200 +#define S_IXUSR 0100 +#define S_IREAD S_IRUSR +#define S_IWRITE S_IWUSR +#define S_IEXEC S_IXUSR +#define S_IRGRP 0040 +#define S_IWGRP 0020 +#define S_IXGRP 0010 +#define S_IROTH 0004 +#define S_IWOTH 0002 +#define S_IXOTH 0001 + +#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) + +#define S_IRWXG (S_IRWXU >> 3) +#define S_IRWXO (S_IRWXG >> 3) +#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +#define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) +#define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +#define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) +#define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) +#define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK) + +struct stat { + dev_t st_dev; /* ID of device containing file */ + ino_t st_ino; /* inode number */ + mode_t st_mode; /* protection */ + nlink_t st_nlink; /* number of hard links */ + uid_t st_uid; /* user ID of owner */ + gid_t st_gid; /* group ID of owner */ + dev_t st_rdev; /* device ID (if special file) */ + off_t st_size; /* total size, in bytes */ + blksize_t st_blksize; /* block size for file system I/O */ + blkcnt_t st_blocks; /* number of 512-byte blocks allocated */ + struct timespec st_atim; /* time of last access */ + struct timespec st_mtim; /* time of last modification */ + struct timespec st_ctim; /* time of last status change */ +}; + +#define st_atime st_atim.tv_sec +#define st_mtime st_mtim.tv_sec +#define st_ctime st_ctim.tv_sec + +#ifdef __cplusplus +} +#endif diff --git a/Kernel/API/POSIX/time.h b/Kernel/API/POSIX/time.h new file mode 100644 index 0000000000..19717a4a98 --- /dev/null +++ b/Kernel/API/POSIX/time.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define CLOCKS_PER_SEC 1000 + +struct timespec { + time_t tv_sec; + long tv_nsec; +}; + +typedef int clockid_t; + +enum { + CLOCK_REALTIME, +#define CLOCK_REALTIME CLOCK_REALTIME + CLOCK_MONOTONIC, +#define CLOCK_MONOTONIC CLOCK_MONOTONIC + CLOCK_MONOTONIC_RAW, +#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC_RAW + CLOCK_REALTIME_COARSE, +#define CLOCK_REALTIME_COARSE CLOCK_REALTIME_COARSE + CLOCK_MONOTONIC_COARSE, +#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_COARSE + CLOCK_ID_COUNT, +}; + +#define TIMER_ABSTIME 99 + +#ifdef __cplusplus +} +#endif diff --git a/Kernel/UnixTypes.h b/Kernel/UnixTypes.h index a71b9ec5dc..91db13321b 100644 --- a/Kernel/UnixTypes.h +++ b/Kernel/UnixTypes.h @@ -9,6 +9,8 @@ #include #include #include +#include +#include // Kernel internal options. #define O_NOFOLLOW_NOERROR (1 << 29) @@ -430,27 +432,6 @@ struct termios { speed_t c_ospeed; }; -struct timespec { - time_t tv_sec; /* Seconds */ - long tv_nsec; /* Nanoseconds */ -}; - -struct stat { - dev_t st_dev; /* ID of device containing file */ - ino_t st_ino; /* inode number */ - mode_t st_mode; /* protection */ - nlink_t st_nlink; /* number of hard links */ - uid_t st_uid; /* user ID of owner */ - gid_t st_gid; /* group ID of owner */ - dev_t st_rdev; /* device ID (if special file) */ - off_t st_size; /* total size, in bytes */ - blksize_t st_blksize; /* blocksize for file system I/O */ - blkcnt_t st_blocks; /* number of 512B blocks allocated */ - struct timespec st_atim; /* time of last access */ - struct timespec st_mtim; /* time of last modification */ - struct timespec st_ctim; /* time of last status change */ -}; - #define POLLIN (1u << 0) #define POLLPRI (1u << 1) #define POLLOUT (1u << 2) @@ -582,24 +563,6 @@ typedef enum { P_PGID } idtype_t; -typedef int clockid_t; - -enum { - CLOCK_REALTIME, -#define CLOCK_REALTIME CLOCK_REALTIME - CLOCK_MONOTONIC, -#define CLOCK_MONOTONIC CLOCK_MONOTONIC - CLOCK_MONOTONIC_RAW, -#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC_RAW - CLOCK_REALTIME_COARSE, -#define CLOCK_REALTIME_COARSE CLOCK_REALTIME_COARSE - CLOCK_MONOTONIC_COARSE, -#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_COARSE - CLOCK_ID_COUNT, -}; - -#define TIMER_ABSTIME 99 - #define UTSNAME_ENTRY_LEN 65 struct utsname { diff --git a/Userland/Libraries/LibC/sys/stat.h b/Userland/Libraries/LibC/sys/stat.h index 579559d796..b24e807f87 100644 --- a/Userland/Libraries/LibC/sys/stat.h +++ b/Userland/Libraries/LibC/sys/stat.h @@ -1,74 +1,18 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include #include #include #include __BEGIN_DECLS -#define S_IFMT 0170000 -#define S_IFDIR 0040000 -#define S_IFCHR 0020000 -#define S_IFBLK 0060000 -#define S_IFREG 0100000 -#define S_IFIFO 0010000 -#define S_IFLNK 0120000 -#define S_IFSOCK 0140000 - -#define S_ISUID 04000 -#define S_ISGID 02000 -#define S_ISVTX 01000 -#define S_IRUSR 0400 -#define S_IWUSR 0200 -#define S_IXUSR 0100 -#define S_IREAD S_IRUSR -#define S_IWRITE S_IWUSR -#define S_IEXEC S_IXUSR -#define S_IRGRP 0040 -#define S_IWGRP 0020 -#define S_IXGRP 0010 -#define S_IROTH 0004 -#define S_IWOTH 0002 -#define S_IXOTH 0001 - -#define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) - -#define S_IRWXG (S_IRWXU >> 3) -#define S_IRWXO (S_IRWXG >> 3) -#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) -#define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) -#define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) -#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) -#define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) -#define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) -#define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK) - -struct stat { - dev_t st_dev; /* ID of device containing file */ - ino_t st_ino; /* inode number */ - mode_t st_mode; /* protection */ - nlink_t st_nlink; /* number of hard links */ - uid_t st_uid; /* user ID of owner */ - gid_t st_gid; /* group ID of owner */ - dev_t st_rdev; /* device ID (if special file) */ - off_t st_size; /* total size, in bytes */ - blksize_t st_blksize; /* blocksize for file system I/O */ - blkcnt_t st_blocks; /* number of 512B blocks allocated */ - struct timespec st_atim; /* time of last access */ - struct timespec st_mtim; /* time of last modification */ - struct timespec st_ctim; /* time of last status change */ -}; - -#define st_atime st_atim.tv_sec -#define st_mtime st_mtim.tv_sec -#define st_ctime st_ctim.tv_sec - mode_t umask(mode_t); int chmod(const char* pathname, mode_t); int fchmod(int fd, mode_t); diff --git a/Userland/Libraries/LibC/time.h b/Userland/Libraries/LibC/time.h index ed65fb2e37..4d41ffec0b 100644 --- a/Userland/Libraries/LibC/time.h +++ b/Userland/Libraries/LibC/time.h @@ -6,8 +6,7 @@ #pragma once -#include -#include +#include __BEGIN_DECLS @@ -42,32 +41,8 @@ void tzset(); char* asctime(const struct tm*); char* asctime_r(const struct tm*, char* buf); -#define CLOCKS_PER_SEC 1000 clock_t clock(); -struct timespec { - time_t tv_sec; - long tv_nsec; -}; - -typedef int clockid_t; - -enum { - CLOCK_REALTIME, -#define CLOCK_REALTIME CLOCK_REALTIME - CLOCK_MONOTONIC, -#define CLOCK_MONOTONIC CLOCK_MONOTONIC - CLOCK_MONOTONIC_RAW, -#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC_RAW - CLOCK_REALTIME_COARSE, -#define CLOCK_REALTIME_COARSE CLOCK_REALTIME_COARSE - CLOCK_MONOTONIC_COARSE, -#define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_COARSE - CLOCK_ID_COUNT, -}; - -#define TIMER_ABSTIME 99 - int clock_gettime(clockid_t, struct timespec*); int clock_settime(clockid_t, struct timespec*); int clock_nanosleep(clockid_t, int flags, const struct timespec* requested_sleep, struct timespec* remaining_sleep);