In Cwd.xs, tidy the conditional code related to symlinks.
authorNicholas Clark <nick@ccl4.org>
Tue, 5 Jul 2011 10:12:47 +0000 (12:12 +0200)
committerNicholas Clark <nick@ccl4.org>
Wed, 6 Jul 2011 08:28:36 +0000 (10:28 +0200)
Move the variable symlink inside the conditionally compiled code, to avoid
on platforms which don't have symlinks about an unused variable.
Move the pre-processor directives back to column zero - they were indented as
part of the upgrade to PathTools 3.26_01 in c7304ea2604337d2.
Correct the indentation of some lines [always just a closing '}'], which was
making the code harder to follow. All these lines seem to have been left
unaltered by c7304ea2604337d2, when code surrounding them changed.

dist/Cwd/Cwd.xs

index 7263c09..d55c318 100644 (file)
@@ -71,7 +71,7 @@ bsd_realpath(const char *path, char resolved[MAXPATHLEN])
        size_t left_len, resolved_len;
        unsigned symlinks;
        int serrno;
-       char left[MAXPATHLEN], next_token[MAXPATHLEN], symlink[MAXPATHLEN];
+       char left[MAXPATHLEN], next_token[MAXPATHLEN];
 
        serrno = errno;
        symlinks = 0;
@@ -150,7 +150,7 @@ bsd_realpath(const char *path, char resolved[MAXPATHLEN])
                        errno = ENAMETOOLONG;
                        return (NULL);
                }
-       #if defined(HAS_LSTAT) && defined(HAS_READLINK) && defined(HAS_SYMLINK)
+#if defined(HAS_LSTAT) && defined(HAS_READLINK) && defined(HAS_SYMLINK)
                {
                        struct stat sb;
                        if (lstat(resolved, &sb) != 0) {
@@ -162,6 +162,7 @@ bsd_realpath(const char *path, char resolved[MAXPATHLEN])
                        }
                        if (S_ISLNK(sb.st_mode)) {
                                int slen;
+                               char symlink[MAXPATHLEN];
                                
                                if (symlinks++ > MAXSYMLINKS) {
                                        errno = ELOOP;
@@ -190,22 +191,22 @@ bsd_realpath(const char *path, char resolved[MAXPATHLEN])
                                if (p != NULL) {
                                        if (symlink[slen - 1] != '/') {
                                                if ((STRLEN)(slen + 1) >= (STRLEN)sizeof(symlink)) {
-                       errno = ENAMETOOLONG;
+                                                       errno = ENAMETOOLONG;
                                                        return (NULL);
-               }
+                                               }
                                                symlink[slen] = '/';
                                                symlink[slen + 1] = 0;
-       }
+                                       }
                                        left_len = my_strlcat(symlink, left, sizeof(left));
                                        if (left_len >= sizeof(left)) {
                                                errno = ENAMETOOLONG;
                                                return (NULL);
-       }
-       }
+                                       }
+                               }
                                left_len = my_strlcpy(left, symlink, sizeof(left));
                        }
                }
-       #endif
+#endif
        }
 
        /*