diff options
author | H. Peter Anvin <hpa@zytor.com> | 2016-02-12 01:32:57 -0800 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2016-02-12 01:32:57 -0800 |
commit | d7043da28199f2a98c202a025c8bccf93329deb9 (patch) | |
tree | 753e2902b8c61305e2c02b0927cd65b72f5d772d | |
parent | 67db8184b152b7bb734f4298361416c8340b9db3 (diff) | |
download | nasm-d7043da28199f2a98c202a025c8bccf93329deb9.tar.gz |
realpath: prefer the buffer size given by pathconf()
If realpath(..., NULL) doesn't work, we have to allocate a buffer
blindly. Use the value returned from pathconf() in preference from
compile-time constants.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | realpath.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -80,15 +80,19 @@ char *nasm_realpath(const char *rel_path) int path_max = -1; char *buf; -# ifdef PATH_MAX - path_max = PATH_MAX; /* SUSv2 */ -# elif defined(MAXPATHLEN) - path_max = MAXPATHLEN; /* Solaris */ -# elif defined(HAVE_PATHCONF) && defined(_PC_PATH_MAX) - path_max = pathconf(path, _PC_PATH_MAX); /* POSIX */ -# endif - if (path_max < 0) +#if defined(HAVE_PATHCONF) && defined(_PC_PATH_MAX) + path_max = pathconf(rel_path, _PC_PATH_MAX); /* POSIX */ +#endif + + if (path_max < 0) { +#ifdef PATH_MAX + path_max = PATH_MAX; /* SUSv2 */ +#elif defined(MAXPATHLEN) + path_max = MAXPATHLEN; /* Solaris */ +#else path_max = 65536; /* Crazily high, we hope */ +#endif + } buf = nasm_malloc(path_max); |