* 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
This commit is contained in:
parent
71896c7386
commit
6de41102e5
30
src/system/libroot/posix/stdlib/realpath.cpp
Normal file
30
src/system/libroot/posix/stdlib/realpath.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <syscalls.h>
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user