Port: Add Solaris string compat
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 14 Oct 2015 20:56:12 +0000 (16:56 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 19 Oct 2015 04:14:05 +0000 (00:14 -0400)
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
src/bin/lttng-relayd/viewer-stream.c
src/bin/lttng-sessiond/cmd.c
src/bin/lttng-sessiond/kernel-consumer.c
src/bin/lttng/commands/enable_events.c
src/common/compat/Makefile.am
src/common/compat/string.h [new file with mode: 0644]
src/common/utils.c

index 4cefd8c90e8944c399f2123cd528f20b16d8596c..87eabe8157f1d8ea10e1204fd414ebb9eba81092 100644 (file)
@@ -69,7 +69,7 @@ AC_CHECK_FUNCS([ \
        atexit bzero clock_gettime dup2 fdatasync ftruncate \
        gethostbyname gethostname getpagesize localtime_r memchr memset \
        mkdir munmap putenv realpath rmdir socket strchr strcspn strdup \
-       strncasecmp strndup strpbrk strrchr strstr strtol strtoul \
+       strncasecmp strndup strnlen strpbrk strrchr strstr strtol strtoul \
        strtoull \
 ])
 
index 333246afb3f4d312874cca9cfc144e6cc0fdf932..42318dff9160ffada3baf0385b6e7320a08f55e5 100644 (file)
@@ -21,6 +21,7 @@
 #define _LGPL_SOURCE
 #include <common/common.h>
 #include <common/index/index.h>
+#include <common/compat/string.h>
 
 #include "lttng-relayd.h"
 #include "viewer-stream.h"
@@ -51,12 +52,12 @@ struct relay_viewer_stream *viewer_stream_create(struct relay_stream *stream,
                goto error;
        }
 
-       vstream->path_name = strndup(stream->path_name, LTTNG_VIEWER_PATH_MAX);
+       vstream->path_name = lttng_strndup(stream->path_name, LTTNG_VIEWER_PATH_MAX);
        if (vstream->path_name == NULL) {
                PERROR("relay viewer path_name alloc");
                goto error;
        }
-       vstream->channel_name = strndup(stream->channel_name,
+       vstream->channel_name = lttng_strndup(stream->channel_name,
                        LTTNG_VIEWER_NAME_MAX);
        if (vstream->channel_name == NULL) {
                PERROR("relay viewer channel_name alloc");
index 65d1d090e393d21e191770bfe0888b0c7c022d8c..b4521dfe3be28c63a083035b27ed121ad4dfbdd5 100644 (file)
@@ -18,7 +18,6 @@
 #define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <assert.h>
-#include <string.h>
 #include <inttypes.h>
 #include <urcu/list.h>
 #include <urcu/uatomic.h>
@@ -28,6 +27,7 @@
 #include <common/sessiond-comm/sessiond-comm.h>
 #include <common/relayd/relayd.h>
 #include <common/utils.h>
+#include <common/compat/string.h>
 
 #include "channel.h"
 #include "consumer.h"
@@ -1048,7 +1048,7 @@ int cmd_enable_channel(struct ltt_session *session,
        assert(attr);
        assert(domain);
 
-       len = strnlen(attr->name, sizeof(attr->name));
+       len = lttng_strnlen(attr->name, sizeof(attr->name));
 
        /* Validate channel name */
        if (attr->name[0] == '.' ||
index 83771f2d75c8896d142a705066410c50023acaf4..06616ba872b3f996ebf0e9447c6aee9440a8bb96 100644 (file)
 #define _LGPL_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
 #include <common/common.h>
 #include <common/defaults.h>
+#include <common/compat/string.h>
 
 #include "consumer.h"
 #include "health-sessiond.h"
@@ -48,9 +48,9 @@ static char *create_channel_path(struct consumer_output *consumer,
                        PERROR("snprintf kernel channel path");
                        goto error;
                }
-               pathname = strndup(tmp_path, sizeof(tmp_path));
+               pathname = lttng_strndup(tmp_path, sizeof(tmp_path));
                if (!pathname) {
-                       PERROR("strndup");
+                       PERROR("lttng_strndup");
                        goto error;
                }
 
@@ -69,9 +69,9 @@ static char *create_channel_path(struct consumer_output *consumer,
                        PERROR("snprintf kernel metadata path");
                        goto error;
                }
-               pathname = strndup(tmp_path, sizeof(tmp_path));
+               pathname = lttng_strndup(tmp_path, sizeof(tmp_path));
                if (!pathname) {
-                       PERROR("strndup");
+                       PERROR("lttng_strndup");
                        goto error;
                }
                DBG3("Kernel network consumer subdir path: %s", pathname);
index 5dcdd064496ce9afac74df7b367666bf80a5eda6..573725d5c1ba8d79bad1e4de43db310640b04681 100644 (file)
@@ -21,7 +21,6 @@
 #include <popt.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -29,6 +28,7 @@
 #include <ctype.h>
 
 #include <src/common/sessiond-comm/sessiond-comm.h>
+#include <common/compat/string.h>
 
 /* Mi dependancy */
 #include <common/mi-lttng.h>
@@ -626,9 +626,9 @@ int check_exclusion_subsets(const char *event_name,
                                char **new_exclusion_list;
 
                                /* Excluder is a proper subset of event */
-                               string = strndup(next_excluder, excluder_length);
+                               string = lttng_strndup(next_excluder, excluder_length);
                                if (!string) {
-                                       PERROR("strndup error");
+                                       PERROR("lttng_strndup error");
                                        goto error;
                                }
                                new_exclusion_list = realloc(exclusion_list,
index 5df27dfa3f4dd3a9628cfe15a2a950a55a5af0ef..7cd3f91fc6f8530356cc860f79d88819cd97d880 100644 (file)
@@ -10,4 +10,4 @@ endif
 
 libcompat_la_SOURCES = poll.h fcntl.h endian.h mman.h clone.h \
                socket.h compat-fcntl.c uuid.h tid.h \
-               getenv.h $(COMPAT)
+               getenv.h string.h $(COMPAT)
diff --git a/src/common/compat/string.h b/src/common/compat/string.h
new file mode 100644 (file)
index 0000000..91a1c09
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2015 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef _COMPAT_STRING_H
+#define _COMPAT_STRING_H
+
+#include <string.h>
+
+#ifdef HAVE_STRNLEN
+static inline
+size_t lttng_strnlen(const char *str, size_t max)
+{
+       return strnlen(str, max);
+}
+#else
+static inline
+size_t lttng_strnlen(const char *str, size_t max)
+{
+       size_t ret;
+       const char *end;
+
+       end = memchr(str, 0, max);
+
+       if (end) {
+               ret = (size_t) (end - str);
+       } else {
+               ret = max;
+       }
+
+       return ret;
+}
+#endif /* HAVE_STRNLEN */
+
+#ifdef HAVE_STRNDUP
+static inline
+char *lttng_strndup(const char *s, size_t n)
+{
+       return strndup(s, n);
+}
+#else
+static inline
+char *lttng_strndup(const char *s, size_t n)
+{
+       char *ret;
+       size_t navail;
+
+       if (!s) {
+               ret = NULL;
+               goto end;
+       }
+
+       /* min() */
+       navail = strlen(s) + 1;
+       if ((n + 1) < navail) {
+               navail = n + 1;
+       }
+
+       ret = malloc(navail);
+       if (!ret) {
+               goto end;
+       }
+
+       memcpy(ret, s, navail);
+       ret[navail - 1] = '\0';
+end:
+       return ret;
+}
+#endif /* HAVE_STRNDUP */
+
+#endif /* _COMPAT_STRING_H */
index 3c9e70ddad6439ee362d9187c751151eca60d32a..aaf577bcfd1a47e172f9c49be4657e3c15d319c5 100644 (file)
@@ -24,7 +24,6 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <stdlib.h>
-#include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -37,6 +36,7 @@
 #include <common/common.h>
 #include <common/runas.h>
 #include <common/compat/getenv.h>
+#include <common/compat/string.h>
 
 #include "utils.h"
 #include "defaults.h"
@@ -92,9 +92,9 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size)
                }
 
                /* Cut the part we will be trying to resolve */
-               cut_path = strndup(path, next - path);
+               cut_path = lttng_strndup(path, next - path);
                if (cut_path == NULL) {
-                       PERROR("strndup");
+                       PERROR("lttng_strndup");
                        goto error;
                }
 
@@ -230,9 +230,9 @@ char *utils_expand_path(const char *path)
        while ((next = strstr(absolute_path, "/./"))) {
 
                /* We prepare the start_path not containing it */
-               start_path = strndup(absolute_path, next - absolute_path);
+               start_path = lttng_strndup(absolute_path, next - absolute_path);
                if (!start_path) {
-                       PERROR("strndup");
+                       PERROR("lttng_strndup");
                        goto error;
                }
                /* And we concatenate it with the part after this string */
@@ -250,9 +250,9 @@ char *utils_expand_path(const char *path)
                }
 
                /* Then we prepare the start_path not containing it */
-               start_path = strndup(absolute_path, previous - absolute_path);
+               start_path = lttng_strndup(absolute_path, previous - absolute_path);
                if (!start_path) {
-                       PERROR("strndup");
+                       PERROR("lttng_strndup");
                        goto error;
                }
 
This page took 0.033999 seconds and 4 git commands to generate.