Fix: fix wint_t warning on MSYS2/mingw
[babeltrace.git] / src / common / common.c
index 404357a38beed46ebf55e086c17542c14cdf3e3a..2616da2596afd87d6158c4c0cd0c457ab256b4b1 100644 (file)
@@ -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;
+}
This page took 0.025613 seconds and 4 git commands to generate.