sbase/cp.c

58 lines
868 B
C
Raw Normal View History

2012-01-30 22:41:33 +00:00
/* See LICENSE file for copyright and license details. */
#include <sys/stat.h>
2012-01-30 22:41:33 +00:00
#include "fs.h"
#include "util.h"
static void
usage(void)
{
eprintf("usage: %s [-afpv] [-R [-H | -L | -P]] source ... dest\n", argv0);
}
2012-01-30 22:41:33 +00:00
int
main(int argc, char *argv[])
{
struct stat st;
2013-03-11 00:59:22 +00:00
ARGBEGIN {
2014-07-09 21:28:43 +00:00
case 'a':
cp_follow = 'P';
cp_aflag = cp_pflag = cp_rflag = 1;
2014-07-09 21:28:43 +00:00
break;
case 'f':
cp_fflag = 1;
break;
2014-07-09 21:28:43 +00:00
case 'p':
cp_pflag = 1;
2014-07-09 21:28:43 +00:00
break;
2013-03-11 00:59:22 +00:00
case 'r':
case 'R':
cp_rflag = 1;
2013-03-11 00:59:22 +00:00
break;
case 'v':
cp_vflag = 1;
break;
case 'H':
case 'L':
case 'P':
cp_follow = ARGC();
break;
2013-03-11 00:59:22 +00:00
default:
usage();
2013-03-11 00:59:22 +00:00
} ARGEND;
if (argc < 2)
usage();
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 cp_status;
2012-01-30 22:41:33 +00:00
}