Port: Add compat for strnlen and strndup
[babeltrace.git] / formats / lttng-live / lttng-live-comm.c
index b9bbbb6725da0aa2bcb7076a0e624b848db44206..d26d83eb4bbb01a9d383585d57fab2761543fb4a 100644 (file)
@@ -26,7 +26,6 @@
 #include <netinet/in.h>
 #include <netdb.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
@@ -38,6 +37,7 @@
 #include <babeltrace/ctf/ctf-index.h>
 
 #include <babeltrace/babeltrace.h>
+#include <babeltrace/endian.h>
 #include <babeltrace/ctf/events.h>
 #include <babeltrace/ctf/callbacks.h>
 #include <babeltrace/ctf/iterator.h>
@@ -51,6 +51,8 @@
 #include <formats/ctf/events-private.h>
 
 #include <babeltrace/compat/memstream.h>
+#include <babeltrace/compat/send.h>
+#include <babeltrace/compat/string.h>
 
 #include "lttng-live.h"
 #include "lttng-viewer-abi.h"
@@ -102,7 +104,7 @@ ssize_t lttng_live_send(int fd, const void *buf, size_t len)
        ssize_t ret;
 
        do {
-               ret = send(fd, buf, len, MSG_NOSIGNAL);
+               ret = bt_send_nosigpipe(fd, buf, len);
        } while (ret < 0 && errno == EINTR);
        return ret;
 }
@@ -133,7 +135,7 @@ int lttng_live_connect_viewer(struct lttng_live_ctx *ctx)
        server_addr.sin_family = AF_INET;
        server_addr.sin_port = htons(ctx->port);
        server_addr.sin_addr = *((struct in_addr *) host->h_addr);
-       bzero(&(server_addr.sin_zero), 8);
+       memset(&(server_addr.sin_zero), 0, 8);
 
        if (connect(ctx->control_sock, (struct sockaddr *) &server_addr,
                                sizeof(struct sockaddr)) == -1) {
@@ -262,9 +264,9 @@ void update_session_list(GPtrArray *session_list, char *hostname,
 
        for (i = 0; i < session_list->len; i++) {
                relay_session = g_ptr_array_index(session_list, i);
-               if ((strncmp(relay_session->hostname, hostname, NAME_MAX) == 0) &&
+               if ((strncmp(relay_session->hostname, hostname, MAXNAMLEN) == 0) &&
                                strncmp(relay_session->name,
-                                       session_name, NAME_MAX) == 0) {
+                                       session_name, MAXNAMLEN) == 0) {
                        relay_session->streams += streams;
                        if (relay_session->clients < clients)
                                relay_session->clients = clients;
@@ -276,8 +278,8 @@ void update_session_list(GPtrArray *session_list, char *hostname,
                return;
 
        relay_session = g_new0(struct lttng_live_relay_session, 1);
-       relay_session->hostname = strndup(hostname, NAME_MAX);
-       relay_session->name = strndup(session_name, NAME_MAX);
+       relay_session->hostname = bt_strndup(hostname, MAXNAMLEN);
+       relay_session->name = bt_strndup(session_name, MAXNAMLEN);
        relay_session->clients = clients;
        relay_session->streams = streams;
        relay_session->timer = timer;
@@ -351,8 +353,8 @@ int lttng_live_list_sessions(struct lttng_live_ctx *ctx, const char *path)
                                        be32toh(lsession.live_timer));
                } else {
                        if ((strncmp(lsession.session_name, ctx->session_name,
-                               NAME_MAX) == 0) && (strncmp(lsession.hostname,
-                                       ctx->traced_hostname, NAME_MAX) == 0)) {
+                               MAXNAMLEN) == 0) && (strncmp(lsession.hostname,
+                                       ctx->traced_hostname, MAXNAMLEN) == 0)) {
                                printf_verbose("Reading from session %" PRIu64 "\n",
                                                session_id);
                                g_array_append_val(ctx->session_ids,
@@ -381,13 +383,13 @@ int lttng_live_ctf_trace_assign(struct lttng_live_viewer_stream *stream,
        int ret = 0;
 
        trace = g_hash_table_lookup(stream->session->ctf_traces,
-                       (gpointer) ctf_trace_id);
+                       &ctf_trace_id);
        if (!trace) {
                trace = g_new0(struct lttng_live_ctf_trace, 1);
                trace->ctf_trace_id = ctf_trace_id;
                trace->streams = g_ptr_array_new();
                g_hash_table_insert(stream->session->ctf_traces,
-                               (gpointer) ctf_trace_id,
+                               &trace->ctf_trace_id,
                                trace);
        }
        if (stream->metadata_flag)
@@ -680,8 +682,8 @@ retry:
                goto error;
        }
        if (ret_len != sizeof(rp)) {
-               fprintf(stderr, "[error] get_data_packet: expected %" PRId64
-                               ", received %" PRId64 "\n", sizeof(rp),
+               fprintf(stderr, "[error] get_data_packet: expected %zu"
+                               ", received %zd\n", sizeof(rp),
                                ret_len);
                goto error;
        }
@@ -1655,7 +1657,7 @@ int lttng_live_read(struct lttng_live_ctx *ctx)
 
        for (i = 0; i < ctx->session_ids->len; i++) {
                id = g_array_index(ctx->session_ids, uint64_t, i);
-               printf_verbose("Attaching to session %lu\n", id);
+               printf_verbose("Attaching to session %" PRIu64 "\n", id);
                ret = lttng_live_attach_session(ctx, id);
                printf_verbose("Attaching session returns %d\n", ret);
                if (ret < 0) {
This page took 0.02545 seconds and 4 git commands to generate.