coreutils

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

AuthorJamozed <[email protected]>
Date2021-04-29 05:38:15
Commit14d235f076b516804099624cc9d5cb453ffe3dd1
Parentd920c1b2ac2bcd8572bb8c12fdfbbc47997d452f

cp: Add skeleton for handling multiple operands

Diffstat

M src/cp.c | 16 ++++++++++++----

1 files changed, 12 insertions, 4 deletions

diff --git a/src/cp.c b/src/cp.c
index 15d877b..7f97dd6 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -1,4 +1,4 @@
-// cp.c, version 0.0.1
+// cp.c, version 0.0.2
 // OMKOV coreutils implementation of POSIX cksum
 // Copyright (C) 2021, Jakob Wakeling
 // All rights reserved.
@@ -39,7 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
 #include <stdint.h>
 #include <stdio.h>
 
-#define VERSION "0.0.1"
+#define VERSION "0.0.2"
 
 static struct lop lops[] = {
 	{ "help",    ARG_NUL, 256 },
@@ -49,7 +49,8 @@ static struct lop lops[] = {
 
 static bool fflag, Hflag, iflag, Lflag, Pflag, pflag, Rflag;
 
-static inline void cp(const char *src, const char *dst);
+static inline void cp(const char *dst, char *const *src, size_t n);
+static inline void fcopy(const char *dst, const char *src);
 static inline bool fsame(FILE *f1, FILE *f2);
 
 static void hlp(void);
@@ -72,13 +73,18 @@ int main(int ac, char *av[]) { A0 = av[0];
 
 	if (opt.ind == ac) { error(1, "missing source operand"); }
 	else if (opt.ind == ac - 1) { error(1, "missing destination operand"); }
-	else { cp(av[opt.ind], av[opt.ind + 1]); }
+	else { cp(av[ac - 1], &av[opt.ind], ac - opt.ind - 1); }
 
 	return warned;
 }
 
+/* Copy one or more files to a specified destination */
+static inline void cp(const char *dst, char *const *src, size_t n) {
+	return fcopy(dst, *src);
+}
+
 /* Copy a file to a specified destination */
-static inline void cp(const char *src, const char *dst) {
+static inline void fcopy(const char *dst, const char *src) {
 	uint8_t b[BUFSIZ * 16]; FILE *fi = NULL, *fo = NULL; struct stat st;
 
 	if (!(fi = fopen(src, "rb"))) { warn("%s: %s", src, serr()); goto end; }