diff options
author | Karel Zak | 2014-04-14 13:44:23 +0200 |
---|---|---|
committer | Karel Zak | 2014-04-14 13:44:23 +0200 |
commit | 4baab7dfd36523ede61159c02744b5cf78928da0 (patch) | |
tree | 90755cbde0951e9952b4ecc79f6e9c4caada6145 /libsmartcols/src/table.c | |
parent | Merge branch 'scols' of git://github.com/ooprala/util-linux (diff) | |
download | kernel-qcow2-util-linux-4baab7dfd36523ede61159c02744b5cf78928da0.tar.gz kernel-qcow2-util-linux-4baab7dfd36523ede61159c02744b5cf78928da0.tar.xz kernel-qcow2-util-linux-4baab7dfd36523ede61159c02744b5cf78928da0.zip |
libsmartcols: improve line and cell separators
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/src/table.c')
-rw-r--r-- | libsmartcols/src/table.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c index 34b43b508..d4c61eea3 100644 --- a/libsmartcols/src/table.c +++ b/libsmartcols/src/table.c @@ -898,20 +898,23 @@ int scols_table_is_tree(struct libscols_table *tb) * * Returns: 0, a negative value in case of an error. */ -int scols_table_set_column_separator(struct libscols_table *tb, char *sep) +int scols_table_set_column_separator(struct libscols_table *tb, const char *sep) { + char *p = NULL; + assert (tb); if (!tb) return -EINVAL; - sep = strdup(sep); - if (!sep) - return -ENOMEM; + if (sep) { + p = strdup(sep); + if (!p) + return -ENOMEM; + } free(tb->colsep); - tb->colsep = sep; - + tb->colsep = p; return 0; } @@ -924,20 +927,23 @@ int scols_table_set_column_separator(struct libscols_table *tb, char *sep) * * Returns: 0, a negative value in case of an error. */ -int scols_table_set_line_separator(struct libscols_table *tb, char *sep) +int scols_table_set_line_separator(struct libscols_table *tb, const char *sep) { + char *p = NULL; + assert (tb); if (!tb) return -EINVAL; - sep = strdup(sep); - if (!sep) - return -ENOMEM; + if (sep) { + p = strdup(sep); + if (!p) + return -ENOMEM; + } free(tb->linesep); - tb->linesep = sep; - + tb->linesep = p; return 0; } |