use restrict everywhere it's required by c99 and/or posix 2008
[musl] / src / misc / realpath.c
index 8dcf5ec..5756817 100644 (file)
@@ -6,7 +6,7 @@
 #include <errno.h>
 #include <unistd.h>
 
-char *realpath(const char *filename, char *resolved)
+char *realpath(const char *restrict filename, char *restrict resolved)
 {
        int fd;
        ssize_t r;
@@ -19,16 +19,16 @@ char *realpath(const char *filename, char *resolved)
                return 0;
        }
 
+       fd = open(filename, O_RDONLY|O_NONBLOCK);
+       if (fd < 0) return 0;
+       snprintf(buf, sizeof buf, "/proc/self/fd/%d", fd);
+
        if (!resolved) {
                alloc = 1;
                resolved = malloc(PATH_MAX);
                if (!resolved) return 0;
        }
 
-       fd = open(filename, O_RDONLY|O_NONBLOCK);
-       if (fd < 0) return 0;
-       snprintf(buf, sizeof buf, "/proc/self/fd/%d", fd);
-
        r = readlink(buf, resolved, PATH_MAX-1);
        if (r < 0) goto err;
        resolved[r] = 0;