syscalls: stat: make return values sane and fix check

This commit is contained in:
Matheus
2022-08-29 00:22:22 -03:00
parent cd8b9ae1e6
commit 1bef1e3dee
+7 -4
View File
@@ -9,9 +9,9 @@
#include <string.h> #include <string.h>
syscallret syscall_stat(const char* path, stat* st){ syscallret syscall_stat(const char* path, stat* st){
syscallret retv;
syscallret retv;
retv.ret = -1; retv.ret = -1;
if(st > USER_SPACE_END || path > USER_SPACE_END){ if(st > USER_SPACE_END || path > USER_SPACE_END){
retv.errno = EFAULT; retv.errno = EFAULT;
return retv; return retv;
@@ -19,7 +19,7 @@ syscallret syscall_stat(const char* path, stat* st){
char* kpath = alloc(strlen(path)); // XXX use proper user strlen func char* kpath = alloc(strlen(path)); // XXX use proper user strlen func
if(!path){ if(!kpath){
retv.errno = ENOMEM; retv.errno = ENOMEM;
return retv; return retv;
} }
@@ -32,6 +32,7 @@ syscallret syscall_stat(const char* path, stat* st){
int ret = vfs_open(&file, *kpath == '/' ? proc->root : proc->cwd, kpath); int ret = vfs_open(&file, *kpath == '/' ? proc->root : proc->cwd, kpath);
if(ret){ if(ret){
retv.errno = ret; retv.errno = ret;
goto _ret; goto _ret;
@@ -42,7 +43,9 @@ syscallret syscall_stat(const char* path, stat* st){
vfs_close(file); vfs_close(file);
memcpy(st, &stbuff, sizeof(stat)); // XXX use user memcpy memcpy(st, &stbuff, sizeof(stat)); // XXX use user memcpy
retv.ret = 0;
retv.errno = 0;
_ret: _ret:
free(kpath); free(kpath);
return retv; return retv;