1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

Kernel+LibC: Share definitions for time.h and sys/stat.h

This commit is contained in:
Andreas Kling 2021-08-14 15:42:24 +02:00
parent 740140a661
commit 0a78056453
5 changed files with 122 additions and 123 deletions

View file

@ -0,0 +1,75 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/API/POSIX/sys/types.h>
#include <Kernel/API/POSIX/time.h>
#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

42
Kernel/API/POSIX/time.h Normal file
View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/API/POSIX/sys/types.h>
#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

View file

@ -9,6 +9,8 @@
#include <AK/DistinctNumeric.h>
#include <AK/Types.h>
#include <Kernel/API/POSIX/fcntl.h>
#include <Kernel/API/POSIX/sys/stat.h>
#include <Kernel/API/POSIX/time.h>
// 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 {

View file

@ -1,74 +1,18 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/API/POSIX/sys/stat.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <time.h>
__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);

View file

@ -6,8 +6,7 @@
#pragma once
#include <sys/cdefs.h>
#include <sys/types.h>
#include <Kernel/API/POSIX/time.h>
__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);