summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/HexEditor/HexEditor.cpp4
-rw-r--r--Userland/Applications/HexEditor/HexEditor.h2
-rw-r--r--Userland/DevTools/UserspaceEmulator/Emulator.cpp12
-rw-r--r--Userland/Libraries/LibC/fcntl.cpp37
-rw-r--r--Userland/Libraries/LibC/fcntl.h3
-rw-r--r--Userland/Libraries/LibCore/LocalServer.cpp1
-rw-r--r--Userland/Libraries/LibCore/LocalSocket.cpp1
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp4
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.h2
-rw-r--r--Userland/Libraries/LibPCIDB/Database.cpp2
-rw-r--r--Userland/Libraries/LibPCIDB/Database.h3
-rw-r--r--Userland/Services/SystemServer/Service.cpp2
-rw-r--r--Userland/Shell/AST.cpp1
-rw-r--r--Userland/Utilities/js.cpp5
14 files changed, 37 insertions, 42 deletions
diff --git a/Userland/Applications/HexEditor/HexEditor.cpp b/Userland/Applications/HexEditor/HexEditor.cpp
index 6ccba8579a..edd98b8c56 100644
--- a/Userland/Applications/HexEditor/HexEditor.cpp
+++ b/Userland/Applications/HexEditor/HexEditor.cpp
@@ -98,12 +98,12 @@ void HexEditor::set_position(int position)
update_status();
}
-bool HexEditor::write_to_file(const StringView& path)
+bool HexEditor::write_to_file(const String& path)
{
if (m_buffer.is_empty())
return true;
- int fd = open_with_path_length(path.characters_without_null_termination(), path.length(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
perror("open");
return false;
diff --git a/Userland/Applications/HexEditor/HexEditor.h b/Userland/Applications/HexEditor/HexEditor.h
index e47eedeec3..15d7632495 100644
--- a/Userland/Applications/HexEditor/HexEditor.h
+++ b/Userland/Applications/HexEditor/HexEditor.h
@@ -51,7 +51,7 @@ public:
void set_buffer(const ByteBuffer&);
void fill_selection(u8 fill_byte);
- bool write_to_file(const StringView& path);
+ bool write_to_file(const String& path);
bool has_selection() const { return !(m_selection_start == -1 || m_selection_end == -1 || (m_selection_end - m_selection_start) < 0 || m_buffer.is_empty()); }
bool copy_selected_text_to_clipboard();
diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.cpp b/Userland/DevTools/UserspaceEmulator/Emulator.cpp
index c463d24618..107dbf5cbb 100644
--- a/Userland/DevTools/UserspaceEmulator/Emulator.cpp
+++ b/Userland/DevTools/UserspaceEmulator/Emulator.cpp
@@ -988,10 +988,14 @@ u32 Emulator::virt$open(u32 params_addr)
auto path = mmu().copy_buffer_from_vm((FlatPtr)params.path.characters, params.path.length);
- int fd = openat_with_path_length(params.dirfd, (const char*)path.data(), path.size(), params.options, params.mode);
- if (fd < 0)
- return -errno;
- return fd;
+ Syscall::SC_open_params host_params {};
+ host_params.dirfd = params.dirfd;
+ host_params.mode = params.mode;
+ host_params.options = params.options;
+ host_params.path.characters = (const char*)path.data();
+ host_params.path.length = path.size();
+
+ return syscall(SC_open, &host_params);
}
int Emulator::virt$pipe(FlatPtr vm_pipefd, int flags)
diff --git a/Userland/Libraries/LibC/fcntl.cpp b/Userland/Libraries/LibC/fcntl.cpp
index dd71fd1559..7790bec113 100644
--- a/Userland/Libraries/LibC/fcntl.cpp
+++ b/Userland/Libraries/LibC/fcntl.cpp
@@ -53,42 +53,24 @@ 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)
-{
- return openat_with_path_length(AT_FDCWD, path, path_length, options, mode);
-}
-
-int openat_with_path_length(int dirfd, const char* path, size_t path_length, int options, mode_t mode)
+int open(const char* path, int options, ...)
{
if (!path) {
errno = EFAULT;
return -1;
}
+ auto path_length = strlen(path);
if (path_length > INT32_MAX) {
errno = EINVAL;
return -1;
}
- Syscall::SC_open_params params { dirfd, { path, path_length }, options, mode };
- int rc = syscall(SC_open, &params);
- __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);
+ Syscall::SC_open_params params { AT_FDCWD, { path, path_length }, options, mode };
+ int rc = syscall(SC_open, &params);
+ __RETURN_WITH_ERRNO(rc, rc, -1);
}
int openat(int dirfd, const char* path, int options, ...)
@@ -97,10 +79,17 @@ int openat(int dirfd, const char* path, int options, ...)
errno = EFAULT;
return -1;
}
+ auto path_length = strlen(path);
+ 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);
- return openat_with_path_length(dirfd, path, strlen(path), options, mode);
+ Syscall::SC_open_params params { dirfd, { path, path_length }, options, mode };
+ int rc = syscall(SC_open, &params);
+ __RETURN_WITH_ERRNO(rc, rc, -1);
}
}
diff --git a/Userland/Libraries/LibC/fcntl.h b/Userland/Libraries/LibC/fcntl.h
index 1aa6e6cd09..e184808762 100644
--- a/Userland/Libraries/LibC/fcntl.h
+++ b/Userland/Libraries/LibC/fcntl.h
@@ -85,11 +85,8 @@ __BEGIN_DECLS
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 watch_file(const char* path, size_t path_length);
diff --git a/Userland/Libraries/LibCore/LocalServer.cpp b/Userland/Libraries/LibCore/LocalServer.cpp
index 092cf82388..ec99d51317 100644
--- a/Userland/Libraries/LibCore/LocalServer.cpp
+++ b/Userland/Libraries/LibCore/LocalServer.cpp
@@ -27,6 +27,7 @@
#include <LibCore/LocalServer.h>
#include <LibCore/LocalSocket.h>
#include <LibCore/Notifier.h>
+#include <fcntl.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/Userland/Libraries/LibCore/LocalSocket.cpp b/Userland/Libraries/LibCore/LocalSocket.cpp
index d49aa1d166..81b30d4c0b 100644
--- a/Userland/Libraries/LibCore/LocalSocket.cpp
+++ b/Userland/Libraries/LibCore/LocalSocket.cpp
@@ -26,6 +26,7 @@
#include <LibCore/LocalSocket.h>
#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/stat.h>
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index bd2e220d19..4b7c5d41d9 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -1050,9 +1050,9 @@ void TextEditor::timer_event(Core::TimerEvent&)
update_cursor();
}
-bool TextEditor::write_to_file(const StringView& path)
+bool TextEditor::write_to_file(const String& path)
{
- int fd = open_with_path_length(path.characters_without_null_termination(), path.length(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
perror("open");
return false;
diff --git a/Userland/Libraries/LibGUI/TextEditor.h b/Userland/Libraries/LibGUI/TextEditor.h
index 1ffeb36555..05ddf20383 100644
--- a/Userland/Libraries/LibGUI/TextEditor.h
+++ b/Userland/Libraries/LibGUI/TextEditor.h
@@ -121,7 +121,7 @@ public:
TextRange normalized_selection() const { return m_selection.normalized(); }
void insert_at_cursor_or_replace_selection(const StringView&);
- bool write_to_file(const StringView& path);
+ bool write_to_file(const String& path);
bool has_selection() const { return m_selection.is_valid(); }
String selected_text() const;
void set_selection(const TextRange&);
diff --git a/Userland/Libraries/LibPCIDB/Database.cpp b/Userland/Libraries/LibPCIDB/Database.cpp
index 597868ae1a..bb73c308ea 100644
--- a/Userland/Libraries/LibPCIDB/Database.cpp
+++ b/Userland/Libraries/LibPCIDB/Database.cpp
@@ -32,7 +32,7 @@
namespace PCIDB {
-RefPtr<Database> Database::open(const StringView& file_name)
+RefPtr<Database> Database::open(const String& file_name)
{
auto file_or_error = MappedFile::map(file_name);
if (file_or_error.is_error())
diff --git a/Userland/Libraries/LibPCIDB/Database.h b/Userland/Libraries/LibPCIDB/Database.h
index dbbe8c9482..9bdeafbe93 100644
--- a/Userland/Libraries/LibPCIDB/Database.h
+++ b/Userland/Libraries/LibPCIDB/Database.h
@@ -31,6 +31,7 @@
#include <AK/NonnullOwnPtr.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
+#include <AK/String.h>
#include <AK/StringView.h>
namespace PCIDB {
@@ -72,7 +73,7 @@ struct Class {
class Database : public RefCounted<Database> {
public:
- static RefPtr<Database> open(const StringView& file_name);
+ static RefPtr<Database> open(const String& file_name);
static RefPtr<Database> open() { return open("/res/pci.ids"); };
const StringView get_vendor(u16 vendor_id) const;
diff --git a/Userland/Services/SystemServer/Service.cpp b/Userland/Services/SystemServer/Service.cpp
index 99b01b5ab6..dc798ba8cb 100644
--- a/Userland/Services/SystemServer/Service.cpp
+++ b/Userland/Services/SystemServer/Service.cpp
@@ -174,7 +174,7 @@ void Service::spawn(int socket_fd)
if (!m_stdio_file_path.is_null()) {
close(STDIN_FILENO);
- int fd = open_with_path_length(m_stdio_file_path.characters(), m_stdio_file_path.length(), O_RDWR, 0);
+ int fd = open(m_stdio_file_path.characters(), O_RDWR, 0);
ASSERT(fd <= 0);
if (fd < 0) {
perror("open");
diff --git a/Userland/Shell/AST.cpp b/Userland/Shell/AST.cpp
index 992452f503..91478a77a0 100644
--- a/Userland/Shell/AST.cpp
+++ b/Userland/Shell/AST.cpp
@@ -33,6 +33,7 @@
#include <AK/URL.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
+#include <fcntl.h>
#include <signal.h>
//#define EXECUTE_DEBUG
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp
index 036c097d7a..a7538d5107 100644
--- a/Userland/Utilities/js.cpp
+++ b/Userland/Utilities/js.cpp
@@ -55,6 +55,7 @@
#include <LibJS/Runtime/TypedArray.h>
#include <LibJS/Runtime/Value.h>
#include <LibLine/Editor.h>
+#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
@@ -422,9 +423,9 @@ static StringView strip_shebang(AK::ByteBuffer file_contents)
return StringView((const char*)file_contents.data() + i, file_contents.size() - i);
}
-static bool write_to_file(const StringView& path)
+static bool write_to_file(const String& path)
{
- int fd = open_with_path_length(path.characters_without_null_termination(), path.length(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
for (size_t i = 0; i < repl_statements.size(); i++) {
auto line = repl_statements[i];
if (line.length() && i != repl_statements.size() - 1) {