diff --git a/src/system/libroot/posix/stdlib/realpath.cpp b/src/system/libroot/posix/stdlib/realpath.cpp new file mode 100644 index 0000000000..5a5b70fd6c --- /dev/null +++ b/src/system/libroot/posix/stdlib/realpath.cpp @@ -0,0 +1,30 @@ +/* + * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include + +#include + + +char* +realpath(const char* path, char* resolved) +{ + status_t status = _kern_normalize_path(path, true, resolved); + if (status != B_OK) { + errno = status; + return NULL; + } + + // The path must actually exist, not just its parent directories + struct stat stat; + if (lstat(resolved, &stat) != 0) + return NULL; + + return resolved; +}