-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht.c
More file actions
46 lines (39 loc) · 1.13 KB
/
t.c
File metadata and controls
46 lines (39 loc) · 1.13 KB
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
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
return 1;
}
// Create a hardlink
int hLink = link(argv[1], "hardLink.txt");
// Create a softlink
int sLink = symlink(argv[1], "softLink.txt");
struct stat st;
struct stat lst;
if (hLink != -1) {
if (stat(argv[1], &st) != -1) {
printf("Original file inode no: %lu\n", st.st_ino);
printf("Hardlink inode no: %lu\n", st.st_ino);
printf("Hardlink created successfully\n");
} else {
perror("Error in getting file stats");
}
} else {
perror("Error in creating hardlink");
}
if (sLink != -1) {
if (lstat(, &lst) != -1) {
printf("Softlink inode no: %lu\n", lst.st_ino);
printf("Softlink created successfully\n");
} else {
perror("Error in getting softlink stats");
}
} else {
perror("Error in creating softlink");
}
return 0;
}