From: Alejandro Colomar Date: Sat, 22 Feb 2025 23:22:13 +0000 (+0100) Subject: lib/commonio.c: Rely on the POSIX.1-2008 behavior of realpath(3) X-Git-Tag: 4.17.4~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a1666323379354cf7834254e21a5de383956221;p=thirdparty%2Fshadow.git lib/commonio.c: Rely on the POSIX.1-2008 behavior of realpath(3) Link: Link: Reported-by: Samuel Thibault Signed-off-by: Alejandro Colomar --- diff --git a/lib/commonio.c b/lib/commonio.c index b7c9a2d41..fc8ad7a57 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -74,17 +74,10 @@ int lrename (const char *old, const char *new) { int res; char *r = NULL; - -#ifndef __GLIBC__ - char resolved_path[PATH_MAX]; -#endif /* !__GLIBC__ */ struct stat sb; + if (lstat (new, &sb) == 0 && S_ISLNK (sb.st_mode)) { -#ifdef __GLIBC__ /* now a POSIX.1-2008 feature */ r = realpath (new, NULL); -#else /* !__GLIBC__ */ - r = realpath (new, resolved_path); -#endif /* !__GLIBC__ */ if (NULL == r) { perror ("realpath in lrename()"); } else { @@ -94,9 +87,7 @@ int lrename (const char *old, const char *new) res = rename (old, new); -#ifdef __GLIBC__ free (r); -#endif /* __GLIBC__ */ return res; }