Use PROGNAME for cp(1)
This commit is contained in:
parent
ea88d968e6
commit
c6db72305a
26
src/cp.c
26
src/cp.c
|
@ -28,6 +28,11 @@
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
/* constants */
|
||||||
|
#ifndef PROGNAME
|
||||||
|
# define PROGNAME "cp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* types */
|
/* types */
|
||||||
typedef int Prefs;
|
typedef int Prefs;
|
||||||
|
@ -55,7 +60,8 @@ static int _cp(Prefs * prefs, int filec, char * filev[])
|
||||||
return _cp_error(filev[filec - 1], 1);
|
return _cp_error(filev[filec - 1], 1);
|
||||||
if(filec > 2)
|
if(filec > 2)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s%s%s", "cp: ", filev[filec - 1],
|
fprintf(stderr, "%s%s%s", PROGNAME ": ",
|
||||||
|
filev[filec - 1],
|
||||||
": Does not exist and more than two"
|
": Does not exist and more than two"
|
||||||
" operands were given\n");
|
" operands were given\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -73,7 +79,7 @@ static int _cp(Prefs * prefs, int filec, char * filev[])
|
||||||
|
|
||||||
static int _cp_error(char const * message, int ret)
|
static int _cp_error(char const * message, int ret)
|
||||||
{
|
{
|
||||||
fputs("cp: ", stderr);
|
fputs(PROGNAME ": ", stderr);
|
||||||
perror(message);
|
perror(message);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +89,7 @@ static int _cp_confirm(char const * message)
|
||||||
int c;
|
int c;
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
fprintf(stderr, "%s%s%s", "cp: ", message, ": Overwrite? ");
|
fprintf(stderr, "%s%s%s", PROGNAME ": ", message, ": Overwrite? ");
|
||||||
if((c = fgetc(stdin)) == EOF)
|
if((c = fgetc(stdin)) == EOF)
|
||||||
return 0;
|
return 0;
|
||||||
while(c != '\n' && (tmp = fgetc(stdin)) != EOF && tmp != '\n');
|
while(c != '\n' && (tmp = fgetc(stdin)) != EOF && tmp != '\n');
|
||||||
|
@ -116,8 +122,8 @@ static int _cp_single(Prefs * prefs, char const * src, char const * dst)
|
||||||
{
|
{
|
||||||
if(st.st_dev == st2.st_dev && st.st_ino == st2.st_ino)
|
if(st.st_dev == st2.st_dev && st.st_ino == st2.st_ino)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: %s: \"%s\"%s\n", "cp", dst, src,
|
fprintf(stderr, "%s: %s: \"%s\"%s\n", PROGNAME, dst,
|
||||||
" is identical (not copied)");
|
src, " is identical (not copied)");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(*prefs & CP_PREFS_i && _cp_confirm(dst) != 1)
|
if(*prefs & CP_PREFS_i && _cp_confirm(dst) != 1)
|
||||||
|
@ -149,7 +155,7 @@ static int _cp_single_dir(Prefs * prefs, char const * src, char const * dst,
|
||||||
{
|
{
|
||||||
if(*prefs & CP_PREFS_R)
|
if(*prefs & CP_PREFS_R)
|
||||||
return _cp_single_recurse(prefs, src, dst, mode);
|
return _cp_single_recurse(prefs, src, dst, mode);
|
||||||
fprintf(stderr, "%s%s%s", "cp: ", src, ": Omitting directory\n");
|
fprintf(stderr, "%s%s%s", PROGNAME ": ", src, ": Omitting directory\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,10 +310,10 @@ static int _cp_multiple(Prefs * prefs, int filec, char * const filev[])
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fputs("Usage: cp [-fip] source_file target_file\n\
|
fputs("Usage: " PROGNAME " [-fip] source_file target_file\n\
|
||||||
cp [-fip] source_file ... target\n\
|
" PROGNAME " [-fip] source_file ... target\n\
|
||||||
cp -R [-H | -L | -P][-fip] source_file ... target\n\
|
" PROGNAME " -R [-H | -L | -P][-fip] source_file ... target\n\
|
||||||
cp -r [-H | -L | -P][-fip] source_file ... target\n\
|
" PROGNAME " -r [-H | -L | -P][-fip] source_file ... target\n\
|
||||||
-f Attempt to remove destination file before a copy if necessary\n\
|
-f Attempt to remove destination file before a copy if necessary\n\
|
||||||
-i Prompt before a copy to an existing file\n\
|
-i Prompt before a copy to an existing file\n\
|
||||||
-p Duplicate characteristics of the source files\n\
|
-p Duplicate characteristics of the source files\n\
|
||||||
|
|
Loading…
Reference in New Issue
Block a user