diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-08 20:01:49 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-08 20:01:49 +0200 |
commit | c110cf193d32e49011df29f04c035054adefd10f (patch) | |
tree | b1169e121792b5ba09756ef70661bcbdd3f183b7 /Libraries/LibC | |
parent | fc4022d1736e2cce3810698b9fe8a7832625277b (diff) | |
download | serenity-c110cf193d32e49011df29f04c035054adefd10f.zip |
Kernel: Have the open() syscall take an explicit path length parameter.
Instead of computing the path length inside the syscall handler, let the
caller do that work. This allows us to implement to new variants of open()
and creat(), called open_with_path_length() and creat_with_path_length().
These are suitable for use with e.g StringView.
Diffstat (limited to 'Libraries/LibC')
-rw-r--r-- | Libraries/LibC/unistd.cpp | 20 | ||||
-rw-r--r-- | Libraries/LibC/unistd.h | 2 |
2 files changed, 20 insertions, 2 deletions
diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index 4744ee5f58..d4622bba1f 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -166,13 +166,29 @@ 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 open(const char* path, int options, ...) { va_list ap; va_start(ap, options); - int rc = syscall(SC_open, path, options, (mode_t)va_arg(ap, unsigned)); + auto mode = (mode_t)va_arg(ap, unsigned); va_end(ap); - __RETURN_WITH_ERRNO(rc, rc, -1); + return open_with_path_length(path, strlen(path), options, mode); } ssize_t read(int fd, void* buf, size_t count) diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index cfe5c26b26..42235b0e63 100644 --- a/Libraries/LibC/unistd.h +++ b/Libraries/LibC/unistd.h @@ -55,6 +55,8 @@ pid_t tcgetpgrp(int fd); 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); ssize_t read(int fd, void* buf, size_t count); ssize_t write(int fd, const void* buf, size_t count); int close(int fd); |