coreutils

General Software Utilities
git clone http://git.omkov.net/coreutils
Log | Tree | Refs | README | LICENCE | Download

coreutils/src/orphan.c (59 lines, 1.3 KiB) -rw-r--r-- file download

1086f2e Jamozed 2020-11-17 13:22:30
0
// orphan.c, version 1.0.1
068c8fb Jamozed 2020-08-05 23:54:14
1
// OMKOV coreutils orphan
068c8fb Jamozed 2020-08-05 23:54:14
2
// Copyright (C) 2020, Jakob Wakeling
e2140ec Jamozed 2022-03-06 15:27:45
3
// MIT Licence
068c8fb Jamozed 2020-08-05 23:54:14
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"
068c8fb Jamozed 2020-08-05 23:54:14
7
068c8fb Jamozed 2020-08-05 23:54:14
8
#include <fcntl.h>
068c8fb Jamozed 2020-08-05 23:54:14
9
#include <unistd.h>
068c8fb Jamozed 2020-08-05 23:54:14
10
068c8fb Jamozed 2020-08-05 23:54:14
11
#include <errno.h>
068c8fb Jamozed 2020-08-05 23:54:14
12
#include <stdio.h>
068c8fb Jamozed 2020-08-05 23:54:14
13
1086f2e Jamozed 2020-11-17 13:22:30
14
#define VERSION "1.0.1"
068c8fb Jamozed 2020-08-05 23:54:14
15
30cf081 Jamozed 2020-08-28 23:01:02
16
static struct lop lops[] = {
30cf081 Jamozed 2020-08-28 23:01:02
17
	{ "help",    ARG_NUL, 256 },
30cf081 Jamozed 2020-08-28 23:01:02
18
	{ "version", ARG_NUL, 257 },
30cf081 Jamozed 2020-08-28 23:01:02
19
	{ NULL, 0, 0 }
30cf081 Jamozed 2020-08-28 23:01:02
20
};
30cf081 Jamozed 2020-08-28 23:01:02
21
068c8fb Jamozed 2020-08-05 23:54:14
22
static void hlp(void);
068c8fb Jamozed 2020-08-05 23:54:14
23
static void ver(void);
068c8fb Jamozed 2020-08-05 23:54:14
24
068c8fb Jamozed 2020-08-05 23:54:14
25
int main(int ac, char *av[]) { A0 = av[0];
30cf081 Jamozed 2020-08-28 23:01:02
26
	struct opt opt = OPTGET_INIT; opt.str = ""; opt.lops = lops;
30cf081 Jamozed 2020-08-28 23:01:02
27
	for (int o; (o = optget(&opt, av, 0)) != -1;) switch (o) {
068c8fb Jamozed 2020-08-05 23:54:14
28
	case 256: { hlp(); return 0; }
068c8fb Jamozed 2020-08-05 23:54:14
29
	case 257: { ver(); return 0; }
068c8fb Jamozed 2020-08-05 23:54:14
30
	default: { return 1; }
068c8fb Jamozed 2020-08-05 23:54:14
31
	}
068c8fb Jamozed 2020-08-05 23:54:14
32
	
068c8fb Jamozed 2020-08-05 23:54:14
33
	if (opt.ind == ac) { error(1, "missing operand"); }
068c8fb Jamozed 2020-08-05 23:54:14
34
	
068c8fb Jamozed 2020-08-05 23:54:14
35
	switch (fork()) {
068c8fb Jamozed 2020-08-05 23:54:14
36
	case -1: { error(1, "%s", serr()); }
068c8fb Jamozed 2020-08-05 23:54:14
37
	case  0: {
068c8fb Jamozed 2020-08-05 23:54:14
38
		execvp(av[opt.ind], &av[opt.ind]);
068c8fb Jamozed 2020-08-05 23:54:14
39
		warn("%s: %s", av[opt.ind], serr());
068c8fb Jamozed 2020-08-05 23:54:14
40
	}
068c8fb Jamozed 2020-08-05 23:54:14
41
	default: { return 0; }
068c8fb Jamozed 2020-08-05 23:54:14
42
	}
068c8fb Jamozed 2020-08-05 23:54:14
43
}
068c8fb Jamozed 2020-08-05 23:54:14
44
068c8fb Jamozed 2020-08-05 23:54:14
45
static void hlp(void) {
1086f2e Jamozed 2020-11-17 13:22:30
46
	puts("orphan - invoke a command as an orphan\n");
068c8fb Jamozed 2020-08-05 23:54:14
47
	puts("usage: orphan command [argument...]\n");
068c8fb Jamozed 2020-08-05 23:54:14
48
	puts("options:");
068c8fb Jamozed 2020-08-05 23:54:14
49
	puts("  --help     Display help information");
068c8fb Jamozed 2020-08-05 23:54:14
50
	puts("  --version  Display version information");
068c8fb Jamozed 2020-08-05 23:54:14
51
}
068c8fb Jamozed 2020-08-05 23:54:14
52
068c8fb Jamozed 2020-08-05 23:54:14
53
static void ver(void) {
068c8fb Jamozed 2020-08-05 23:54:14
54
	puts("OMKOV cryptutils orphan, version " VERSION);
068c8fb Jamozed 2020-08-05 23:54:14
55
	puts("Copyright (C) 2020, Jakob Wakeling");
e2140ec Jamozed 2022-03-06 15:27:45
56
	puts("MIT Licence (https://opensource.org/licenses/MIT)");
068c8fb Jamozed 2020-08-05 23:54:14
57
}
58