sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

cp.c (896B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <sys/stat.h>
      3 
      4 #include "fs.h"
      5 #include "util.h"
      6 
      7 static void
      8 usage(void)
      9 {
     10 	eprintf("usage: %s [-afpv] [-R [-H | -L | -P]] source ... dest\n", argv0);
     11 }
     12 
     13 int
     14 main(int argc, char *argv[])
     15 {
     16 	struct stat st;
     17 
     18 	ARGBEGIN {
     19 	case 'a':
     20 		cp_follow = 'P';
     21 		cp_aflag = cp_pflag = cp_rflag = 1;
     22 		break;
     23 	case 'f':
     24 		cp_fflag = 1;
     25 		break;
     26 	case 'p':
     27 		cp_pflag = 1;
     28 		break;
     29 	case 'r':
     30 	case 'R':
     31 		cp_rflag = 1;
     32 		break;
     33 	case 'v':
     34 		cp_vflag = 1;
     35 		break;
     36 	case 'H':
     37 	case 'L':
     38 	case 'P':
     39 		cp_follow = ARGC();
     40 		break;
     41 	default:
     42 		usage();
     43 	} ARGEND
     44 
     45 	if (argc < 2)
     46 		usage();
     47 
     48 	if (argc > 2) {
     49 		if (stat(argv[argc - 1], &st) < 0)
     50 			eprintf("stat %s:", argv[argc - 1]);
     51 		if (!S_ISDIR(st.st_mode))
     52 			eprintf("%s: not a directory\n", argv[argc - 1]);
     53 	}
     54 	enmasse(argc, argv, cp);
     55 
     56 	return fshut(stdout, "<stdout>") || cp_status;
     57 }