瀏覽代碼

LibCore: Add an ErrorOr wrapper for uname

mjz19910 3 年之前
父節點
當前提交
91f5fc796b
共有 2 個文件被更改,包括 15 次插入0 次删除
  1. 13 0
      Userland/Libraries/LibCore/System.cpp
  2. 2 0
      Userland/Libraries/LibCore/System.h

+ 13 - 0
Userland/Libraries/LibCore/System.cpp

@@ -648,6 +648,19 @@ ErrorOr<void> utime(StringView path, Optional<struct utimbuf> maybe_buf)
 #endif
 #endif
 }
 }
 
 
+ErrorOr<struct utsname> uname()
+{
+    utsname uts;
+#ifdef __serenity__
+    int rc = syscall(SC_uname, &uts);
+    HANDLE_SYSCALL_RETURN_VALUE("uname"sv, rc, uts);
+#else
+    if (::uname(&uts) < 0)
+        return Error::from_syscall("uname"sv, -errno);
+#endif
+    return uts;
+}
+
 ErrorOr<int> socket(int domain, int type, int protocol)
 ErrorOr<int> socket(int domain, int type, int protocol)
 {
 {
     auto fd = ::socket(domain, type, protocol);
     auto fd = ::socket(domain, type, protocol);

+ 2 - 0
Userland/Libraries/LibCore/System.h

@@ -17,6 +17,7 @@
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
+#include <sys/utsname.h>
 #include <sys/wait.h>
 #include <sys/wait.h>
 #include <termios.h>
 #include <termios.h>
 #include <time.h>
 #include <time.h>
@@ -97,6 +98,7 @@ ErrorOr<int> mkstemp(Span<char> pattern);
 ErrorOr<void> fchmod(int fd, mode_t mode);
 ErrorOr<void> fchmod(int fd, mode_t mode);
 ErrorOr<void> rename(StringView old_path, StringView new_path);
 ErrorOr<void> rename(StringView old_path, StringView new_path);
 ErrorOr<void> utime(StringView path, Optional<struct utimbuf>);
 ErrorOr<void> utime(StringView path, Optional<struct utimbuf>);
+ErrorOr<struct utsname> uname();
 ErrorOr<Array<int, 2>> pipe2(int flags);
 ErrorOr<Array<int, 2>> pipe2(int flags);
 
 
 ErrorOr<int> socket(int domain, int type, int protocol);
 ErrorOr<int> socket(int domain, int type, int protocol);