summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2016-02-18 02:00:16 -0800
committerH. Peter Anvin <hpa@linux.intel.com>2016-02-18 02:00:16 -0800
commitf0ea3d7c2b9f3767788fa3945fcdcc8606c0ef69 (patch)
treefd7f8ad56b3a4a7d844e35280606e56fb99382b3
parent501b35f234cb605ab576147ba7e20bfb986f7fd1 (diff)
parent9e122a6603af15472d2acdcf8563fcd0fc96bb0c (diff)
downloadnasm-f0ea3d7c2b9f3767788fa3945fcdcc8606c0ef69.tar.gz
Merge branch 'master' into elfmerge
-rw-r--r--realpath.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/realpath.c b/realpath.c
index 48b685ab..d93dc15f 100644
--- a/realpath.c
+++ b/realpath.c
@@ -57,7 +57,8 @@
*/
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)
@@ -69,16 +70,14 @@ char *nasm_realpath(const char *rel_path)
char *nasm_realpath(const char *rel_path)
{
- char *buf;
+ char *rp;
- buf = realpath(rel_path, NULL);
- if (buf)
- return buf;
+ rp = realpath(rel_path, NULL);
/* Not all implemetations of realpath() support a NULL second argument */
- if (errno == EINVAL) {
- int path_max = -1;
- char *buf;
+ if (!rp && errno == EINVAL) {
+ long path_max = -1;
+ char *rp;
#if defined(HAVE_PATHCONF) && defined(_PC_PATH_MAX)
path_max = pathconf(rel_path, _PC_PATH_MAX); /* POSIX */
@@ -94,20 +93,20 @@ char *nasm_realpath(const char *rel_path)
#endif
}
- buf = nasm_malloc(path_max);
+ rp = nasm_malloc(path_max);
- if (!realpath(rel_path, buf)) {
- nasm_free(buf);
- buf = NULL;
+ if (!realpath(rel_path, rp)) {
+ nasm_free(rp);
+ rp = NULL;
} else {
/* On some systems, pathconf() can return a very large value */
- buf[path_max - 1] = '\0'; /* Just in case overrun is possible */
- buf = nasm_realloc(buf, strlen(buf) + 1);
+ rp[path_max - 1] = '\0'; /* Just in case overrun is possible */
+ rp = nasm_realloc(rp, strlen(rp) + 1);
}
}
- return buf;
+ return rp ? rp : nasm_strdup(rel_path);
}
#elif defined(HAVE__FULLPATH)
@@ -118,7 +117,8 @@ 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