mirror of
https://github.com/netwide-assembler/nasm
synced 2026-08-26 16:23:04 -04:00
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>
This commit is contained in:
parent
67db8184b1
commit
d7043da281
1 changed files with 12 additions and 8 deletions
20
realpath.c
20
realpath.c
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue