summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5f7d377)
raw | patch | inline | side by side (parent: 5f7d377)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 19 Oct 2014 20:21:45 +0000 (22:21 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 19 Oct 2014 20:21:45 +0000 (22:21 +0200) |
This function returns the size of the data-type for a given type.
src/core/data.c | patch | blob | history | |
src/include/core/data.h | patch | blob | history |
diff --git a/src/core/data.c b/src/core/data.c
index f489367a42218e35a94bbf64afbff7d6255442fb..9890aafb65c80fded00ba1db13db3390908bfef9 100644 (file)
--- a/src/core/data.c
+++ b/src/core/data.c
return 0;
} /* sdb_data_parse */
+size_t
+sdb_data_sizeof(int type)
+{
+ sdb_data_t v;
+ if (type == SDB_TYPE_INTEGER)
+ return sizeof(v.data.integer);
+ else if (type == SDB_TYPE_DECIMAL)
+ return sizeof(v.data.decimal);
+ else if (type == SDB_TYPE_STRING)
+ return sizeof(v.data.string);
+ else if (type == SDB_TYPE_DATETIME)
+ return sizeof(v.data.datetime);
+ else if (type == SDB_TYPE_BINARY)
+ return sizeof(v.data.binary);
+ else if (type == SDB_TYPE_REGEX)
+ return sizeof(v.data.re);
+ return 0;
+} /* sdb_data_sizeof */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
index 514c4d524ce2dd04dc463ff6b7e51254dede129f..c8c7482e796f4438aeafdb8eebe4588223636e7b 100644 (file)
--- a/src/include/core/data.h
+++ b/src/include/core/data.h
@@ -257,6 +257,17 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted);
int
sdb_data_parse(char *str, int type, sdb_data_t *data);
+/*
+ * sdb_data_sizeof:
+ * Return the size of the data-type identified by the specified type.
+ *
+ * Returns:
+ * - the size of the data-type on success
+ * - 0 else
+ */
+size_t
+sdb_data_sizeof(int type);
+
#ifdef __cplusplus
} /* extern "C" */
#endif