Browse Source

Handle strlcat/strlcpy correctly on platforms that have them.

svn:r2647
Nick Mathewson 19 years ago
parent
commit
67f14032b1
5 changed files with 17 additions and 15 deletions
  1. 3 4
      configure.in
  2. 8 0
      src/common/compat.c
  3. 6 0
      src/common/compat.h
  4. 0 8
      src/common/util.c
  5. 0 3
      src/common/util.h

+ 3 - 4
configure.in

@@ -143,8 +143,7 @@ dnl These headers are not essential
 
 AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h)
 
-AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit setrlimit)
-AC_REPLACE_FUNCS(strlcat strlcpy)
+AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit setrlimit strlcat strlcpy)
 
 AC_CHECK_MEMBERS([struct timeval.tv_sec])
 
@@ -233,10 +232,10 @@ AC_SUBST(LOCALSTATEDIR)
 
 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
 # than autoconf's macros like.
-CFLAGS="$CFLAGS -Wall -W -Wno-unused-parameter -Wfloat-equal -Wdeclaration-after-statement -Wundef -Wendif-labels -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -g -O2"
+CFLAGS="$CFLAGS -Wall -W -Wno-unused-parameter -Wfloat-equal -Wundef -Wendif-labels -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -g -O2"
 
 # Add these in when you feel like fun.
-# -Wbad-function-cast -Werror
+# -Wbad-function-cast -Werror  -Wdeclaration-after-statement
 
 echo "confdir: $CONFDIR"
 

+ 8 - 0
src/common/compat.c

@@ -68,6 +68,14 @@
 #include "log.h"
 #include "util.h"
 
+/* Inline the strl functions if the plaform doesn't have them. */
+#ifndef HAVE_STRLCPY
+#include "strlcpy.c"
+#endif
+#ifndef HAVE_STRLCAT
+#include "strlcat.c"
+#endif
+
 /** Replacement for snprintf.  Differs from platform snprintf in two
  * ways: First, always NUL-terminates its output.  Second, always
  * returns -1 if the result is truncated.  (Note that this return

+ 6 - 0
src/common/compat.h

@@ -55,6 +55,12 @@
 #define strncasecmp strnicmp
 #define strcasecmp stricmp
 #endif
+#ifndef HAVE_STRLCAT
+size_t strlcat(char *dst, const char *src, size_t siz);
+#endif
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *dst, const char *src, size_t siz);
+#endif
 
 int tor_snprintf(char *str, size_t size, const char *format, ...)
      CHECK_PRINTF(3,4);

+ 0 - 8
src/common/util.c

@@ -88,14 +88,6 @@
 #define INADDR_NONE ((unsigned long) -1)
 #endif
 
-/* Inline the strl functions if the plaform doesn't have them. */
-#ifndef HAVE_STRLCPY
-#include "strlcpy.c"
-#endif
-#ifndef HAVE_STRLCAT
-#include "strlcat.c"
-#endif
-
 #ifndef O_BINARY
 #define O_BINARY 0
 #endif

+ 0 - 3
src/common/util.h

@@ -46,9 +46,6 @@ char *tor_strndup(const char *s, size_t n);
 
 /* String manipulation */
 #define HEX_CHARACTERS "0123456789ABCDEFabcdef"
-size_t strlcat(char *dst, const char *src, size_t siz);
-size_t strlcpy(char *dst, const char *src, size_t siz);
-
 void tor_strlower(char *s);
 int strcmpstart(const char *s1, const char *s2);
 int tor_strstrip(char *s, const char *strip);