save a bit of code with *strchrnul = '\0' trick
authorDenis Vlasenko <vda.linux@googlemail.com>
Wed, 26 Dec 2007 20:56:55 +0000 (20:56 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Wed, 26 Dec 2007 20:56:55 +0000 (20:56 -0000)
function                                             old     new   delta
nextline                                              59      55      -4
include_conf                                         902     898      -4
read_config                                          414     406      -8
fsck_main                                           1880    1869     -11

e2fsprogs/fsck.c
modutils/modprobe.c
networking/inetd.c
networking/udhcp/files.c
util-linux/mount.c

index f80de81787bedf0d300c17867dce701a891b64d1..8dd9785ee474db656919b3d656edfdc570f2a8dd 100644 (file)
@@ -349,9 +349,7 @@ static int parse_fstab_line(char *line, struct fs_info **ret_fs)
 
        *ret_fs = 0;
        strip_line(line);
-       cp = strchr(line, '#');
-       if (cp)
-               *cp = '\0'; /* Ignore everything after the comment char */
+       *strchrnul(line, '#') = '\0'; /* Ignore everything after comment */
        cp = line;
 
        device = parse_word(&cp);
index bc2dbd12848151d9ba4e81f2f095f5443d87e1ab..f6681a8d831231a6d0d9b503a71de374b7b082e1 100644 (file)
@@ -242,11 +242,8 @@ static void include_conf(struct dep_t **first, struct dep_t **current, char *buf
 
        while (reads(fd, buffer, buflen)) {
                int l;
-               char *p;
 
-               p = strchr(buffer, '#');
-               if (p)
-                       *p = '\0';
+               *strchrnul(buffer, '#') = '\0';
 
                l = strlen(buffer);
 
index 5d3774639af4c1a7bdd7eb6dd5b69f660d6d3b88..a9c9397f50edb95fe87fa4c57b9f7832a14af09d 100644 (file)
@@ -554,13 +554,9 @@ static void setup(servtab_t *sep)
 
 static char *nextline(void)
 {
-       char *cp;
-
        if (fgets(line, LINE_SIZE, fconfig) == NULL)
                return NULL;
-       cp = strchr(line, '\n');
-       if (cp)
-               *cp = '\0';
+       *strchrnul(line, '\n') = '\0';
        return line;
 }
 
index 63c90647d70089afa11a48b982c767cf2193d67b..491b8871e0fe39abee6fa0c7447eff02a43b94b6 100644 (file)
@@ -332,14 +332,12 @@ int read_config(const char *file)
 
        while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) {
                char debug_orig[READ_CONFIG_BUF_SIZE];
-               char *p;
 
                lm++;
-               p = strchr(buffer, '\n');
-               if (p) *p = '\0';
-               if (ENABLE_FEATURE_UDHCP_DEBUG) strcpy(debug_orig, buffer);
-               p = strchr(buffer, '#');
-               if (p) *p = '\0';
+               *strchrnul(buffer, '\n') = '\0';
+               if (ENABLE_FEATURE_UDHCP_DEBUG)
+                       strcpy(debug_orig, buffer);
+               *strchrnul(buffer, '#') = '\0';
 
                token = strtok(buffer, " \t");
                if (!token) continue;
index 1ecdd95292b7919b3599a1d21cf16f0dac95634c..abf5cd03f978d33de15b8741d0266389d1559157 100644 (file)
@@ -1448,7 +1448,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
        // Might this be a virtual filesystem?
 
        if (ENABLE_FEATURE_MOUNT_HELPERS
-        && (strchr(mp->mnt_fsname,'#'))
+        && (strchr(mp->mnt_fsname, '#'))
        ) {
                char *s, *p, *args[35];
                int n = 0;