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 \
])
#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"
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");
#define _GNU_SOURCE
#define _LGPL_SOURCE
#include <assert.h>
-#include <string.h>
#include <inttypes.h>
#include <urcu/list.h>
#include <urcu/uatomic.h>
#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"
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] == '.' ||
#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"
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;
}
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);
#include <popt.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <ctype.h>
#include <src/common/sessiond-comm/sessiond-comm.h>
+#include <common/compat/string.h>
/* Mi dependancy */
#include <common/mi-lttng.h>
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,
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)
--- /dev/null
+/*
+ * 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 */
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
-#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <common/common.h>
#include <common/runas.h>
#include <common/compat/getenv.h>
+#include <common/compat/string.h>
#include "utils.h"
#include "defaults.h"
}
/* 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;
}
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 */
}
/* 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;
}