mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
LibC: Move the creat() and open() families to <fcntl.h>
Since POSIX says that's where they belong :^)
This commit is contained in:
parent
8d4d63d9b6
commit
fbcab844de
4 changed files with 66 additions and 66 deletions
|
@ -2,7 +2,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <string.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
@ -21,4 +21,61 @@ int watch_file(const char* path, int path_length)
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int creat(const char* path, mode_t mode)
|
||||||
|
{
|
||||||
|
return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
int creat_with_path_length(const char* path, size_t path_length, mode_t mode)
|
||||||
|
{
|
||||||
|
return open_with_path_length(path, path_length, O_CREAT | O_WRONLY | O_TRUNC, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
int open_with_path_length(const char* path, size_t path_length, int options, mode_t mode)
|
||||||
|
{
|
||||||
|
if (path_length > INT32_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
Syscall::SC_open_params params { path, (int)path_length, options, mode };
|
||||||
|
int rc = syscall(SC_open, ¶ms);
|
||||||
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int openat_with_path_length(int dirfd, const char* path, size_t path_length, int options, mode_t mode)
|
||||||
|
{
|
||||||
|
if (path_length > INT32_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
Syscall::SC_openat_params params { dirfd, path, (int)path_length, options, mode };
|
||||||
|
int rc = syscall(SC_openat, ¶ms);
|
||||||
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int open(const char* path, int options, ...)
|
||||||
|
{
|
||||||
|
if (!path) {
|
||||||
|
errno = EFAULT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, options);
|
||||||
|
auto mode = (mode_t)va_arg(ap, unsigned);
|
||||||
|
va_end(ap);
|
||||||
|
return open_with_path_length(path, strlen(path), options, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
int openat(int dirfd, const char* path, int options, ...)
|
||||||
|
{
|
||||||
|
if (!path) {
|
||||||
|
errno = EFAULT;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, options);
|
||||||
|
auto mode = (mode_t)va_arg(ap, unsigned);
|
||||||
|
va_end(ap);
|
||||||
|
return openat_with_path_length(dirfd, path, strlen(path), options, mode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,14 @@ __BEGIN_DECLS
|
||||||
#define S_IRWXG (S_IRWXU >> 3)
|
#define S_IRWXG (S_IRWXU >> 3)
|
||||||
#define S_IRWXO (S_IRWXG >> 3)
|
#define S_IRWXO (S_IRWXG >> 3)
|
||||||
|
|
||||||
|
int creat(const char* path, mode_t);
|
||||||
|
int open(const char* path, int options, ...);
|
||||||
|
int creat_with_path_length(const char* path, size_t path_length, mode_t);
|
||||||
|
int open_with_path_length(const char* path, size_t path_length, int options, mode_t);
|
||||||
|
#define AT_FDCWD -100
|
||||||
|
int openat(int dirfd, const char* path, int options, ...);
|
||||||
|
int openat_with_path_length(int dirfd, const char* path, size_t path_length, int options, mode_t);
|
||||||
|
|
||||||
int fcntl(int fd, int cmd, ...);
|
int fcntl(int fd, int cmd, ...);
|
||||||
int watch_file(const char* path, int path_length);
|
int watch_file(const char* path, int path_length);
|
||||||
|
|
||||||
|
|
|
@ -186,64 +186,6 @@ pid_t getpgrp()
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int creat(const char* path, mode_t mode)
|
|
||||||
{
|
|
||||||
return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
int creat_with_path_length(const char* path, size_t path_length, mode_t mode)
|
|
||||||
{
|
|
||||||
return open_with_path_length(path, path_length, O_CREAT | O_WRONLY | O_TRUNC, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
int open_with_path_length(const char* path, size_t path_length, int options, mode_t mode)
|
|
||||||
{
|
|
||||||
if (path_length > INT32_MAX) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
Syscall::SC_open_params params { path, (int)path_length, options, mode };
|
|
||||||
int rc = syscall(SC_open, ¶ms);
|
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int openat_with_path_length(int dirfd, const char* path, size_t path_length, int options, mode_t mode)
|
|
||||||
{
|
|
||||||
if (path_length > INT32_MAX) {
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
Syscall::SC_openat_params params { dirfd, path, (int)path_length, options, mode };
|
|
||||||
int rc = syscall(SC_openat, ¶ms);
|
|
||||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int open(const char* path, int options, ...)
|
|
||||||
{
|
|
||||||
if (!path) {
|
|
||||||
errno = EFAULT;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, options);
|
|
||||||
auto mode = (mode_t)va_arg(ap, unsigned);
|
|
||||||
va_end(ap);
|
|
||||||
return open_with_path_length(path, strlen(path), options, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
int openat(int dirfd, const char* path, int options, ...)
|
|
||||||
{
|
|
||||||
if (!path) {
|
|
||||||
errno = EFAULT;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, options);
|
|
||||||
auto mode = (mode_t)va_arg(ap, unsigned);
|
|
||||||
va_end(ap);
|
|
||||||
return openat_with_path_length(dirfd, path, strlen(path), options, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssize_t read(int fd, void* buf, size_t count)
|
ssize_t read(int fd, void* buf, size_t count)
|
||||||
{
|
{
|
||||||
int rc = syscall(SC_read, fd, buf, count);
|
int rc = syscall(SC_read, fd, buf, count);
|
||||||
|
|
|
@ -73,13 +73,6 @@ int setuid(uid_t);
|
||||||
int setgid(gid_t);
|
int setgid(gid_t);
|
||||||
pid_t tcgetpgrp(int fd);
|
pid_t tcgetpgrp(int fd);
|
||||||
int tcsetpgrp(int fd, pid_t pgid);
|
int tcsetpgrp(int fd, pid_t pgid);
|
||||||
int creat(const char* path, mode_t);
|
|
||||||
int open(const char* path, int options, ...);
|
|
||||||
int creat_with_path_length(const char* path, size_t path_length, mode_t);
|
|
||||||
int open_with_path_length(const char* path, size_t path_length, int options, mode_t);
|
|
||||||
#define AT_FDCWD -100
|
|
||||||
int openat(int dirfd, const char* path, int options, ...);
|
|
||||||
int openat_with_path_length(int dirfd, const char* path, size_t path_length, int options, mode_t);
|
|
||||||
ssize_t read(int fd, void* buf, size_t count);
|
ssize_t read(int fd, void* buf, size_t count);
|
||||||
ssize_t write(int fd, const void* buf, size_t count);
|
ssize_t write(int fd, const void* buf, size_t count);
|
||||||
int close(int fd);
|
int close(int fd);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue