X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fcommon.c;h=2616da2596afd87d6158c4c0cd0c457ab256b4b1;hb=81a26b7c6dc1dd6758f20afde5901fd80566d57f;hp=404357a38beed46ebf55e086c17542c14cdf3e3a;hpb=3e9b9ab05d500fc1b1590e0a9e0b82316d818999;p=babeltrace.git diff --git a/src/common/common.c b/src/common/common.c index 404357a3..2616da25 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -512,6 +512,7 @@ set_end_pos: error: if (output) { g_string_free(output, TRUE); + output = NULL; } end: @@ -672,7 +673,7 @@ struct bt_common_lttng_live_url_parts bt_common_parse_lttng_live_url( at += end_pos; - /* :// */ + /* `://` */ if (strncmp(at, "://", 3) != 0) { if (error_buf) { snprintf(error_buf, error_buf_size, @@ -682,6 +683,7 @@ struct bt_common_lttng_live_url_parts bt_common_parse_lttng_live_url( goto error; } + /* Skip `://` */ at += 3; /* Hostname */ @@ -731,12 +733,13 @@ struct bt_common_lttng_live_url_parts bt_common_parse_lttng_live_url( } if (at[end_pos] == '\0') { + /* Relay daemon hostname and ports provided only */ goto end; } at += end_pos; - /* /host/ */ + /* `/host/` */ if (strncmp(at, "/host/", 6) != 0) { if (error_buf) { snprintf(error_buf, error_buf_size, @@ -760,9 +763,16 @@ struct bt_common_lttng_live_url_parts bt_common_parse_lttng_live_url( } if (at[end_pos] == '\0') { - goto end; + if (error_buf) { + snprintf(error_buf, error_buf_size, + "Missing `/` after target hostname (`%s`)", + parts.target_hostname->str); + } + + goto error; } + /* Skip `/` */ at += end_pos + 1; /* Session name */ @@ -1403,10 +1413,8 @@ static inline void handle_conversion_specifier_std(char *buf, char **buf_ch, switch (length_mod) { case LENGTH_MOD_NONE: - BUF_STD_APPEND_SINGLE_ARG(int); - break; case LENGTH_MOD_LOW_L: - BUF_STD_APPEND_SINGLE_ARG(wint_t); + BUF_STD_APPEND_SINGLE_ARG(int); break; default: abort(); @@ -1852,3 +1860,44 @@ int bt_common_g_string_append_printf(GString *str, const char *fmt, ...) } return print_len; } + +BT_HIDDEN +int bt_common_append_file_content_to_g_string(GString *str, FILE *fp) +{ + const size_t chunk_size = 4096; + int ret = 0; + char *buf; + size_t read_len; + gsize orig_len = str->len; + + BT_ASSERT(str); + BT_ASSERT(fp); + buf = g_malloc(chunk_size); + if (!buf) { + ret = -1; + goto end; + } + + while (true) { + if (ferror(fp)) { + ret = -1; + goto end; + } + + if (feof(fp)) { + break; + } + + read_len = fread(buf, 1, chunk_size, fp); + g_string_append_len(str, buf, read_len); + } + +end: + if (ret) { + /* Remove what was appended */ + g_string_truncate(str, orig_len); + } + + g_free(buf); + return ret; +}