From 1096eb4195cca417b8b39a08c4b3893a15c31666 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Olivier=20Coursi=C3=A8re?= <olivier.coursiere@laposte.net>
Date: Sat, 17 Aug 2013 17:40:46 +0000
Subject: [PATCH] * Add support for NULL as resolved_name argument in realpath
as defined in The Open Group Base Specifications Issue 7
IEEE Std 1003.1, 2013 Edition
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/realpath.html).
In this case, the returned buffer is allocated by realpath and can be
passed to free().
The behavior was only "implementation defined" in previous revision like
The Open Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition
(http://pubs.opengroup.org/onlinepubs/000095399/functions/realpath.html).
---
src/system/libroot/posix/stdlib/realpath.cpp | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/system/libroot/posix/stdlib/realpath.cpp b/src/system/libroot/posix/stdlib/realpath.cpp
index 575198e..2dff9fb 100644
a
|
b
|
|
16 | 16 | char* |
17 | 17 | realpath(const char* path, char* resolved) |
18 | 18 | { |
19 | | status_t status = _kern_normalize_path(path, true, resolved); |
| 19 | char* resolvedPath = resolved; |
| 20 | |
| 21 | if (resolvedPath == NULL) { |
| 22 | resolvedPath = (char*)malloc(PATH_MAX + 1); |
| 23 | if (resolvedPath == NULL) { |
| 24 | __set_errno(B_NO_MEMORY); |
| 25 | return NULL; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | status_t status = _kern_normalize_path(path, true, resolvedPath); |
20 | 30 | if (status != B_OK) { |
21 | 31 | __set_errno(status); |
22 | 32 | return NULL; |
… |
… |
realpath(const char* path, char* resolved)
|
24 | 34 | |
25 | 35 | // The path must actually exist, not just its parent directories |
26 | 36 | struct stat stat; |
27 | | if (lstat(resolved, &stat) != 0) |
| 37 | if (lstat(resolvedPath, &stat) != 0) |
28 | 38 | return NULL; |
29 | 39 | |
30 | | return resolved; |
| 40 | return resolvedPath; |
31 | 41 | } |