git: c6cb1b2ee506 - stable/13 - cp: Improve error messages.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 21 Apr 2025 17:41:14 UTC
The branch stable/13 has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=c6cb1b2ee5065ea2eaf725c09b45fd7a249bb4dc
commit c6cb1b2ee5065ea2eaf725c09b45fd7a249bb4dc
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-04-15 17:57:28 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-04-20 08:00:24 +0000
cp: Improve error messages.
MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: allanjude, markj
Differential Revision: https://reviews.freebsd.org/D49841
(cherry picked from commit 7622e2d21a22f7af65a7145f91ef34179bb6ee03)
---
bin/cp/cp.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index a8c57308ae96..79a808059536 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -227,7 +227,7 @@ main(int argc, char *argv[])
* Case (1). Target is not a directory.
*/
if (argc > 1)
- errx(1, "%s is not a directory", to.p_path);
+ errc(1, ENOTDIR, "%s", to.p_path);
/*
* Need to detect the case:
@@ -250,17 +250,17 @@ main(int argc, char *argv[])
type = FILE_TO_FILE;
if (have_trailing_slash && type == FILE_TO_FILE) {
- if (r == -1) {
- errx(1, "directory %s does not exist",
- to.p_path);
- } else
- errx(1, "%s is not a directory", to.p_path);
+ if (r == -1)
+ errc(1, ENOENT, "%s", to.p_path);
+ else
+ errc(1, ENOTDIR, "%s", to.p_path);
}
- } else
+ } else {
/*
* Case (2). Target is a directory.
*/
type = FILE_TO_DIR;
+ }
/*
* For DIR_TO_DNE, we could provide copy() with the to_stat we've
@@ -368,8 +368,8 @@ copy(char *argv[], enum op type, int fts_options, struct stat *root_stat)
base = (p == NULL) ? 0 :
(int)(p - curr->fts_path + 1);
- if (!strcmp(&curr->fts_path[base],
- ".."))
+ if (strcmp(curr->fts_path + base, "..")
+ == 0)
base += 1;
} else
base = curr->fts_pathlen;