Kernel/LibC: Implement realpath
realpath is implemented as a syscall. This is not really required but it was the easiest way to get it working as there is already path canonicalization at kernel level.
This commit is contained in:
@@ -81,6 +81,7 @@ __BEGIN_DECLS
|
||||
O(SYS_GETSOCKNAME, getsockname) \
|
||||
O(SYS_GETSOCKOPT, getsockopt) \
|
||||
O(SYS_SETSOCKOPT, setsockopt) \
|
||||
O(SYS_REALPATH, realpath) \
|
||||
|
||||
enum Syscall
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <icxxabi.h>
|
||||
@@ -368,6 +369,22 @@ char* getenv(const char* name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char* realpath(const char* __restrict file_name, char* __restrict resolved_name)
|
||||
{
|
||||
char buffer[PATH_MAX] {};
|
||||
long canonical_length = syscall(SYS_REALPATH, file_name, buffer);
|
||||
if (canonical_length == -1)
|
||||
return NULL;
|
||||
if (resolved_name == NULL)
|
||||
{
|
||||
resolved_name = static_cast<char*>(malloc(canonical_length + 1));
|
||||
if (resolved_name == NULL)
|
||||
return NULL;
|
||||
}
|
||||
strcpy(resolved_name, buffer);
|
||||
return resolved_name;
|
||||
}
|
||||
|
||||
int system(const char* command)
|
||||
{
|
||||
// FIXME
|
||||
|
||||
Reference in New Issue
Block a user