-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflink.c
43 lines (35 loc) · 848 Bytes
/
flink.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <assert.h>
#include "mutil.h"
#include "mdebug.h"
#define MAXPATH 4096
int
main(int argc, char *argv[]) {
char usage[] = "Usage: flink <symlink path>\n"
" [-h]\n";
char *path = NULL;
if (argc < 2) {
fprintf(stderr, usage);
return 1;
} else {
for (int i = 0; i < argc; ++i) {
if (strncmp(argv[i], "-h", 2) == 0) {
fprintf(stderr, "Usage: bins [-h]\n");
return 1;
} else {
path = argv[i];
}
}
}
if (path == NULL) {
fprintf(stderr, usage);
return 1;
}
char buffer[MAXPATH];
ssize_t nbytes = followlink(path, buffer, MAXPATH);
if (nbytes < 0) {
return 1;
}
printf("%s\n", buffer);
return 0;
}