From 347f371adefcfc44b3871a7369f3467dd85ac6c9 Mon Sep 17 00:00:00 2001 From: 8nlight <8nlight@disroot.org> Date: Thu, 12 Oct 2023 20:04:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20=C2=AB?= =?UTF-8?q?src=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mv.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mv.c b/src/mv.c index d67a712..742997a 100644 --- a/src/mv.c +++ b/src/mv.c @@ -31,17 +31,26 @@ int move(const char *src, const char *dst) { } int main(const int argc, const char **argv) { - if (argc <= 2) { + if (argc == 2) { printf("mv: missing operand\n"); return 1; } - for (int i = 1; i < argc - 1; i++) { - if (move(argv[i], argv[argc - 1])) { - fprintf(stderr, "mv: %s %s\n", argv[i], strerror(errno)); + else if (argc == 3) { + if (rename(argv[1], argv[2]) < 0) { + fprintf(stderr, "mv: %s %s\n", argv[1], strerror(errno)); return 1; } } + else { + for (int i = 1; i < argc - 1; i++) { + if (move(argv[i], argv[argc - 1])) { + fprintf(stderr, "mv: %s %s\n", argv[i], strerror(errno)); + return 1; + } + } + } + return 0; }