Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/mount Simplify a_uid and a_gid, and fix a_mask to actua...



details:   https://anonhg.NetBSD.org/src/rev/3e9067a7fa9f
branches:  trunk
changeset: 574530:3e9067a7fa9f
user:      dsl <dsl%NetBSD.org@localhost>
date:      Thu Mar 03 21:15:26 2005 +0000

description:
Simplify a_uid and a_gid, and fix a_mask to actually use its argument
(fortunately it is always called with 'optarg')
Saves a few bytes from mount_msdos in rescue_tiny.

diffstat:

 sbin/mount/fattr.c |  64 +++++++++++++++++++++--------------------------------
 sbin/mount/fattr.h |   8 +++---
 2 files changed, 29 insertions(+), 43 deletions(-)

diffs (121 lines):

diff -r f6a411a5f37d -r 3e9067a7fa9f sbin/mount/fattr.c
--- a/sbin/mount/fattr.c        Thu Mar 03 20:49:47 2005 +0000
+++ b/sbin/mount/fattr.c        Thu Mar 03 21:15:26 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fattr.c,v 1.3 2004/10/29 19:11:15 dsl Exp $ */
+/* $NetBSD: fattr.c,v 1.4 2005/03/03 21:15:26 dsl Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fattr.c,v 1.3 2004/10/29 19:11:15 dsl Exp $");
+__RCSID("$NetBSD: fattr.c,v 1.4 2005/03/03 21:15:26 dsl Exp $");
 #endif /* not lint */
 
 #include <sys/cdefs.h>
@@ -53,60 +53,46 @@
 
 #include "fattr.h"
 
+static int
+num_id(const char *s, const char *id_type)
+{
+       int id;
+       char *ep;
+
+       id = strtol(s, &ep, 0);
+       if (*ep || s == ep || id < 0)
+               errx(1, "unknown %s id: %s", id_type, s);
+       return id;
+}
+
 gid_t
-a_gid(s)
-       char *s;
+a_gid(const char *s)
 {
        struct group *gr;
-       char *gname;
-       gid_t gid;
 
        if ((gr = getgrnam(s)) != NULL)
-               gid = gr->gr_gid;
-       else {
-               for (gname = s; *s && isdigit((unsigned char)*s); ++s);
-               if (!*s)
-                       gid = atoi(gname);
-               else
-                       errx(1, "unknown group id: %s", gname);
-       }
-       return (gid);
+               return gr->gr_gid;
+       return num_id(s, "group");
 }
 
 uid_t
-a_uid(s)
-       char *s;
+a_uid(const char *s)
 {
        struct passwd *pw;
-       char *uname;
-       uid_t uid;
 
        if ((pw = getpwnam(s)) != NULL)
-               uid = pw->pw_uid;
-       else {
-               for (uname = s; *s && isdigit((unsigned char)*s); ++s);
-               if (!*s)
-                       uid = atoi(uname);
-               else
-                       errx(1, "unknown user id: %s", uname);
-       }
-       return (uid);
+               return pw->pw_uid;
+       return num_id(s, "user");
 }
 
 mode_t
-a_mask(s)
-       char *s;
+a_mask(const char *s)
 {
-       int done, rv;
+       int rv;
        char *ep;
 
-       done = 0;
-       rv = -1;
-       if (*s >= '0' && *s <= '7') {
-               done = 1;
-               rv = strtol(optarg, &ep, 8);
-       }
-       if (!done || rv < 0 || *ep)
+       rv = strtol(optarg, &ep, 8);
+       if (s == ep || *ep || rv < 0)
                errx(1, "invalid file mode: %s", s);
-       return (rv);
+       return rv;
 }
diff -r f6a411a5f37d -r 3e9067a7fa9f sbin/mount/fattr.h
--- a/sbin/mount/fattr.h        Thu Mar 03 20:49:47 2005 +0000
+++ b/sbin/mount/fattr.h        Thu Mar 03 21:15:26 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fattr.h,v 1.2 2005/02/05 14:44:46 xtraeme Exp $ */
+/* $NetBSD: fattr.h,v 1.3 2005/03/03 21:15:26 dsl Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -33,6 +33,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-gid_t a_gid(char *);
-uid_t a_uid(char *);
-mode_t a_mask(char *);
+gid_t a_gid(const char *);
+uid_t a_uid(const char *);
+mode_t a_mask(const char *);



Home | Main Index | Thread Index | Old Index