ee71580 |
Jamozed |
2020-07-06 22:45:39 |
0
|
// link.c, version 1.0.1 |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
1
|
// OMKOV coreutils implementation of POSIX link |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
2
|
// Copyright (C) 2020, Jakob Wakeling |
e2140ec |
Jamozed |
2022-03-06 15:27:45 |
3
|
// MIT Licence |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
4
|
|
b181413 |
Jamozed |
2022-02-05 22:32:00 |
5
|
#include "util/error.h" |
b181413 |
Jamozed |
2022-02-05 22:32:00 |
6
|
#include "util/optget.h" |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
7
|
|
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
8
|
#include <unistd.h> |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
9
|
|
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
10
|
#include <stdio.h> |
ee71580 |
Jamozed |
2020-07-06 22:45:39 |
11
|
|
ee71580 |
Jamozed |
2020-07-06 22:45:39 |
12
|
#define VERSION "1.0.1" |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
13
|
|
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
14
|
static struct lop lops[] = { |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
15
|
{ "help", ARG_NUL, 256 }, |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
16
|
{ "version", ARG_NUL, 257 }, |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
17
|
{ NULL, 0, 0 } |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
18
|
}; |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
19
|
|
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
20
|
static void hlp(void); |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
21
|
static void ver(void); |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
22
|
|
ee71580 |
Jamozed |
2020-07-06 22:45:39 |
23
|
int main(int ac, char *av[]) { A0 = av[0]; |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
24
|
struct opt opt = OPTGET_INIT; opt.str = ""; opt.lops = lops; |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
25
|
for (int o; (o = optget(&opt, av, 1)) != -1;) switch (o) { |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
26
|
case 256: { hlp(); return 0; } |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
27
|
case 257: { ver(); return 0; } |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
28
|
default: { return 1; } |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
29
|
} |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
30
|
|
ee71580 |
Jamozed |
2020-07-06 22:45:39 |
31
|
if (ac <= 2) { error(1, "missing operand"); } |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
32
|
|
ee71580 |
Jamozed |
2020-07-06 22:45:39 |
33
|
if (link(av[1], av[2])) { error(1, "%s: %s", av[1], serr()); } |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
34
|
|
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
35
|
return 0; |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
36
|
} |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
37
|
|
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
38
|
static void hlp(void) { |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
39
|
puts("link - create a link to a file\n"); |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
40
|
puts("usage: link file1 file2\n"); |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
41
|
puts("options:"); |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
42
|
puts(" --help Display help information"); |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
43
|
puts(" --version Display version information"); |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
44
|
} |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
45
|
|
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
46
|
static void ver(void) { |
ee71580 |
Jamozed |
2020-07-06 22:45:39 |
47
|
puts("OMKOV coreutils link, version " VERSION); |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
48
|
puts("Copyright (C) 2020, Jakob Wakeling"); |
e2140ec |
Jamozed |
2022-03-06 15:27:45 |
49
|
puts("MIT Licence (https://opensource.org/licenses/MIT)"); |
d1a0c88 |
Jamozed |
2020-06-26 18:09:15 |
50
|
} |
|
|
|
51
|
|