[hackers] [sbase] Audit cp(1) || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 3 Mar 2015 14:32:26 +0100 (CET)

commit 327f8533b660c8a579765e8f59f86b3a0039fe64
Author: FRIGN <dev_AT_frign.de>
Date: Mon Mar 2 19:15:19 2015 +0100

    Audit cp(1)
    1) Refactor the manpage, which has been a bloody mess, documenting
       fantasy-flags (-d for example) and add a STANDARDS section
    2) fix usage()
    3) sort ARG-block
    4) Check return-value of stat() separately, so a lack of permissions
       doesn't tell the user "the directory doesn't exist", which could
       be a bit confusing.
    5) Add empty line before return.

diff --git a/README b/README
index 0375e1b..7b36203 100644
--- a/README
+++ b/README
_AT_@ -20,7 +20,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
 =* cmp yes none
 #* cols non-posix none
 =* comm yes none
-= cp yes none (-i)
+=*| cp yes none (-i)
 =* cron non-posix none
 #* cut yes none
 =*| date yes none
diff --git a/cp.1 b/cp.1
index 275ff5f..06fe795 100644
--- a/cp.1
+++ b/cp.1
_AT_@ -1,4 +1,4 @@
-.Dd February 17, 2015
+.Dd March 2, 2015
 .Dt CP 1
 .Os sbase
_AT_@ -11,45 +11,61 @@
 .Fl R
 .Op Fl H | L | P
-.Op Ar file ...
-.Op Ar directory
+.Op Ar source ...
+.Op Ar dest
-copies a given
-.Ar file ,
-naming it the given
-.Ar name .
-If multiple
-.Ar files
-are listed
-they will be copied into the given
-.Ar directory .
+.Ar source
+.Ar dest .
+If more than one
+.Ar source
+is given
+.Ar dest
+has to be a directory.
 .Bl -tag -width Ds
 .It Fl a
-Preserve mode, timestamp, links and permissions. Implies
-.Fl d ,
-.Fl p
+Preserve block devices, character devices, sockets and FIFOs. Implies
+.Fl p ,
+.Fl P
-.Fl r .
+.Fl R .
 .It Fl f
-If an existing destination file cannot be opened, remove it and try again.
+If an existing
+.Ar dest
+cannot be opened, remove it and try again.
 .It Fl p
 Preserve mode, timestamp and permissions.
 .It Fl v
-Print names of source and destination per file to stdout. In the format:
-"source \-> destination".
-.It Fl R
-Copies directories recursively. If this flag is not specified, directories
-are not copied.
+Write "'source' -> 'dest'" for each
+.Ar source
+to stdout.
 .It Fl H
-Only dereference symbolic links that are passed as command line arguments when
-recursively traversing directories.
+.Ar source
+if it is a symbolic link.
 .It Fl L
-Always dereference symbolic links while recursively traversing directories
+Dereference all symbolic links.
+This is the default.
 .It Fl P
-Don't dereference symbolic links.
+Preserve symbolic links.
+.It Fl R
+Traverse directories recursively. If this flag is not specified, directories
+are not copied.
 .Xr mv 1
+utility is compliant with the
+.St -p1003.1-2008
+specification except from the
+.Op Fl i
+The flags
+.Op Fl av
+are an extension to that specification.
diff --git a/cp.c b/cp.c
index b3d7028..cc976d1 100644
--- a/cp.c
+++ b/cp.c
_AT_@ -7,7 +7,7 @@
 static void
- eprintf("usage: %s [-afpv] [-R [-H | -L | -P]] source... dest\n", argv0);
+ eprintf("usage: %s [-afpv] [-R [-H | -L | -P]] source ... dest\n", argv0);
_AT_@ -26,13 +26,13 @@ main(int argc, char *argv[])
         case 'p':
                 cp_pflag = 1;
- case 'v':
- cp_vflag = 1;
- break;
         case 'r':
         case 'R':
                 cp_rflag = 1;
+ case 'v':
+ cp_vflag = 1;
+ break;
         case 'H':
         case 'L':
         case 'P':
_AT_@ -45,8 +45,13 @@ main(int argc, char *argv[])
         if (argc < 2)
- if (argc > 2 && !(stat(argv[argc-1], &st) == 0 && S_ISDIR(st.st_mode)))
- eprintf("%s: not a directory\n", argv[argc-1]);
+ 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, cp_HLPflag);
         return cp_status;
Received on Tue Mar 03 2015 - 14:32:26 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 03 2015 - 14:36:32 CET