mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +00:00
LibCore: Add Core::System wrappers for fstat() and fcntl()
This commit is contained in:
parent
21a5fb0fa2
commit
c37a02341b
2 changed files with 25 additions and 0 deletions
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibSystem/syscall.h>
|
#include <LibSystem/syscall.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
|
#define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
|
||||||
if ((rc) < 0) { \
|
if ((rc) < 0) { \
|
||||||
|
@ -44,4 +46,24 @@ ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigac
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<struct stat> fstat(int fd)
|
||||||
|
{
|
||||||
|
struct stat st = {};
|
||||||
|
if (::fstat(fd, &st) < 0)
|
||||||
|
return Error::from_syscall("fstat"sv, -errno);
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<int> fcntl(int fd, int command, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, command);
|
||||||
|
u32 extra_arg = va_arg(ap, u32);
|
||||||
|
int rc = ::fcntl(fd, command, extra_arg);
|
||||||
|
va_end(ap);
|
||||||
|
if (rc < 0)
|
||||||
|
return Error::from_syscall("fcntl"sv, -errno);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
namespace Core::System {
|
namespace Core::System {
|
||||||
|
|
||||||
|
@ -17,5 +18,7 @@ ErrorOr<void> unveil(StringView path, StringView permissions);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);
|
ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);
|
||||||
|
ErrorOr<struct stat> fstat(int fd);
|
||||||
|
ErrorOr<int> fcntl(int fd, int command, ...);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue