]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/vfscore: Implement `getcwd` with a raw system call
authorSimon Kuenzer <simon.kuenzer@neclab.eu>
Mon, 21 Dec 2020 15:47:33 +0000 (16:47 +0100)
committerSharan Santhanam <sharan.santhanam@neclab.eu>
Fri, 29 Jan 2021 11:01:02 +0000 (16:31 +0530)
Implements `getcwd` with a raw system call (`UK_SYSCALL_R_DEFINE`)
instead. This variant should be preferred because it avoids the
usage of `errno`.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Liza Babu <lizza.babu@gmail.com>
lib/vfscore/main.c

index 458345a5cff2416849739c3242cb05309de77a2c..0e2230ab006be61359713cc11ef12191eaf9af95 100644 (file)
@@ -1361,7 +1361,7 @@ UK_TRACEPOINT(trace_vfs_getcwd, "%p %d", char*, size_t);
 UK_TRACEPOINT(trace_vfs_getcwd_ret, "\"%s\"", const char*);
 UK_TRACEPOINT(trace_vfs_getcwd_err, "%d", int);
 
-UK_SYSCALL_DEFINE(char*, getcwd, char*, path, size_t, size)
+UK_SYSCALL_R_DEFINE(char*, getcwd, char*, path, size_t, size)
 {
        trace_vfs_getcwd(path, size);
        struct task *t = main_task;
@@ -1370,7 +1370,7 @@ UK_SYSCALL_DEFINE(char*, getcwd, char*, path, size_t, size)
 
        if (size < len) {
                error = ERANGE;
-               goto out_errno;
+               goto out_error;
        }
 
        if (!path) {
@@ -1379,12 +1379,12 @@ UK_SYSCALL_DEFINE(char*, getcwd, char*, path, size_t, size)
                path = (char*)malloc(size);
                if (!path) {
                        error = ENOMEM;
-                       goto out_errno;
+                       goto out_error;
                }
        } else {
                if (!size) {
                        error = EINVAL;
-                       goto out_errno;
+                       goto out_error;
                }
        }
 
@@ -1392,10 +1392,9 @@ UK_SYSCALL_DEFINE(char*, getcwd, char*, path, size_t, size)
        trace_vfs_getcwd_ret(path);
        return path;
 
-       out_errno:
+out_error:
        trace_vfs_getcwd_err(error);
-       errno = error;
-       return NULL;
+       return ERR2PTR(-error);
 }
 
 UK_TRACEPOINT(trace_vfs_dup, "%d", int);