Import Upstream version 2.5+git20181211
Gürkan Myczko authored 4 years ago
root committed 4 years ago
24 | 24 | // the path. So this implementation is limited, it's really better to |
25 | 25 | // use realpath() if your platform has it. |
26 | 26 | |
27 | #if defined(__GP2X__) || defined(__WIZ__) || defined(__CAANOO__) || defined(__amigaos__) | |
27 | #if !defined(PATH_MAX) | |
28 | 28 | // This is a random default value ... |
29 | #define PATH_MAX 32768 | |
29 | #define PATH_MAX 4096 | |
30 | 30 | #endif |
31 | 31 | |
32 | 32 | static char *sep(char *path) |
122 | 122 | return _fullpath(resolved_path,_path,260); |
123 | 123 | } |
124 | 124 | #else |
125 | #include <limits.h> | |
125 | ||
126 | 126 | // Use the stdlib function. |
127 | 127 | char *Realpath(const char *_path, char *resolved_path) |
128 | 128 | { |
129 | // While linux version of realpath handles the resolved_path being a | |
130 | // null pointer, this is not the case for other platforms (Haiku), nor | |
131 | // specified by the open group in POSIX. So, be safe and allocate | |
132 | // ourselves. | |
133 | if(resolved_path==NULL) // if we called realpath with null as a 2nd arg | |
134 | resolved_path = (char*) malloc( PATH_MAX ); | |
135 | return realpath(_path, resolved_path); | |
129 | /// POSIX 2004 states : | |
130 | /// If resolved_name is a null pointer, the behavior of realpath() | |
131 | /// is implementation-defined. | |
132 | /// | |
133 | /// but POSIX 2008 : | |
134 | /// If resolved_name is a null pointer, the generated pathname shall | |
135 | /// be stored as a null-terminated string in a buffer allocated as if | |
136 | /// by a call to malloc(). | |
137 | /// | |
138 | /// So we assume all platforms now support passing NULL. | |
139 | /// If you find a platform where this is not the case, | |
140 | /// please add a new implementation with #ifdef's. | |
141 | return realpath(_path, resolved_path); | |
136 | 142 | } |
137 | 143 | #endif |
138 | ||
139 |