summaryrefslogtreecommitdiffstats
path: root/libsmartcols/src/cell.c
diff options
context:
space:
mode:
authorKarel Zak2014-03-19 16:29:39 +0100
committerKarel Zak2014-04-03 12:29:16 +0200
commitc638c57ac3af8b819ef7b71804d585c3e9cf549c (patch)
tree8c3c06a279c2cf91285b3dd4ef9fb3f19a2a8307 /libsmartcols/src/cell.c
parentinclude/carefulputc: cleanup and add fputs_{quoted,nonblank}() (diff)
downloadkernel-qcow2-util-linux-c638c57ac3af8b819ef7b71804d585c3e9cf549c.tar.gz
kernel-qcow2-util-linux-c638c57ac3af8b819ef7b71804d585c3e9cf549c.tar.xz
kernel-qcow2-util-linux-c638c57ac3af8b819ef7b71804d585c3e9cf549c.zip
libsmartcols: add table struct, cleanup refcounting
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/src/cell.c')
-rw-r--r--libsmartcols/src/cell.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/libsmartcols/src/cell.c b/libsmartcols/src/cell.c
index 31934ab64..5e3ea6081 100644
--- a/libsmartcols/src/cell.c
+++ b/libsmartcols/src/cell.c
@@ -26,12 +26,14 @@ int scols_reset_cell(struct libscols_cell *ce)
if (!ce)
return -EINVAL;
- free(ce->data);
+ if (!ce->is_ref)
+ free(ce->data);
free(ce->color);
memset(ce, 0, sizeof(*ce));
return 0;
}
+/* stores copy of the @str to cell */
int scols_cell_set_data(struct libscols_cell *ce, const char *str)
{
char *p = NULL;
@@ -45,8 +47,26 @@ int scols_cell_set_data(struct libscols_cell *ce, const char *str)
if (!p)
return -ENOMEM;
}
- free(ce->data);
+ if (!ce->is_ref)
+ free(ce->data);
ce->data = p;
+ ce->is_ref = 0;
+ return 0;
+}
+
+/* add reference to @str to cell */
+int scols_cell_refer_data(struct libscols_cell *ce, char *str)
+{
+ char *p = NULL;
+
+ assert(ce);
+
+ if (!ce)
+ return -EINVAL;
+ if (!ce->is_ref)
+ free(ce->data);
+ ce->data = p;
+ ce->is_ref = 1;
return 0;
}