X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finclude%2Fcore%2Fdata.h;h=0b4b2e7419312e10d68f9725d7db061dea9d0d14;hb=e2fbe0efeb9be4c61911a18b337dc89ca351ca81;hp=c7c51b830c3761f91bb0ff55736a26087fb560e1;hpb=1830b6288476b5b680482bbcd8f4d04b4455549f;p=sysdb.git diff --git a/src/include/core/data.h b/src/include/core/data.h index c7c51b8..0b4b2e7 100644 --- a/src/include/core/data.h +++ b/src/include/core/data.h @@ -29,7 +29,6 @@ #define SDB_CORE_DATA_H 1 #include "core/time.h" -#include "utils/strbuf.h" #include #include @@ -94,24 +93,44 @@ sdb_data_copy(sdb_data_t *dst, const sdb_data_t *src); /* * sdb_data_free_datum: * Free any dynamic memory referenced by the specified datum. Does not free - * the memory allocated for the sdb_data_t object itself. This function must + * the memory allocated by the sdb_data_t object itself. This function must * not be used if any static or stack memory is referenced from the data * object. */ void sdb_data_free_datum(sdb_data_t *datum); +/* + * sdb_data_strlen: + * Returns a (worst-case) estimate for the number of bytes required to format + * the datum as a string. Does not take the terminating null byte into + * account. + */ +size_t +sdb_data_strlen(sdb_data_t *datum); + +enum { + SDB_UNQUOTED = 0, + SDB_SINGLE_QUOTED, + SDB_DOUBLE_QUOTED, +}; + /* * sdb_data_format: - * Append the specified datum to the specified string buffer using a default - * format. + * Output the specified datum to the specified string using a default format. + * The value of 'quoted' determines whether and how non-integer and + * non-decimal values are quoted. If the buffer size is less than the return + * value of sdb_data_strlen, the datum may be truncated. The buffer will + * always be nul-terminated after calling this function. * * Returns: - * - 0 on success + * - the number of characters written to the buffer (excluding the terminated + * null byte) or the number of characters which would have been written in + * case the output was truncated * - a negative value else */ int -sdb_data_format(sdb_data_t *datum, sdb_strbuf_t *buf); +sdb_data_format(sdb_data_t *datum, char *buf, size_t buflen, int quoted); #ifdef __cplusplus } /* extern "C" */