summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@apple.com>2010-07-10 10:19:14 -0700
committerJeremy Huddleston <jeremyhu@apple.com>2010-07-10 10:19:14 -0700
commit8263f19cf9002c7b5f2967a2bde7af4ed117c1e5 (patch)
treebc51ad1db093e0ba37d26bd25f25186e5f75215a
parent3fa31068bcae6a5bee7fbd41788e13d6d56da8c0 (diff)
strnlen: Fix building on systems without strnlen(3)
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r--Makefile.am4
-rw-r--r--configure.ac5
-rw-r--r--strnlen.c37
-rw-r--r--strnlen.h32
-rw-r--r--xwininfo.c4
5 files changed, 80 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index c7e3fb3..3212c6d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,7 +22,7 @@
bin_PROGRAMS = xwininfo
AM_CFLAGS = $(CWARNFLAGS) $(XWININFO_CFLAGS)
-xwininfo_LDADD = $(XWININFO_LIBS)
+xwininfo_LDADD = $(XWININFO_LIBS) $(LIBOBJS)
xwininfo_SOURCES = \
clientwin.c \
@@ -39,7 +39,7 @@ appmandir = $(APP_MAN_DIR)
appman_DATA = $(appman_PRE:man=@APP_MAN_SUFFIX@)
-EXTRA_DIST = $(appman_PRE) autogen.sh
+EXTRA_DIST = $(appman_PRE) autogen.sh strnlen.h
MAINTAINERCLEANFILES = ChangeLog INSTALL
CLEANFILES = $(appman_DATA)
diff --git a/configure.ac b/configure.ac
index 4344cf1..45867ae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,11 @@ XORG_DEFAULT_OPTIONS
AC_CHECK_FUNCS([strlcat])
+AC_FUNC_STRNLEN
+if test "x$ac_cv_func_strnlen_working" = xyes; then
+ AC_DEFINE(HAVE_STRNLEN, 1, [Define to 1 if you have a working strnlen function.])
+fi
+
# Check for iconv in libc, then libiconv
AC_SEARCH_LIBS([iconv], [iconv], [AC_DEFINE([HAVE_ICONV], 1,
[Define to 1 if you have the iconv() function])])
diff --git a/strnlen.c b/strnlen.c
new file mode 100644
index 0000000..725e262
--- /dev/null
+++ b/strnlen.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2009 Apple Inc.
+ *
+ * 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 ABOVE LISTED COPYRIGHT HOLDER(S) 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.
+ */
+
+ /*
+ * Author: Jeremy Huddleston, Apple Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <strnlen.h>
+#include <string.h>
+
+size_t strnlen(const char *s, size_t maxlen) {
+ const char *p = memchr(s, 0, maxlen);
+ return (size_t)(p ? (p - s) : maxlen);
+}
diff --git a/strnlen.h b/strnlen.h
new file mode 100644
index 0000000..e1cdb85
--- /dev/null
+++ b/strnlen.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2009 Apple Inc.
+ *
+ * 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 ABOVE LISTED COPYRIGHT HOLDER(S) 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.
+ */
+
+ /*
+ * Author: Jeremy Huddleston, Apple Inc.
+ */
+
+#ifndef __STRNLEN_H__
+#define __STRNLEN_H__ 1
+#include <stdlib.h>
+
+extern size_t strnlen(const char *s, size_t maxlen);
+#endif /* __STRNLEN_H__ */
diff --git a/xwininfo.c b/xwininfo.c
index cd81834..265f6c6 100644
--- a/xwininfo.c
+++ b/xwininfo.c
@@ -83,6 +83,10 @@ of the copyright holder.
#include <ctype.h>
#include <errno.h>
+#ifndef HAVE_STRNLEN
+#include "strnlen.h"
+#endif
+
/* Include routines to handle parsing defaults */
#include "dsimple.h"