mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
LibC: Implement serenity_open
This syscall is very much similar to open(2), with the difference of accepting a string and a length, instead of requiring a null-terminated string. This way, if the string passed is not null-terminated, we can still perform the syscall.
This commit is contained in:
parent
c710d52afa
commit
59eb2d5de4
Notes:
sideshowbarker
2024-07-17 22:43:17 +09:00
Author: https://github.com/sin-ack Commit: https://github.com/SerenityOS/serenity/commit/59eb2d5de4e Pull-request: https://github.com/SerenityOS/serenity/pull/9977 Reviewed-by: https://github.com/Dexesttp Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/awesomekling
2 changed files with 27 additions and 0 deletions
|
@ -4,6 +4,8 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <Kernel/API/POSIX/fcntl.h>
|
||||
#include <Kernel/API/Syscall.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <serenity.h>
|
||||
|
@ -148,4 +150,27 @@ int emuctl(uintptr_t command, uintptr_t arg0, uintptr_t arg1)
|
|||
{
|
||||
return syscall(SC_emuctl, command, arg0, arg1);
|
||||
}
|
||||
|
||||
int serenity_open(char const* path, size_t path_length, int options, ...)
|
||||
{
|
||||
if (!path) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (path_length > INT32_MAX) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, options);
|
||||
auto mode = (mode_t)va_arg(ap, unsigned);
|
||||
va_end(ap);
|
||||
|
||||
Syscall::SC_open_params params { AT_FDCWD, { path, path_length }, options, mode };
|
||||
int rc = syscall(SC_open, ¶ms);
|
||||
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,4 +60,6 @@ uint16_t internet_checksum(const void* ptr, size_t count);
|
|||
|
||||
int emuctl(uintptr_t command, uintptr_t arg0, uintptr_t arg1);
|
||||
|
||||
int serenity_open(char const* path, size_t path_length, int options, ...);
|
||||
|
||||
__END_DECLS
|
||||
|
|
Loading…
Reference in a new issue