82b2c72 |
Jamozed |
2020-07-06 23:57:41 |
0
|
// unlink.c, version 1.0.1 |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
1
|
// OMKOV coreutils implementation of POSIX unlink |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
2
|
// Copyright (C) 2020, Jakob Wakeling |
e2140ec |
Jamozed |
2022-03-06 15:27:45 |
3
|
// MIT Licence |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
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" |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
7
|
|
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
8
|
#include <unistd.h> |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
9
|
|
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
10
|
#include <stdio.h> |
82b2c72 |
Jamozed |
2020-07-06 23:57:41 |
11
|
|
82b2c72 |
Jamozed |
2020-07-06 23:57:41 |
12
|
#define VERSION "1.0.1" |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
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); |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
22
|
|
82b2c72 |
Jamozed |
2020-07-06 23:57:41 |
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; } |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
28
|
default: { return 1; } |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
29
|
} |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
30
|
|
82b2c72 |
Jamozed |
2020-07-06 23:57:41 |
31
|
if (ac == 1) { error(1, "missing operand"); } |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
32
|
|
82b2c72 |
Jamozed |
2020-07-06 23:57:41 |
33
|
if (unlink(av[1])) { error(1, "%s", serr()); } |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
34
|
|
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
35
|
return 0; |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
36
|
} |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
37
|
|
1154147 |
Jamozed |
2021-01-02 10:50:31 |
38
|
/* Print help information */ |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
39
|
static void hlp(void) { |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
40
|
puts("unlink - remove a file using the unlink function\n"); |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
41
|
puts("usage: unlink file\n"); |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
42
|
puts("options:"); |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
43
|
puts(" --help Display help information"); |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
44
|
puts(" --version Display version information"); |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
45
|
} |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
46
|
|
1154147 |
Jamozed |
2021-01-02 10:50:31 |
47
|
/* Print version information */ |
30cf081 |
Jamozed |
2020-08-28 23:01:02 |
48
|
static void ver(void) { |
82b2c72 |
Jamozed |
2020-07-06 23:57:41 |
49
|
puts("OMKOV coreutils unlink, version " VERSION); |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
50
|
puts("Copyright (C) 2020, Jakob Wakeling"); |
e2140ec |
Jamozed |
2022-03-06 15:27:45 |
51
|
puts("MIT Licence (https://opensource.org/licenses/MIT)"); |
0534c26 |
Jamozed |
2020-06-26 18:12:01 |
52
|
} |
|
|
|
53
|
|