summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen2001-02-27 18:22:03 +0000
committerEric Andersen2001-02-27 18:22:03 +0000
commit4142d4dc661c85b731c21b3296a04d1c5b5c3367 (patch)
tree11f7cf83505eb63db8e5dfaa47c5d5b8b81e6176
parente677dfedd1183da404e781a48607ad7a8a7e6d87 (diff)
downloadbusybox-4142d4dc661c85b731c21b3296a04d1c5b5c3367.zip
busybox-4142d4dc661c85b731c21b3296a04d1c5b5c3367.tar.gz
Patch from Vladimir N. Oleynik to save 128 bytes by moving error
checking for some my_* functions to utility.c
-rw-r--r--busybox.h6
-rw-r--r--chmod_chown_chgrp.c9
-rw-r--r--coreutils/id.c3
-rw-r--r--id.c3
-rw-r--r--include/busybox.h6
-rw-r--r--utility.c17
6 files changed, 16 insertions, 28 deletions
diff --git a/busybox.h b/busybox.h
index 8d4976a..53d2211 100644
--- a/busybox.h
+++ b/busybox.h
@@ -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);
diff --git a/chmod_chown_chgrp.c b/chmod_chown_chgrp.c
index a458cf7..4fc9869 100644
--- a/chmod_chown_chgrp.c
+++ b/chmod_chown_chgrp.c
@@ -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);
}
/*
diff --git a/coreutils/id.c b/coreutils/id.c
index 3667b32..3f90d55 100644
--- a/coreutils/id.c
+++ b/coreutils/id.c
@@ -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)
diff --git a/id.c b/id.c
index 3667b32..3f90d55 100644
--- a/id.c
+++ b/id.c
@@ -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)
diff --git a/include/busybox.h b/include/busybox.h
index 8d4976a..53d2211 100644
--- a/include/busybox.h
+++ b/include/busybox.h
@@ -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);
diff --git a/utility.c b/utility.c
index e353596..df4573c 100644
--- a/utility.c
+++ b/utility.c
@@ -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;
}