]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: (optstr) improve default initialization
authorKarel Zak <kzak@redhat.com>
Fri, 25 Sep 2020 08:25:25 +0000 (10:25 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 25 Sep 2020 08:25:25 +0000 (10:25 +0200)
Don't use memset() if we can use compiler for the first
initialization.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/optstr.c

index 781bb29806de5e3c369fdd1b70b9886d5760e285..b85f3924062d3d31293acf43da425e40e09008cc 100644 (file)
@@ -39,7 +39,7 @@ struct libmnt_optloc {
        size_t  namesz;
 };
 
-#define mnt_init_optloc(_ol)   (memset((_ol), 0, sizeof(struct libmnt_optloc)))
+#define MNT_INIT_OPTLOC        { .begin = NULL }
 
 #define mnt_optmap_entry_novalue(e) \
                (e && (e)->name && !strchr((e)->name, '=') && !((e)->mask & MNT_PREFIX))
@@ -292,14 +292,12 @@ int mnt_optstr_prepend_option(char **optstr, const char *name, const char *value
 int mnt_optstr_get_option(const char *optstr, const char *name,
                          char **value, size_t *valsz)
 {
-       struct libmnt_optloc ol;
+       struct libmnt_optloc ol = MNT_INIT_OPTLOC;
        int rc;
 
        if (!optstr || !name)
                return -EINVAL;
 
-       mnt_init_optloc(&ol);
-
        rc = mnt_optstr_locate_option((char *) optstr, name, &ol);
        if (!rc) {
                if (value)
@@ -330,9 +328,7 @@ int mnt_optstr_deduplicate_option(char **optstr, const char *name)
 
        opt = *optstr;
        do {
-               struct libmnt_optloc ol;
-
-               mnt_init_optloc(&ol);
+               struct libmnt_optloc ol = MNT_INIT_OPTLOC;
 
                rc = mnt_optstr_locate_option(opt, name, &ol);
                if (!rc) {
@@ -439,15 +435,13 @@ insert_value(char **str, char *pos, const char *substr, char **next)
  */
 int mnt_optstr_set_option(char **optstr, const char *name, const char *value)
 {
-       struct libmnt_optloc ol;
+       struct libmnt_optloc ol = MNT_INIT_OPTLOC;
        char *nameend;
        int rc = 1;
 
        if (!optstr || !name)
                return -EINVAL;
 
-       mnt_init_optloc(&ol);
-
        if (*optstr)
                rc = mnt_optstr_locate_option(*optstr, name, &ol);
        if (rc < 0)
@@ -486,14 +480,12 @@ int mnt_optstr_set_option(char **optstr, const char *name, const char *value)
  */
 int mnt_optstr_remove_option(char **optstr, const char *name)
 {
-       struct libmnt_optloc ol;
+       struct libmnt_optloc ol = MNT_INIT_OPTLOC;
        int rc;
 
        if (!optstr || !name)
                return -EINVAL;
 
-       mnt_init_optloc(&ol);
-
        rc = mnt_optstr_locate_option(*optstr, name, &ol);
        if (rc != 0)
                return rc;
@@ -1062,13 +1054,11 @@ int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next)
 int mnt_optstr_fix_user(char **optstr)
 {
        char *username;
-       struct libmnt_optloc ol;
+       struct libmnt_optloc ol = MNT_INIT_OPTLOC;
        int rc = 0;
 
        DBG(CXT, ul_debug("fixing user"));
 
-       mnt_init_optloc(&ol);
-
        rc = mnt_optstr_locate_option(*optstr, "user", &ol);
        if (rc)
                return rc == 1 ? 0 : rc;        /* 1: user= not found */