diff options
author | Karel Zak | 2016-04-22 13:59:06 +0200 |
---|---|---|
committer | Karel Zak | 2016-04-22 13:59:06 +0200 |
commit | deb1c903272d45e8a1975b1da151d4deb3defe3b (patch) | |
tree | 72bc20ea7cad9056bc6ae669debd02a8ed89f7b0 /libmount/src/tab.c | |
parent | tests: move getopt to separate directory (diff) | |
download | kernel-qcow2-util-linux-deb1c903272d45e8a1975b1da151d4deb3defe3b.tar.gz kernel-qcow2-util-linux-deb1c903272d45e8a1975b1da151d4deb3defe3b.tar.xz kernel-qcow2-util-linux-deb1c903272d45e8a1975b1da151d4deb3defe3b.zip |
libmount: remove duplicate code
For petty long time we have strdup_to_struct_member() macro to avoid
duplicate code when strdup() strings in setter functions. Let's use it
for libmount.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/tab.c')
-rw-r--r-- | libmount/src/tab.c | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/libmount/src/tab.c b/libmount/src/tab.c index a8d835e04..b09c79f0d 100644 --- a/libmount/src/tab.c +++ b/libmount/src/tab.c @@ -287,18 +287,7 @@ const char *mnt_table_get_intro_comment(struct libmnt_table *tb) */ int mnt_table_set_intro_comment(struct libmnt_table *tb, const char *comm) { - char *p = NULL; - - if (!tb) - return -EINVAL; - if (comm) { - p = strdup(comm); - if (!p) - return -ENOMEM; - } - free(tb->comm_intro); - tb->comm_intro = p; - return 0; + return strdup_to_struct_member(tb, comm_intro, comm); } /** @@ -339,18 +328,7 @@ const char *mnt_table_get_trailing_comment(struct libmnt_table *tb) */ int mnt_table_set_trailing_comment(struct libmnt_table *tb, const char *comm) { - char *p = NULL; - - if (!tb) - return -EINVAL; - if (comm) { - p = strdup(comm); - if (!p) - return -ENOMEM; - } - free(tb->comm_tail); - tb->comm_tail = p; - return 0; + return strdup_to_struct_member(tb, comm_tail, comm); } /** |