]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/commonio.c: Rely on the POSIX.1-2008 behavior of realpath(3)
authorAlejandro Colomar <alx@kernel.org>
Sat, 22 Feb 2025 23:22:13 +0000 (00:22 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 3 Mar 2025 09:21:31 +0000 (10:21 +0100)
Link: <https://github.com/shadow-maint/shadow/pull/1222#discussion_r1966612238>
Link: <https://stackoverflow.com/questions/60802732/are-realpath-portability-concerns-obsolete>
Reported-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/commonio.c

index b7c9a2d418da132a8a716b7ce74e908ed22ea8b0..fc8ad7a57b51da3454f0ed0059f76751655b8a77 100644 (file)
@@ -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;
 }