From 6de41102e5d2f7043c5053cef301ffbde3eccb6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 10 Jul 2009 12:27:05 +0000 Subject: [PATCH] * Replaced the broken BSD realpath() that is neither thread-safe nor POSIX compliant with one that is both, and magnitudes faster at that, too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31498 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/stdlib/realpath.cpp | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/system/libroot/posix/stdlib/realpath.cpp 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; +}