summaryrefslogtreecommitdiff
path: root/user/icewm/guard-string-funcs.patch
blob: dfb412b9ced241e9cd3f1f1094938410e79b75e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
From 57b8f15fbd67709055c245222b0c20cd27d3c3a1 Mon Sep 17 00:00:00 2001
From: Bert Gijsbers <gijsbers@science.uva.nl>
Date: Mon, 31 Jul 2017 21:30:20 +0200
Subject: [PATCH] Changes for ALTLinux which has its own prototypes for
 strlcpy/strlcat. Also cleanup obsolete AC_FUNC_*s and sort -u the
 CHECK_FUNCs. Add two AC_RUN_IFELSE to detect correct operations of
 strlcpy/strcat. Define HAVE_STRLCPY / HAVE_STRLCAT if they do. Don't include
 our own strlcpy/strlcat if these are defined.

---
 configure.ac       | 49 ++++++++++++++++++++++++++++++++++++++++---------
 src/CMakeLists.txt | 19 +++++++------------
 src/base.h         |  5 +++++
 src/misc.cc        |  4 ++++
 4 files changed, 56 insertions(+), 21 deletions(-)

diff --git a/configure.ac b/configure.ac
index fe9176ea..e00cb147 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,21 +110,52 @@ AC_CHECK_SIZEOF(long, 4)
 AC_TYPE_SIGNAL
 
 # Checks for library functions.
-AC_FUNC_STRFTIME
-AC_FUNC_VPRINTF
-AC_FUNC_ERROR_AT_LINE
 if test x$cross_compling != xyes ; then :; AC_FUNC_FORK fi
-AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
 if test x$cross_compling != xyes ; then :; AC_FUNC_MALLOC fi
-AC_FUNC_MMAP
 if test x$cross_compling != xyes ; then :; AC_FUNC_REALLOC fi
-AC_FUNC_STRNLEN
-AC_CHECK_FUNCS([dup2 getcwd gethostbyname gethostname gettimeofday mblen memchr memmove memset mkdir nl_langinfo putenv select setlocale socket strcasecmp strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol sysinfo uname abort wordexp])
-AC_CHECK_FUNCS([gettimeofday putenv select socket strtol strtoul basename])
-AC_CHECK_FUNCS([sysctlbyname asprintf])
+AC_CHECK_FUNCS([abort basename dup2])
+AC_CHECK_FUNCS([gethostbyname gethostname gettimeofday])
+AC_CHECK_FUNCS([mblen memchr memmove memset mkdir nl_langinfo])
+AC_CHECK_FUNCS([select setlocale socket])
+AC_CHECK_FUNCS([strcasecmp strchr strcspn strdup strerror])
+AC_CHECK_FUNCS([strncasecmp strrchr strspn strstr strtol strtoul])
+AC_CHECK_FUNCS([sysctlbyname sysinfo uname wordexp])
 AC_CHECK_FUNC([getloadavg],[AC_DEFINE([HAVE_GETLOADAVG2], 1, [getloadavg() is available])])
 AC_FUNC_SELECT_ARGTYPES
 
+AC_MSG_CHECKING([for strlcpy])
+AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <string.h>]],[[
+               char a[2];
+               if (strlcpy(a, "yes", 2) != 3)
+                   return 1;]])],
+              [
+               AC_MSG_RESULT([yes])
+               AC_DEFINE_UNQUOTED([HAVE_STRLCPY], 1,
+                                  [Define to 1 if you have the strlcpy function.])
+              ],
+              [
+               AC_MSG_RESULT([no])
+               AC_DEFINE_UNQUOTED([HAVE_STRLCPY], 0,
+                                  [Define to 1 if you have the strlcpy function.])
+              ])
+
+AC_MSG_CHECKING([for strlcat])
+AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <string.h>]],[[
+               char a[4] = "no";
+               if (strlcat(a, "yes", 4) != 5)
+                   return 1;]])],
+              [
+               AC_MSG_RESULT([yes])
+               AC_DEFINE_UNQUOTED([HAVE_STRLCAT], 1,
+                                  [Define to 1 if you have the strlcat function.])
+              ],
+              [
+               AC_MSG_RESULT([no])
+               AC_DEFINE_UNQUOTED([HAVE_STRLCAT], 0,
+                                  [Define to 1 if you have the strlcat function.])
+              ])
+
+
 PKG_CHECK_MODULES([CORE],[fontconfig xext x11])
 AC_SUBST([CORE_CFLAGS])
 AC_SUBST([CORE_LIBS])
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index da476a0b..6f694c18 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -59,10 +59,12 @@ endif()
 # for x in `cat funclist` ; do grep $x src/* lib/* && echo $x >> exlist ; done 
 # perl -e 'print "CHECK_FUNCTION_EXISTS($_ HAVE_".uc($_).")\n" for @ARGV' `cat exlist`
 # perl -e 'print "#cmakedefine HAVE_".uc($_)."\n" for @ARGV' `cat exlist`
+CHECK_FUNCTION_EXISTS(abort HAVE_ABORT)
+CHECK_FUNCTION_EXISTS(basename HAVE_BASENAME)
 CHECK_FUNCTION_EXISTS(dup2 HAVE_DUP2)
-CHECK_FUNCTION_EXISTS(getcwd HAVE_GETCWD)
 CHECK_FUNCTION_EXISTS(gethostbyname HAVE_GETHOSTBYNAME)
 CHECK_FUNCTION_EXISTS(gethostname HAVE_GETHOSTNAME)
+CHECK_FUNCTION_EXISTS(getloadavg HAVE_GETLOADAVG)
 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
 CHECK_FUNCTION_EXISTS(mblen HAVE_MBLEN)
 CHECK_FUNCTION_EXISTS(memchr HAVE_MEMCHR)
@@ -70,7 +72,6 @@ CHECK_FUNCTION_EXISTS(memmove HAVE_MEMMOVE)
 CHECK_FUNCTION_EXISTS(memset HAVE_MEMSET)
 CHECK_FUNCTION_EXISTS(mkdir HAVE_MKDIR)
 CHECK_FUNCTION_EXISTS(nl_langinfo HAVE_NL_LANGINFO)
-CHECK_FUNCTION_EXISTS(putenv HAVE_PUTENV)
 CHECK_FUNCTION_EXISTS(select HAVE_SELECT)
 CHECK_FUNCTION_EXISTS(setlocale HAVE_SETLOCALE)
 CHECK_FUNCTION_EXISTS(socket HAVE_SOCKET)
@@ -79,23 +80,17 @@ CHECK_FUNCTION_EXISTS(strchr HAVE_STRCHR)
 CHECK_FUNCTION_EXISTS(strcspn HAVE_STRCSPN)
 CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP)
 CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
+CHECK_FUNCTION_EXISTS(strlcpy HAVE_STRLCPY)
+CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
 CHECK_FUNCTION_EXISTS(strncasecmp HAVE_STRNCASECMP)
 CHECK_FUNCTION_EXISTS(strrchr HAVE_STRRCHR)
 CHECK_FUNCTION_EXISTS(strspn HAVE_STRSPN)
 CHECK_FUNCTION_EXISTS(strstr HAVE_STRSTR)
 CHECK_FUNCTION_EXISTS(strtol HAVE_STRTOL)
+CHECK_FUNCTION_EXISTS(strtoul HAVE_STRTOL)
+CHECK_FUNCTION_EXISTS(sysctlbyname HAVE_SYSCTLBYNAME)
 CHECK_FUNCTION_EXISTS(sysinfo HAVE_SYSINFO)
 CHECK_FUNCTION_EXISTS(uname HAVE_UNAME)
-CHECK_FUNCTION_EXISTS(abort HAVE_ABORT)
-CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
-CHECK_FUNCTION_EXISTS(putenv HAVE_PUTENV)
-CHECK_FUNCTION_EXISTS(select HAVE_SELECT)
-CHECK_FUNCTION_EXISTS(socket HAVE_SOCKET)
-CHECK_FUNCTION_EXISTS(strtol HAVE_STRTOL)
-CHECK_FUNCTION_EXISTS(basename HAVE_BASENAME)
-CHECK_FUNCTION_EXISTS(sysctlbyname HAVE_SYSCTLBYNAME)
-CHECK_FUNCTION_EXISTS(getloadavg HAVE_GETLOADAVG)
-CHECK_FUNCTION_EXISTS(asprintf HAVE_ASPRINTF)
 CHECK_FUNCTION_EXISTS(wordexp HAVE_WORDEXP)
 
 CHECK_LIBRARY_EXISTS (X11 XInternAtoms "" HAVE_XINTERNATOMS)
diff --git a/src/base.h b/src/base.h
index 0df34ccb..2083ca6f 100644
--- a/src/base.h
+++ b/src/base.h
@@ -49,9 +49,14 @@ inline T abs(T v) {
 /*** String Functions *********************************************************/
 
 /* Prefer this as a safer alternative over strcpy. Return strlen(from). */
+#ifndef HAVE_STRLCPY
 size_t strlcpy(char *dest, const char *from, size_t dest_size);
+#endif
+
 /* Prefer this over strcat. Return strlen(dest) + strlen(from). */
+#ifndef HAVE_STRLCAT
 size_t strlcat(char *dest, const char *from, size_t dest_size);
+#endif
 
 char *newstr(char const *str);
 char *newstr(char const *str, int len);
diff --git a/src/misc.cc b/src/misc.cc
index b0ac1c95..97638495 100644
--- a/src/misc.cc
+++ b/src/misc.cc
@@ -448,6 +448,7 @@ void operator delete[](void *p) {
 #endif
 
 /* Prefer this as a safer alternative over strcpy. Return strlen(from). */
+#ifndef HAVE_STRLCPY
 size_t strlcpy(char *dest, const char *from, size_t dest_size)
 {
     const char *in = from;
@@ -461,8 +462,10 @@ size_t strlcpy(char *dest, const char *from, size_t dest_size)
     while (*in) ++in;
     return in - from;
 }
+#endif
 
 /* Prefer this over strcat. Return strlen(dest) + strlen(from). */
+#ifndef HAVE_STRLCAT
 size_t strlcat(char *dest, const char *from, size_t dest_size)
 {
     char *to = dest;
@@ -470,6 +473,7 @@ size_t strlcat(char *dest, const char *from, size_t dest_size)
     while (to < stop && *to) ++to;
     return to - dest + strlcpy(to, from, dest_size - (to - dest));
 }
+#endif
 
 char *newstr(char const *str) {
     return (str != NULL ? newstr(str, strlen(str)) : NULL);
-- 
2.15.0