mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-09-22 10:43:39 -04:00
realpath: if we can't get the full path, return the known portion
Right now, we don't check the return value from nasm_realpath(); furthermore doing so and failing is probably not the ideal behavior. If we can't get the full canonical path, then punt and just return nasm_strdup() of the known path name; better than nothing. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
32
realpath.c
32
realpath.c
@@ -57,7 +57,8 @@
|
|||||||
*/
|
*/
|
||||||
char *nasm_realpath(const char *rel_path)
|
char *nasm_realpath(const char *rel_path)
|
||||||
{
|
{
|
||||||
return canonicalize_file_name(rel_path);
|
char *rp = canonicalize_file_name(rel_path);
|
||||||
|
return rp ? rp : nasm_strdup(rel_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(HAVE_REALPATH)
|
#elif defined(HAVE_REALPATH)
|
||||||
@@ -69,16 +70,14 @@ char *nasm_realpath(const char *rel_path)
|
|||||||
|
|
||||||
char *nasm_realpath(const char *rel_path)
|
char *nasm_realpath(const char *rel_path)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *rp;
|
||||||
|
|
||||||
buf = realpath(rel_path, NULL);
|
rp = realpath(rel_path, NULL);
|
||||||
if (buf)
|
|
||||||
return buf;
|
|
||||||
|
|
||||||
/* Not all implemetations of realpath() support a NULL second argument */
|
/* Not all implemetations of realpath() support a NULL second argument */
|
||||||
if (errno == EINVAL) {
|
if (!rp && errno == EINVAL) {
|
||||||
int path_max = -1;
|
long path_max = -1;
|
||||||
char *buf;
|
char *rp;
|
||||||
|
|
||||||
#if defined(HAVE_PATHCONF) && defined(_PC_PATH_MAX)
|
#if defined(HAVE_PATHCONF) && defined(_PC_PATH_MAX)
|
||||||
path_max = pathconf(rel_path, _PC_PATH_MAX); /* POSIX */
|
path_max = pathconf(rel_path, _PC_PATH_MAX); /* POSIX */
|
||||||
@@ -94,20 +93,20 @@ char *nasm_realpath(const char *rel_path)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = nasm_malloc(path_max);
|
rp = nasm_malloc(path_max);
|
||||||
|
|
||||||
if (!realpath(rel_path, buf)) {
|
if (!realpath(rel_path, rp)) {
|
||||||
nasm_free(buf);
|
nasm_free(rp);
|
||||||
buf = NULL;
|
rp = NULL;
|
||||||
} else {
|
} else {
|
||||||
/* On some systems, pathconf() can return a very large value */
|
/* On some systems, pathconf() can return a very large value */
|
||||||
|
|
||||||
buf[path_max - 1] = '\0'; /* Just in case overrun is possible */
|
rp[path_max - 1] = '\0'; /* Just in case overrun is possible */
|
||||||
buf = nasm_realloc(buf, strlen(buf) + 1);
|
rp = nasm_realloc(rp, strlen(rp) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf;
|
return rp ? rp : nasm_strdup(rel_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(HAVE__FULLPATH)
|
#elif defined(HAVE__FULLPATH)
|
||||||
@@ -118,7 +117,8 @@ char *nasm_realpath(const char *rel_path)
|
|||||||
|
|
||||||
char *nasm_realpath(const char *rel_path)
|
char *nasm_realpath(const char *rel_path)
|
||||||
{
|
{
|
||||||
return _fullpath(NULL, rel_path, 0);
|
char *rp = _fullpath(NULL, rel_path, 0);
|
||||||
|
return rp ? rp : nasm_strdup(rel_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
Reference in New Issue
Block a user