Explorar o código

Userland: Add realpath

Rok Povsic %!s(int64=6) %!d(string=hai) anos
pai
achega
e36b9635df
Modificáronse 1 ficheiros con 22 adicións e 0 borrados
  1. 22 0
      Userland/realpath.cpp

+ 22 - 0
Userland/realpath.cpp

@@ -0,0 +1,22 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char** argv)
+{
+    if (argc != 2) {
+        printf("usage: realpath <path>\n");
+        return 1;
+    }
+
+    char* value = realpath(argv[1], nullptr);
+    if (value == nullptr) {
+        printf("realpath() error: %s\n", strerror(errno));
+        return 1;
+    }
+    printf("%s\n", value);
+    free(value);
+    return 0;
+}