-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsymlink.c
More file actions
28 lines (26 loc) · 679 Bytes
/
symlink.c
File metadata and controls
28 lines (26 loc) · 679 Bytes
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
/* Symbolic links
* November 28, 2021 */
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "USAGE: %s [filename] [symbolic link]\n", argv[0]);
return 1;
}
if (symlink(argv[1], argv[2]) != 0) {
if (errno == EEXIST)
fprintf(stderr, "ERROR: Symlink output already exists\n");
else if (errno == EACCES)
fprintf(stderr, "ERROR: No write permission in directory\n");
else if (errno == ELOOP)
fprintf(stderr, "ERROR: Symbolic link loop\n");
else
fprintf(stderr, "ERROR: Could not make symbolic link\n");
return 2;
}
else {
printf("Created symbolic link\n");
return 0;
}
}