diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c --- a/lib/libc/stdlib/realpath.c +++ b/lib/libc/stdlib/realpath.c @@ -212,7 +212,7 @@ char * __ssp_real(realpath)(const char * __restrict path, char * __restrict resolved) { - char *m, *res; + char *m = NULL, *res = NULL; if (path == NULL) { errno = EINVAL; @@ -222,17 +222,14 @@ errno = ENOENT; return (NULL); } - if (resolved != NULL) { - m = NULL; - } else { - m = resolved = malloc(PATH_MAX); - if (resolved == NULL) + if (resolved == NULL) { + if ((resolved = m = malloc(PATH_MAX)) == NULL) return (NULL); } - if (__sys___realpathat(AT_FDCWD, path, resolved, PATH_MAX, 0) == 0) { - return (resolved); - } - res = realpath1(path, resolved); + if (__sys___realpathat(AT_FDCWD, path, resolved, PATH_MAX, 0) == 0) + res = resolved; + else if (errno == ENOSYS || m == NULL) + res = realpath1(path, resolved); if (res == NULL) free(m); return (res);