From abddd8616349bc2a18e96f1efcb16a5af57401da Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 19 Oct 2014 22:21:45 +0200 Subject: [PATCH] data: Added sdb_data_sizeof(). This function returns the size of the data-type for a given type. --- src/core/data.c | 19 +++++++++++++++++++ src/include/core/data.h | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/core/data.c b/src/core/data.c index f489367..9890aaf 100644 --- a/src/core/data.c +++ b/src/core/data.c @@ -646,5 +646,24 @@ sdb_data_parse(char *str, int type, sdb_data_t *data) 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 : */ diff --git a/src/include/core/data.h b/src/include/core/data.h index 514c4d5..c8c7482 100644 --- 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 -- 2.30.2