forked from selkhateeb/hardlink
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hlink.c
32 lines (30 loc) · 776 Bytes
/
hlink.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
#include <unistd.h>
#include <stdio.h>
#include <string.h>
/*
On Mac OSX, we can't create hard links on directories using the ln command..
Install:
make
sudo make install
*/
int main(int argc, char* argv[]) {
//Make sure we have the right arguments
if (argc != 3)
{
fprintf(stderr,"Usage:\thlink source destination\n");
fprintf(stderr,"\t hard links the source directory to the destination\n");
fprintf(stderr,"\thlink -u destination\n");
fprintf(stderr,"\t unlinks the destination directoy\n");
return 1;
}
int ret = 0;
if(strcmp(argv[1], "-u") == 0)
{
ret = unlink(argv[2]);
}
else
ret = link(argv[1],argv[2]);
if (ret != 0)
perror("hlink");
return ret;
}