die_if_bad_username: shrink: 88 -> 77 bytes
authorDenis Vlasenko <vda.linux@googlemail.com>
Wed, 19 Mar 2008 23:25:00 +0000 (23:25 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Wed, 19 Mar 2008 23:25:00 +0000 (23:25 -0000)
libbb/die_if_bad_username.c

index 251b1f06c03bdc36ae5188119d190f6e7fdb309e..337ac6012b5250e876b0d434b355f28716914a37 100644 (file)
 
 void die_if_bad_username(const char *name)
 {
-       int i = 0;
-
+       goto skip; /* 1st char being dash isn't valid */
        do {
-               if (!isalnum(*name)
-                && !(*name == '_')
-                && !(*name == '.')
-                && !(*name == '@')
-                && !(*name == '-' && i)
-                && !(*name == '$' && !*(name + 1))
-               )
-                       bb_error_msg_and_die("illegal character '%c'", *name);
-               i++;
+               if (*name == '-')
+                       continue;
+ skip:
+               if (isalnum(*name)
+                || *name == '_'
+                || *name == '.'
+                || *name == '@'
+                || (*name == '$' && !*(name + 1))
+               ) {
+                       continue;
+               }
+               bb_error_msg_and_die("illegal character '%c'", *name);
        } while (*++name);
 }