[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Extract strlcpy and strlcmp to libtor-string
commit 90a09df5ba7b3e55ea388a4cc9b92161442bb380
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Fri Jun 22 11:18:19 2018 -0400
Extract strlcpy and strlcmp to libtor-string
---
src/common/.may_include | 2 --
src/common/compat.c | 8 --------
src/common/compat.h | 26 +-------------------------
src/lib/string/.may_include | 3 +++
src/lib/string/compat_string.c | 14 ++++++++++++++
src/lib/string/compat_string.h | 39 +++++++++++++++++++++++++++++++++++++++
src/lib/string/include.am | 2 ++
7 files changed, 59 insertions(+), 35 deletions(-)
diff --git a/src/common/.may_include b/src/common/.may_include
index d2a3d2fff..484b57e10 100644
--- a/src/common/.may_include
+++ b/src/common/.may_include
@@ -8,7 +8,5 @@ linux_syscalls.inc
micro-revision.i
siphash.h
src/ext/timeouts/timeout.c
-strlcat.c
-strlcpy.c
tor_queue.h
tor_readpassphrase.h
diff --git a/src/common/compat.c b/src/common/compat.c
index 351fa0563..1dcd06581 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -131,14 +131,6 @@ SecureZeroMemory(PVOID ptr, SIZE_T cnt)
#include "common/address.h"
#include "common/sandbox.h"
-/* Inline the strl functions if the platform doesn't have them. */
-#ifndef HAVE_STRLCPY
-#include "strlcpy.c"
-#endif
-#ifndef HAVE_STRLCAT
-#include "strlcat.c"
-#endif
-
/* When set_max_file_descriptors() is called, update this with the max file
* descriptor value so we can use it to check the limit when opening a new
* socket. Default value is what Debian sets as the default hard limit. */
diff --git a/src/common/compat.h b/src/common/compat.h
index 21fd0211a..605438cc6 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -48,6 +48,7 @@
#include "lib/cc/compat_compiler.h"
#include "common/compat_time.h"
#include "lib/string/compat_ctype.h"
+#include "lib/string/compat_string.h"
#include "lib/string/printf.h"
#include <stdio.h>
@@ -55,31 +56,6 @@
/* ===== Compiler compatibility */
-/* ===== String compatibility */
-#ifdef _WIN32
-/* Windows names string functions differently from most other platforms. */
-#define strncasecmp _strnicmp
-#define strcasecmp _stricmp
-#endif
-
-#if defined __APPLE__
-/* On OSX 10.9 and later, the overlap-checking code for strlcat would
- * appear to have a severe bug that can sometimes cause aborts in Tor.
- * Instead, use the non-checking variants. This is sad.
- *
- * See https://trac.torproject.org/projects/tor/ticket/15205
- */
-#undef strlcat
-#undef strlcpy
-#endif /* defined __APPLE__ */
-
-#ifndef HAVE_STRLCAT
-size_t strlcat(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
-#endif
-#ifndef HAVE_STRLCPY
-size_t strlcpy(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
-#endif
-
/** Represents an mmaped file. Allocated via tor_mmap_file; freed with
* tor_munmap_file. */
typedef struct tor_mmap_t {
diff --git a/src/lib/string/.may_include b/src/lib/string/.may_include
index 8781566d9..c5d771861 100644
--- a/src/lib/string/.may_include
+++ b/src/lib/string/.may_include
@@ -4,3 +4,6 @@ lib/err/*.h
lib/malloc/*.h
lib/ctime/*.h
lib/string/*.h
+
+strlcat.c
+strlcpy.c
diff --git a/src/lib/string/compat_string.c b/src/lib/string/compat_string.c
new file mode 100644
index 000000000..6df1bc4a1
--- /dev/null
+++ b/src/lib/string/compat_string.c
@@ -0,0 +1,14 @@
+/* Copyright (c) 2003-2004, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "lib/string/compat_string.h"
+
+/* Inline the strl functions if the platform doesn't have them. */
+#ifndef HAVE_STRLCPY
+#include "strlcpy.c"
+#endif
+#ifndef HAVE_STRLCAT
+#include "strlcat.c"
+#endif
diff --git a/src/lib/string/compat_string.h b/src/lib/string/compat_string.h
new file mode 100644
index 000000000..212d08b7a
--- /dev/null
+++ b/src/lib/string/compat_string.h
@@ -0,0 +1,39 @@
+/* Copyright (c) 2003-2004, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef TOR_COMPAT_STRING_H
+#define TOR_COMPAT_STRING_H
+
+#include "orconfig.h"
+#include "lib/cc/compat_compiler.h"
+
+#include <stddef.h>
+
+/* ===== String compatibility */
+#ifdef _WIN32
+/* Windows names string functions differently from most other platforms. */
+#define strncasecmp _strnicmp
+#define strcasecmp _stricmp
+#endif
+
+#if defined __APPLE__
+/* On OSX 10.9 and later, the overlap-checking code for strlcat would
+ * appear to have a severe bug that can sometimes cause aborts in Tor.
+ * Instead, use the non-checking variants. This is sad.
+ *
+ * See https://trac.torproject.org/projects/tor/ticket/15205
+ */
+#undef strlcat
+#undef strlcpy
+#endif /* defined __APPLE__ */
+
+#ifndef HAVE_STRLCAT
+size_t strlcat(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
+#endif
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
+#endif
+
+#endif
diff --git a/src/lib/string/include.am b/src/lib/string/include.am
index d458515d2..e532d5030 100644
--- a/src/lib/string/include.am
+++ b/src/lib/string/include.am
@@ -7,6 +7,7 @@ endif
src_lib_libtor_string_a_SOURCES = \
src/lib/string/compat_ctype.c \
+ src/lib/string/compat_string.c \
src/lib/string/util_string.c \
src/lib/string/printf.c \
src/lib/string/scanf.c
@@ -18,6 +19,7 @@ src_lib_libtor_string_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
noinst_HEADERS += \
src/lib/string/compat_ctype.h \
+ src/lib/string/compat_string.h \
src/lib/string/util_string.h \
src/lib/string/printf.h \
src/lib/string/scanf.h
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits