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/column.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/column.c')
-rw-r--r-- | libsmartcols/src/column.c | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c index 5e7050192..a49d3de5c 100644 --- a/libsmartcols/src/column.c +++ b/libsmartcols/src/column.c @@ -196,7 +196,7 @@ struct libscols_cell *scols_column_get_header(struct libscols_column *cl) /** * scols_column_set_color: * @cl: a pointer to a struct libscols_column instance - * @color: color name or ESC sequence + * @co: color name or ESC sequence * * The default color for data cells and column header. * @@ -208,27 +208,14 @@ struct libscols_cell *scols_column_get_header(struct libscols_column *cl) * * Returns: 0, a negative value in case of an error. */ -int scols_column_set_color(struct libscols_column *cl, const char *color) +int scols_column_set_color(struct libscols_column *cl, const char *co) { - char *p = NULL; - - if (!cl) - return -EINVAL; - if (color) { - if (isalpha(*color)) { - color = color_sequence_from_colorname(color); - - if (!color) - return -EINVAL; - } - p = strdup(color); - if (!p) - return -ENOMEM; + if (co && isalpha(*co)) { + co = color_sequence_from_colorname(co); + if (!co) + return -EINVAL; } - - free(cl->color); - cl->color = p; - return 0; + return strdup_to_struct_member(cl, color, co); } /** |