Ticket #9931: 0001-Add-support-for-NULL-as-resolved_name-argument-in-re.patch

File 0001-Add-support-for-NULL-as-resolved_name-argument-in-re.patch, 1.8 KB (added by oco, 11 years ago)
  • src/system/libroot/posix/stdlib/realpath.cpp

    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  
    1616char*
    1717realpath(const char* path, char* resolved)
    1818{
    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);
    2030    if (status != B_OK) {
    2131        __set_errno(status);
    2232        return NULL;
    realpath(const char* path, char* resolved)  
    2434
    2535    // The path must actually exist, not just its parent directories
    2636    struct stat stat;
    27     if (lstat(resolved, &stat) != 0)
     37    if (lstat(resolvedPath, &stat) != 0)
    2838        return NULL;
    2939
    30     return resolved;
     40    return resolvedPath;
    3141}