diff options
author | Karel Zak | 2016-04-22 13:59:06 +0200 |
---|---|---|
committer | Karel Zak | 2016-04-22 14:17:21 +0200 |
commit | 8fcdce8fffeb243184d1f0bf1460a23cd0c598e3 (patch) | |
tree | 70afca7890e959f15661606f6673928b8643685a /libsmartcols/src/line.c | |
parent | libmount: remove duplicate code (diff) | |
download | kernel-qcow2-util-linux-8fcdce8fffeb243184d1f0bf1460a23cd0c598e3.tar.gz kernel-qcow2-util-linux-8fcdce8fffeb243184d1f0bf1460a23cd0c598e3.tar.xz kernel-qcow2-util-linux-8fcdce8fffeb243184d1f0bf1460a23cd0c598e3.zip |
libsmartcols 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 'libsmartcols/src/line.c')
-rw-r--r-- | libsmartcols/src/line.c | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/libsmartcols/src/line.c b/libsmartcols/src/line.c index 93cd09b99..a0e3a856c 100644 --- a/libsmartcols/src/line.c +++ b/libsmartcols/src/line.c @@ -285,31 +285,18 @@ int scols_line_next_child(struct libscols_line *ln, /** * scols_line_set_color: * @ln: a pointer to a struct libscols_line instance - * @color: color name or ESC sequence + * @co: color name or ESC sequence * * Returns: 0, a negative value in case of an error. */ -int scols_line_set_color(struct libscols_line *ln, const char *color) +int scols_line_set_color(struct libscols_line *ln, const char *co) { - char *p = NULL; - - if (!ln) - return -EINVAL; - if (color) { - if (isalnum(*color)) { - color = color_sequence_from_colorname(color); - - if (!color) - return -EINVAL; - } - p = strdup(color); - if (!p) - return -ENOMEM; + if (co && isalnum(*co)) { + co = color_sequence_from_colorname(co); + if (!co) + return -EINVAL; } - - free(ln->color); - ln->color = p; - return 0; + return strdup_to_struct_member(ln, color, co); } /** |