X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fcommon.h;h=5156e1b0be565312ddcaac487f75102e5f59f40a;hb=2c1d3e9111d8f1b55361b9b880350c2680c90093;hp=b7245275832466c196ab464a54c3aa7e6ade6f01;hpb=45c51519900e100d9acda4acb9516ef69bc2d045;p=babeltrace.git diff --git a/src/common/common.h b/src/common/common.h index b7245275..5156e1b0 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -608,8 +609,6 @@ const char *bt_common_func_status_string(int status) return "INVALID_OBJECT"; case __BT_FUNC_STATUS_MEMORY_ERROR: return "MEMORY_ERROR"; - case __BT_FUNC_STATUS_LOADING_ERROR: - return "LOADING_ERROR"; case __BT_FUNC_STATUS_ERROR: return "ERROR"; case __BT_FUNC_STATUS_OK: @@ -620,8 +619,6 @@ const char *bt_common_func_status_string(int status) return "NOT_FOUND"; case __BT_FUNC_STATUS_AGAIN: return "AGAIN"; - case __BT_FUNC_STATUS_UNSUPPORTED: - return "UNSUPPORTED"; case __BT_FUNC_STATUS_CANCELED: return "CANCELED"; default: @@ -720,4 +717,50 @@ end: return ret; } +/* + * bt_g_string_append_printf cannot be inlined because it expects a + * variadic argument list. + */ +BT_HIDDEN +int bt_common_g_string_append_printf(GString *str, const char *fmt, ...); + +static inline +void bt_common_g_string_append(GString *str, const char *s) +{ + gsize len, allocated_len, s_len; + + /* str->len excludes \0. */ + len = str->len; + /* Exclude \0. */ + allocated_len = str->allocated_len - 1; + s_len = strlen(s); + if (G_UNLIKELY(allocated_len < len + s_len)) { + /* Resize. */ + g_string_set_size(str, len + s_len); + } else { + str->len = len + s_len; + } + memcpy(str->str + len, s, s_len + 1); +} + +static inline +void bt_common_g_string_append_c(GString *str, char c) +{ + gsize len, allocated_len, s_len; + + /* str->len excludes \0. */ + len = str->len; + /* Exclude \0. */ + allocated_len = str->allocated_len - 1; + s_len = 1; + if (G_UNLIKELY(allocated_len < len + s_len)) { + /* Resize. */ + g_string_set_size(str, len + s_len); + } else { + str->len = len + s_len; + } + str->str[len] = c; + str->str[len + 1] = '\0'; +} + #endif /* BABELTRACE_COMMON_INTERNAL_H */