forked from michaelforney/sbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cp.c
60 lines (52 loc) · 950 Bytes
/
cp.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* See LICENSE file for copyright and license details. */
#include <sys/stat.h>
#include "fs.h"
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s [-afpv] [-R [-H | -L | -P]] source ... dest\n", argv0);
}
int
main(int argc, char *argv[])
{
struct stat st;
ARGBEGIN {
case 'a':
cp_follow = 'P';
cp_aflag = cp_pflag = cp_rflag = 1;
break;
case 'f':
cp_fflag = 1;
break;
case 'p':
cp_pflag = 1;
break;
case 'r':
case 'R':
cp_rflag = 1;
break;
case 'v':
cp_vflag = 1;
break;
case 'H':
case 'L':
case 'P':
cp_follow = ARGC();
break;
default:
usage();
} ARGEND
if (argc < 2)
usage();
if (!cp_follow)
cp_follow = cp_rflag ? 'P' : 'L';
if (argc > 2) {
if (stat(argv[argc - 1], &st) < 0)
eprintf("stat %s:", argv[argc - 1]);
if (!S_ISDIR(st.st_mode))
eprintf("%s: not a directory\n", argv[argc - 1]);
}
enmasse(argc, argv, cp);
return fshut(stdout, "<stdout>") || cp_status;
}