From: Michael Jeanson Date: Wed, 14 Oct 2015 20:56:12 +0000 (-0400) Subject: Port: Add Solaris string compat X-Git-Tag: v2.8.0-rc1~284 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f5436bfcf6797b979b308a9af782750f9d079686;p=lttng-tools.git Port: Add Solaris string compat Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/configure.ac b/configure.ac index 4cefd8c90..87eabe815 100644 --- a/configure.ac +++ b/configure.ac @@ -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 \ ]) diff --git a/src/bin/lttng-relayd/viewer-stream.c b/src/bin/lttng-relayd/viewer-stream.c index 333246afb..42318dff9 100644 --- a/src/bin/lttng-relayd/viewer-stream.c +++ b/src/bin/lttng-relayd/viewer-stream.c @@ -21,6 +21,7 @@ #define _LGPL_SOURCE #include #include +#include #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"); diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 65d1d090e..b4521dfe3 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -18,7 +18,6 @@ #define _GNU_SOURCE #define _LGPL_SOURCE #include -#include #include #include #include @@ -28,6 +27,7 @@ #include #include #include +#include #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] == '.' || diff --git a/src/bin/lttng-sessiond/kernel-consumer.c b/src/bin/lttng-sessiond/kernel-consumer.c index 83771f2d7..06616ba87 100644 --- a/src/bin/lttng-sessiond/kernel-consumer.c +++ b/src/bin/lttng-sessiond/kernel-consumer.c @@ -19,12 +19,12 @@ #define _LGPL_SOURCE #include #include -#include #include #include #include #include +#include #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); diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 5dcdd0644..573725d5c 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -29,6 +28,7 @@ #include #include +#include /* Mi dependancy */ #include @@ -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, diff --git a/src/common/compat/Makefile.am b/src/common/compat/Makefile.am index 5df27dfa3..7cd3f91fc 100644 --- a/src/common/compat/Makefile.am +++ b/src/common/compat/Makefile.am @@ -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 index 000000000..91a1c09e2 --- /dev/null +++ b/src/common/compat/string.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2015 Michael Jeanson + * + * 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 + +#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 */ diff --git a/src/common/utils.c b/src/common/utils.c index 3c9e70dda..aaf577bcf 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,7 @@ #include #include #include +#include #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; }