xfstests: resolve symlinked devices to real paths
[xfstests-dev.git] / src / realpath.c
1 #include <limits.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5
6 /*
7  * Simple wrapper around realpath(3) to get absolute path
8  * to a device name; many xfstests scripts don't cope well
9  * with symlinked devices due to differences in /proc/mounts,
10  * /etc/mtab, mount output, etc.
11  */
12
13 int main(int argc, char *argv[])
14 {
15         char path[PATH_MAX];
16         char resolved_path[PATH_MAX];
17
18         if (argc != 2) {
19                 printf("Usage: %s <filename>\n", argv[0]);
20                 return 1;
21         }
22
23         strncpy(path, argv[1], PATH_MAX-1);
24
25         if (!realpath(path, resolved_path)) {
26                 perror("Failed to resolve path for %s");
27                 return 1;
28         }
29
30         printf("%s\n", resolved_path);
31         return 0;
32 }