瀏覽代碼

LibCore: Add a small library with only ArgsParser for DynamicLoader

This will be used in the DynamicLoader code, as it can't do syscalls via
LibCore code.
Because we can't use most of the LibCore code, we convert the versioning
code in Version.cpp to use LibC uname() function.
Liav A 1 年之前
父節點
當前提交
7e8dfe758c
共有 2 個文件被更改,包括 18 次插入5 次删除
  1. 7 0
      Userland/Libraries/LibCore/CMakeLists.txt
  2. 11 5
      Userland/Libraries/LibCore/Version.cpp

+ 7 - 0
Userland/Libraries/LibCore/CMakeLists.txt

@@ -17,6 +17,13 @@ set(SOURCES
 serenity_lib(LibCoreMinimal coreminimal)
 target_link_libraries(LibCoreMinimal PRIVATE LibSystem)
 
+if (SERENITYOS)
+    add_library(DynamicLoader_LibCoreArgsParser 
+        ArgsParser.cpp
+        Version.cpp)
+    target_link_libraries(DynamicLoader_LibCoreArgsParser PUBLIC DynamicLoader_CompileOptions)
+endif()
+
 set(SOURCES
     AnonymousBuffer.cpp
     Command.cpp

+ 11 - 5
Userland/Libraries/LibCore/Version.cpp

@@ -5,18 +5,24 @@
  */
 
 #include <AK/String.h>
-#include <LibCore/System.h>
 #include <LibCore/Version.h>
 
+#ifdef AK_OS_SERENITY
+#    include <sys/utsname.h>
+#endif
+
 namespace Core::Version {
 
 ErrorOr<String> read_long_version_string()
 {
 #ifdef AK_OS_SERENITY
-    auto uname = TRY(Core::System::uname());
-
-    auto const* version = uname.release;
-    auto const* git_hash = uname.version;
+    struct utsname uts;
+    int rc = uname(&uts);
+    if ((rc) < 0) {
+        return Error::from_syscall("uname"sv, rc);
+    }
+    auto const* version = uts.release;
+    auto const* git_hash = uts.version;
 
     return String::formatted("Version {} revision {}", version, git_hash);
 #else