Use global applet_name instead of local versions.

This commit is contained in:
Matt Kraai 2000-07-12 00:53:06 +00:00
parent 3ecbe9f4dc
commit e714bce003
6 changed files with 32 additions and 50 deletions

View File

@ -36,7 +36,6 @@
static unsigned long uid = -1; static unsigned long uid = -1;
static unsigned long gid = -1; static unsigned long gid = -1;
static int whichApp; static int whichApp;
static char *invocationName = NULL;
static char *theMode = NULL; static char *theMode = NULL;
@ -88,7 +87,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
case CHMOD_APP: case CHMOD_APP:
/* Parse the specified modes */ /* Parse the specified modes */
if (parse_mode(theMode, &(statbuf->st_mode)) == FALSE) { if (parse_mode(theMode, &(statbuf->st_mode)) == FALSE) {
fatalError( "%s: unknown mode: %s\n", invocationName, theMode); fatalError( "%s: unknown mode: %s\n", applet_name, theMode);
} }
if (chmod(fileName, statbuf->st_mode) == 0) if (chmod(fileName, statbuf->st_mode) == 0)
return (TRUE); return (TRUE);
@ -105,8 +104,8 @@ int chmod_chown_chgrp_main(int argc, char **argv)
char *p=NULL; char *p=NULL;
const char *appUsage; const char *appUsage;
whichApp = (strcmp(*argv, "chown") == 0)? whichApp = (strcmp(applet_name, "chown") == 0)?
CHOWN_APP : (strcmp(*argv, "chmod") == 0)? CHOWN_APP : (strcmp(applet_name, "chmod") == 0)?
CHMOD_APP : CHGRP_APP; CHMOD_APP : CHGRP_APP;
appUsage = (whichApp == CHOWN_APP)? appUsage = (whichApp == CHOWN_APP)?
@ -114,7 +113,6 @@ int chmod_chown_chgrp_main(int argc, char **argv)
if (argc < 2) if (argc < 2)
usage(appUsage); usage(appUsage);
invocationName = *argv;
argv++; argv++;
/* Parse options */ /* Parse options */
@ -125,7 +123,7 @@ int chmod_chown_chgrp_main(int argc, char **argv)
recursiveFlag = TRUE; recursiveFlag = TRUE;
break; break;
default: default:
fprintf(stderr, invalid_option, invocationName, **argv); fprintf(stderr, invalid_option, applet_name, **argv);
usage(appUsage); usage(appUsage);
} }
} }
@ -133,7 +131,7 @@ int chmod_chown_chgrp_main(int argc, char **argv)
} }
if (argc == 0 || *argv == NULL) { if (argc == 0 || *argv == NULL) {
fprintf(stderr, too_few_args, invocationName); fprintf(stderr, too_few_args, applet_name);
usage(appUsage); usage(appUsage);
} }
@ -172,14 +170,14 @@ int chmod_chown_chgrp_main(int argc, char **argv)
uid = my_getpwnam(*argv); uid = my_getpwnam(*argv);
if (uid == -1) { if (uid == -1) {
fatalError( "%s: unknown user name: %s\n", fatalError( "%s: unknown user name: %s\n",
invocationName, *argv); applet_name, *argv);
} }
} }
} }
/* Ok, ready to do the deed now */ /* Ok, ready to do the deed now */
if (argc <= 1) { if (argc <= 1) {
fatalError( "%s: too few arguments\n", invocationName); fatalError( "%s: too few arguments\n", applet_name);
} }
while (argc-- > 1) { while (argc-- > 1) {
if (recursiveAction (*(++argv), recursiveFlag, FALSE, FALSE, if (recursiveAction (*(++argv), recursiveFlag, FALSE, FALSE,
@ -189,7 +187,7 @@ int chmod_chown_chgrp_main(int argc, char **argv)
exit(TRUE); exit(TRUE);
bad_group: bad_group:
fatalError( "%s: unknown group name: %s\n", invocationName, groupName); fatalError( "%s: unknown group name: %s\n", applet_name, groupName);
} }
/* /*

View File

@ -14,8 +14,6 @@
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */ #define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
char *progname;
int deallocvt_main(int argc, char *argv[]) int deallocvt_main(int argc, char *argv[])
{ {
int fd, num, i; int fd, num, i;
@ -29,8 +27,6 @@ int deallocvt_main(int argc, char *argv[])
); );
} }
progname = argv[0];
fd = get_console_fd("/dev/console"); fd = get_console_fd("/dev/console");
if (argc == 1) { if (argc == 1) {
@ -43,14 +39,14 @@ int deallocvt_main(int argc, char *argv[])
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
num = atoi(argv[i]); num = atoi(argv[i]);
if (num == 0) if (num == 0)
fprintf(stderr, "%s: 0: illegal VT number\n", progname); fprintf(stderr, "%s: 0: illegal VT number\n", applet_name);
else if (num == 1) else if (num == 1)
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
progname); applet_name);
else if (ioctl(fd, VT_DISALLOCATE, num)) { else if (ioctl(fd, VT_DISALLOCATE, num)) {
perror("VT_DISALLOCATE"); perror("VT_DISALLOCATE");
fprintf(stderr, "%s: could not deallocate console %d\n", fprintf(stderr, "%s: could not deallocate console %d\n",
progname, num); applet_name, num);
exit( FALSE); exit( FALSE);
} }
} }

View File

@ -71,7 +71,6 @@ int num_args;
int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */ int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */
char delim = '\t'; /* default delimiting character */ char delim = '\t'; /* default delimiting character */
FILE *fd; FILE *fd;
char *name;
char line[BUFSIZ]; char line[BUFSIZ];
int exit_status; int exit_status;
int option = 0; /* for -s option */ int option = 0; /* for -s option */
@ -91,7 +90,7 @@ void warn(int warn_number, char *option)
"%s: Cannot open %s\n" "%s: Cannot open %s\n"
}; };
fprintf(stderr, warn_msg[warn_number], name, option); fprintf(stderr, warn_msg[warn_number], applet_name, option);
exit_status = warn_number + 1; exit_status = warn_number + 1;
} }
@ -107,7 +106,7 @@ void cuterror(int err)
"%s: MAX_ARGS exceeded\n" "%s: MAX_ARGS exceeded\n"
}; };
fprintf(stderr, err_mes[err - 101], name); fprintf(stderr, err_mes[err - 101], applet_name);
exit(err); exit(err);
} }
@ -213,8 +212,6 @@ int cut_main(int argc, char **argv)
int i = 1; int i = 1;
int numberFilenames = 0; int numberFilenames = 0;
name = argv[0];
if (argc == 1 || strcmp(argv[1], dash_dash_help)==0) if (argc == 1 || strcmp(argv[1], dash_dash_help)==0)
usage( "cut [OPTION]... [FILE]...\n" usage( "cut [OPTION]... [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP #ifndef BB_FEATURE_TRIVIAL_HELP

30
cp_mv.c
View File

@ -45,7 +45,6 @@
#define is_cp 0 #define is_cp 0
#define is_mv 1 #define is_mv 1
static int dz_i; /* index into cp_mv_usage */ static int dz_i; /* index into cp_mv_usage */
static const char *dz; /* dollar zero, .bss */
static const char *cp_mv_usage[] = /* .rodata */ static const char *cp_mv_usage[] = /* .rodata */
{ {
"cp [OPTION]... SOURCE DEST\n" "cp [OPTION]... SOURCE DEST\n"
@ -89,7 +88,7 @@ static void name_too_long__exit (void) __attribute__((noreturn));
static static
void name_too_long__exit (void) void name_too_long__exit (void)
{ {
fprintf(stderr, name_too_long, dz); fprintf(stderr, name_too_long, applet_name);
exit(FALSE); exit(FALSE);
} }
@ -124,14 +123,14 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
if (srcDirFlag == TRUE) { if (srcDirFlag == TRUE) {
if (recursiveFlag == FALSE) { if (recursiveFlag == FALSE) {
fprintf(stderr, omitting_directory, dz, baseSrcName); fprintf(stderr, omitting_directory, applet_name, baseSrcName);
return TRUE; return TRUE;
} }
srcBasename = (strstr(fileName, baseSrcName) srcBasename = (strstr(fileName, baseSrcName)
+ strlen(baseSrcName)); + strlen(baseSrcName));
if (destLen + strlen(srcBasename) > BUFSIZ) { if (destLen + strlen(srcBasename) > BUFSIZ) {
fprintf(stderr, name_too_long, dz); fprintf(stderr, name_too_long, applet_name);
return FALSE; return FALSE;
} }
strcat(destName, srcBasename); strcat(destName, srcBasename);
@ -146,7 +145,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
mv_Action_first_time = errno = 0; mv_Action_first_time = errno = 0;
if (rename(fileName, destName) < 0 && errno != EXDEV) { if (rename(fileName, destName) < 0 && errno != EXDEV) {
fprintf(stderr, "%s: rename(%s, %s): %s\n", fprintf(stderr, "%s: rename(%s, %s): %s\n",
dz, fileName, destName, strerror(errno)); applet_name, fileName, destName, strerror(errno));
goto do_copyFile; /* Try anyway... */ goto do_copyFile; /* Try anyway... */
} }
else if (errno == EXDEV) else if (errno == EXDEV)
@ -159,7 +158,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
if (is_in_ino_dev_hashtable(statbuf, &name)) { if (is_in_ino_dev_hashtable(statbuf, &name)) {
if (link(name, destName) < 0) { if (link(name, destName) < 0) {
fprintf(stderr, "%s: link(%s, %s): %s\n", fprintf(stderr, "%s: link(%s, %s): %s\n",
dz, name, destName, strerror(errno)); applet_name, name, destName, strerror(errno));
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
@ -178,11 +177,11 @@ rm_Action(const char *fileName, struct stat *statbuf, void* junk)
if (S_ISDIR(statbuf->st_mode)) { if (S_ISDIR(statbuf->st_mode)) {
if (rmdir(fileName) < 0) { if (rmdir(fileName) < 0) {
fprintf(stderr, "%s: rmdir(%s): %s\n", dz, fileName, strerror(errno)); fprintf(stderr, "%s: rmdir(%s): %s\n", applet_name, fileName, strerror(errno));
status = FALSE; status = FALSE;
} }
} else if (unlink(fileName) < 0) { } else if (unlink(fileName) < 0) {
fprintf(stderr, "%s: unlink(%s): %s\n", dz, fileName, strerror(errno)); fprintf(stderr, "%s: unlink(%s): %s\n", applet_name, fileName, strerror(errno));
status = FALSE; status = FALSE;
} }
return status; return status;
@ -190,8 +189,7 @@ rm_Action(const char *fileName, struct stat *statbuf, void* junk)
extern int cp_mv_main(int argc, char **argv) extern int cp_mv_main(int argc, char **argv)
{ {
dz = *argv; /* already basename'd by busybox.c:main */ if (*applet_name == 'c' && *(applet_name + 1) == 'p')
if (*dz == 'c' && *(dz + 1) == 'p')
dz_i = is_cp; dz_i = is_cp;
else else
dz_i = is_mv; dz_i = is_mv;
@ -276,20 +274,20 @@ extern int cp_mv_main(int argc, char **argv)
char *pushd, *d, *p; char *pushd, *d, *p;
if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) { if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno)); fprintf(stderr, "%s: getcwd(): %s\n", applet_name, strerror(errno));
continue; continue;
} }
if (chdir(baseDestName) < 0) { if (chdir(baseDestName) < 0) {
fprintf(stderr, "%s: chdir(%s): %s\n", dz, baseSrcName, strerror(errno)); fprintf(stderr, "%s: chdir(%s): %s\n", applet_name, baseSrcName, strerror(errno));
continue; continue;
} }
if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) { if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno)); fprintf(stderr, "%s: getcwd(): %s\n", applet_name, strerror(errno));
continue; continue;
} }
while (!state && *d != '\0') { while (!state && *d != '\0') {
if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */ if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
fprintf(stderr, "%s: stat(%s) :%s\n", dz, d, strerror(errno)); fprintf(stderr, "%s: stat(%s) :%s\n", applet_name, d, strerror(errno));
state = -1; state = -1;
continue; continue;
} }
@ -298,7 +296,7 @@ extern int cp_mv_main(int argc, char **argv)
fprintf(stderr, fprintf(stderr,
"%s: Cannot %s `%s' " "%s: Cannot %s `%s' "
"into a subdirectory of itself, `%s/%s'\n", "into a subdirectory of itself, `%s/%s'\n",
dz, dz, baseSrcName, baseDestName, baseSrcName); applet_name, applet_name, baseSrcName, baseDestName, baseSrcName);
state = -1; state = -1;
continue; continue;
} }
@ -307,7 +305,7 @@ extern int cp_mv_main(int argc, char **argv)
} }
} }
if (chdir(pushd) < 0) { if (chdir(pushd) < 0) {
fprintf(stderr, "%s: chdir(%s): %s\n", dz, pushd, strerror(errno)); fprintf(stderr, "%s: chdir(%s): %s\n", applet_name, pushd, strerror(errno));
free(pushd); free(pushd);
free(d); free(d);
continue; continue;

7
cut.c
View File

@ -71,7 +71,6 @@ int num_args;
int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */ int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */
char delim = '\t'; /* default delimiting character */ char delim = '\t'; /* default delimiting character */
FILE *fd; FILE *fd;
char *name;
char line[BUFSIZ]; char line[BUFSIZ];
int exit_status; int exit_status;
int option = 0; /* for -s option */ int option = 0; /* for -s option */
@ -91,7 +90,7 @@ void warn(int warn_number, char *option)
"%s: Cannot open %s\n" "%s: Cannot open %s\n"
}; };
fprintf(stderr, warn_msg[warn_number], name, option); fprintf(stderr, warn_msg[warn_number], applet_name, option);
exit_status = warn_number + 1; exit_status = warn_number + 1;
} }
@ -107,7 +106,7 @@ void cuterror(int err)
"%s: MAX_ARGS exceeded\n" "%s: MAX_ARGS exceeded\n"
}; };
fprintf(stderr, err_mes[err - 101], name); fprintf(stderr, err_mes[err - 101], applet_name);
exit(err); exit(err);
} }
@ -213,8 +212,6 @@ int cut_main(int argc, char **argv)
int i = 1; int i = 1;
int numberFilenames = 0; int numberFilenames = 0;
name = argv[0];
if (argc == 1 || strcmp(argv[1], dash_dash_help)==0) if (argc == 1 || strcmp(argv[1], dash_dash_help)==0)
usage( "cut [OPTION]... [FILE]...\n" usage( "cut [OPTION]... [FILE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP #ifndef BB_FEATURE_TRIVIAL_HELP

View File

@ -14,8 +14,6 @@
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */ #define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
char *progname;
int deallocvt_main(int argc, char *argv[]) int deallocvt_main(int argc, char *argv[])
{ {
int fd, num, i; int fd, num, i;
@ -29,8 +27,6 @@ int deallocvt_main(int argc, char *argv[])
); );
} }
progname = argv[0];
fd = get_console_fd("/dev/console"); fd = get_console_fd("/dev/console");
if (argc == 1) { if (argc == 1) {
@ -43,14 +39,14 @@ int deallocvt_main(int argc, char *argv[])
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
num = atoi(argv[i]); num = atoi(argv[i]);
if (num == 0) if (num == 0)
fprintf(stderr, "%s: 0: illegal VT number\n", progname); fprintf(stderr, "%s: 0: illegal VT number\n", applet_name);
else if (num == 1) else if (num == 1)
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
progname); applet_name);
else if (ioctl(fd, VT_DISALLOCATE, num)) { else if (ioctl(fd, VT_DISALLOCATE, num)) {
perror("VT_DISALLOCATE"); perror("VT_DISALLOCATE");
fprintf(stderr, "%s: could not deallocate console %d\n", fprintf(stderr, "%s: could not deallocate console %d\n",
progname, num); applet_name, num);
exit( FALSE); exit( FALSE);
} }
} }