Patch from Vladimir N. Oleynik to save 128 bytes by moving error

checking for some my_* functions to utility.c
This commit is contained in:
Eric Andersen 2001-02-27 18:22:03 +00:00
parent e677dfedd1
commit 4142d4dc66
6 changed files with 16 additions and 28 deletions

View File

@ -175,11 +175,11 @@ extern unsigned long parse_number(const char *numstr,
/* These parse entries in /etc/passwd and /etc/group. This is desirable
* for BusyBox since we want to avoid using the glibc NSS stuff, which
* increases target size and is often not needed embedded systems. */
extern long my_getpwnam(char *name);
extern long my_getgrnam(char *name);
extern long my_getpwnam(const char *name);
extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid);
extern long my_getpwnamegid(char *name);
extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode);

View File

@ -122,8 +122,6 @@ int chmod_chown_chgrp_main(int argc, char **argv)
gid = strtoul(groupName, &p, 10); /* maybe it's already numeric */
if (groupName == p)
gid = my_getgrnam(groupName);
if (gid == -1)
goto bad_group;
} else {
groupName = strchr(*argv, '.');
if (groupName == NULL)
@ -133,8 +131,6 @@ int chmod_chown_chgrp_main(int argc, char **argv)
gid = strtoul(groupName, &p, 10);
if (groupName == p)
gid = my_getgrnam(groupName);
if (gid == -1)
goto bad_group;
} else
gid = -1;
}
@ -145,9 +141,6 @@ int chmod_chown_chgrp_main(int argc, char **argv)
uid = strtoul(*argv, &p, 10); /* if numeric ... */
if (*argv == p)
uid = my_getpwnam(*argv);
if (uid == -1) {
error_msg_and_die( "unknown user name: %s", *argv);
}
}
}
@ -162,8 +155,6 @@ int chmod_chown_chgrp_main(int argc, char **argv)
}
return EXIT_SUCCESS;
bad_group:
error_msg_and_die( "unknown group name: %s", groupName);
}
/*

View File

@ -76,9 +76,6 @@ extern int id_main(int argc, char **argv)
pwnam=my_getpwnam(user);
grnam=my_getgrnam(group);
if (gid == -1 || pwnam==-1 || grnam==-1) {
error_msg_and_die("%s: No such user", user);
}
if (no_group) {
if(name_not_number && user)

3
id.c
View File

@ -76,9 +76,6 @@ extern int id_main(int argc, char **argv)
pwnam=my_getpwnam(user);
grnam=my_getgrnam(group);
if (gid == -1 || pwnam==-1 || grnam==-1) {
error_msg_and_die("%s: No such user", user);
}
if (no_group) {
if(name_not_number && user)

View File

@ -175,11 +175,11 @@ extern unsigned long parse_number(const char *numstr,
/* These parse entries in /etc/passwd and /etc/group. This is desirable
* for BusyBox since we want to avoid using the glibc NSS stuff, which
* increases target size and is often not needed embedded systems. */
extern long my_getpwnam(char *name);
extern long my_getgrnam(char *name);
extern long my_getpwnam(const char *name);
extern long my_getgrnam(const char *name);
extern void my_getpwuid(char *name, long uid);
extern void my_getgrgid(char *group, long gid);
extern long my_getpwnamegid(char *name);
extern long my_getpwnamegid(const char *name);
extern int device_open(char *device, int mode);

View File

@ -877,29 +877,32 @@ extern int parse_mode(const char *s, mode_t * theMode)
#if defined BB_CHMOD_CHOWN_CHGRP || defined BB_PS || defined BB_LS \
|| defined BB_TAR || defined BB_ID || defined BB_LOGGER \
|| defined BB_LOGNAME || defined BB_WHOAMI || defined BB_SH
#if defined BB_CHMOD_CHOWN_CHGRP || defined BB_ID
/* returns a uid given a username */
long my_getpwnam(char *name)
long my_getpwnam(const char *name)
{
struct passwd *myuser;
myuser = getpwnam(name);
if (myuser==NULL)
return(-1);
error_msg_and_die("unknown user name: %s", name);
return myuser->pw_uid;
}
/* returns a gid given a group name */
long my_getgrnam(char *name)
long my_getgrnam(const char *name)
{
struct group *mygroup;
mygroup = getgrnam(name);
if (mygroup==NULL)
return(-1);
error_msg_and_die("unknown group name: %s", name);
return (mygroup->gr_gid);
}
#endif
/* gets a username given a uid */
void my_getpwuid(char *name, long uid)
@ -927,18 +930,18 @@ void my_getgrgid(char *group, long gid)
#if defined BB_ID
/* gets a gid given a user name */
long my_getpwnamegid(char *name)
long my_getpwnamegid(const char *name)
{
struct group *mygroup;
struct passwd *myuser;
myuser=getpwnam(name);
if (myuser==NULL)
error_msg_and_die( "unknown user name: %s", name);
error_msg_and_die("unknown user name: %s", name);
mygroup = getgrgid(myuser->pw_gid);
if (mygroup==NULL)
error_msg_and_die( "unknown gid %ld", (long)myuser->pw_gid);
error_msg_and_die("unknown gid %ld", (long)myuser->pw_gid);
return mygroup->gr_gid;
}