Skip to content

Commit 7c26144

Browse files
author
Felicity Tarnell
committed
Provide compat functions for wcsl{cpy,cat}().
1 parent 684c581 commit 7c26144

File tree

6 files changed

+118
-10
lines changed

6 files changed

+118
-10
lines changed

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LIBS = @LIBS@
1919
INSTALL = @INSTALL@
2020

2121
OBJS = tts.o wide.o entry.o ui.o functions.o commands.o bindings.o \
22-
str.o style.o
22+
str.o style.o wcslcpy.o
2323

2424
prefix = @prefix@
2525
exec_prefix = @exec_prefix@

config.h.in

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
/* Define to 1 if you have the `IORegisterForSystemPower' function. */
2525
#undef HAVE_IOREGISTERFORSYSTEMPOWER
2626

27+
/* Define to 1 if you have the `m' library (-lm). */
28+
#undef HAVE_LIBM
29+
2730
/* Define to 1 if you have the <memory.h> header file. */
2831
#undef HAVE_MEMORY_H
2932

@@ -69,6 +72,12 @@
6972
/* Define to 1 if you have the `use_default_colors' function. */
7073
#undef HAVE_USE_DEFAULT_COLORS
7174

75+
/* Define to 1 if you have the `wcslcat' function. */
76+
#undef HAVE_WCSLCAT
77+
78+
/* Define to 1 if you have the `wcslcpy' function. */
79+
#undef HAVE_WCSLCPY
80+
7281
/* Define to the address where bug reports for this package should be sent. */
7382
#undef PACKAGE_BUGREPORT
7483

configure

+6-5
Original file line numberDiff line numberDiff line change
@@ -2225,7 +2225,7 @@ case $host_os in
22252225
CPPFLAGS="$CPPFLAGS -D_NETBSD_SOURCE"
22262226
;;
22272227
solaris*)
2228-
CPPFLAGS="-D__EXTENSIONS__ -D_XOPEN_SOURCE=700 -D_FILE_OFFSET_BITS=64"
2228+
CPPFLAGS="-D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64"
22292229
;;
22302230
esac
22312231

@@ -3872,12 +3872,13 @@ fi
38723872

38733873
oLIBS="$LIBS"
38743874
LIBS="$LIBS $CURSES_LIB"
3875-
for ac_func in use_default_colors
3875+
for ac_func in use_default_colors wcslcpy wcslcat
38763876
do :
3877-
ac_fn_c_check_func "$LINENO" "use_default_colors" "ac_cv_func_use_default_colors"
3878-
if test "x$ac_cv_func_use_default_colors" = xyes; then :
3877+
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
3878+
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
3879+
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
38793880
cat >>confdefs.h <<_ACEOF
3880-
#define HAVE_USE_DEFAULT_COLORS 1
3881+
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
38813882
_ACEOF
38823883

38833884
fi

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ AC_PROG_INSTALL
2626
AX_WITH_CURSES
2727
oLIBS="$LIBS"
2828
LIBS="$LIBS $CURSES_LIB"
29-
AC_CHECK_FUNCS([use_default_colors])
29+
AC_CHECK_FUNCS([use_default_colors wcslcpy wcslcat])
3030
LIBS="$oLIBS"
3131

3232
AC_CHECK_HEADERS([IOKit/pwr_mgt/IOPMLib.h])

str.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,19 @@ wchar_t t[16];
194194

195195
if (tm >= (60 * 60)) {
196196
swprintf(t, wsizeof(t), L"%dh", tm / (60 * 60));
197-
wcslcat(res, t, sizeof(res));
197+
wcslcat(res, t, wsizeof(res));
198198
tm %= (60 * 60);
199199
}
200200

201201
if (tm >= 60) {
202202
swprintf(t, wsizeof(t), L"%dm", tm / 60);
203-
wcslcat(res, t, sizeof(res));
203+
wcslcat(res, t, wsizeof(res));
204204
tm %= 60;
205205
}
206206

207207
if (tm) {
208208
swprintf(t, wsizeof(t), L"%ds", tm);
209-
wcslcat(res, t, sizeof(res));
209+
wcslcat(res, t, wsizeof(res));
210210
}
211211

212212
return wcsdup(res);

wcslcpy.c

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* $NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */
2+
/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */
3+
4+
/*
5+
* Copyright (c) 1998 Todd C. Miller <[email protected]>
6+
*
7+
* Permission to use, copy, modify, and distribute this software for any
8+
* purpose with or without fee is hereby granted, provided that the above
9+
* copyright notice and this permission notice appear in all copies.
10+
*
11+
* THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
12+
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
13+
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
14+
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
16+
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18+
*/
19+
20+
#include <sys/types.h>
21+
#include <assert.h>
22+
#include <string.h>
23+
24+
#include "config.h"
25+
26+
/*
27+
* Copy src to string dst of size siz. At most siz-1 characters
28+
* will be copied. Always NUL terminates (unless siz == 0).
29+
* Returns strlen(src); if retval >= siz, truncation occurred.
30+
*/
31+
#ifndef HAVE_WCSLCPY
32+
size_t
33+
wcslcpy(dst, src, siz)
34+
wchar_t *dst;
35+
wchar_t const *src;
36+
size_t siz;
37+
{
38+
wchar_t *d = dst;
39+
const wchar_t *s = src;
40+
size_t n = siz;
41+
42+
/* Copy as many bytes as will fit */
43+
if (n != 0 && --n != 0) {
44+
do {
45+
if ((*d++ = *s++) == 0)
46+
break;
47+
} while (--n != 0);
48+
}
49+
50+
/* Not enough room in dst, add NUL and traverse rest of src */
51+
if (n == 0) {
52+
if (siz != 0)
53+
*d = '\0'; /* NUL-terminate dst */
54+
while (*s++)
55+
;
56+
}
57+
58+
return(s - src - 1); /* count does not include NUL */
59+
}
60+
#endif
61+
62+
/*
63+
* Appends src to string dst of size siz (unlike strncat, siz is the
64+
* full size of dst, not space left). At most siz-1 characters
65+
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
66+
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
67+
* If retval >= siz, truncation occurred.
68+
*/
69+
#ifndef HAVE_WCSLCAT
70+
size_t
71+
wcslcat(wchar_t *dst, const wchar_t *src, size_t siz)
72+
{
73+
wchar_t *d = dst;
74+
const wchar_t *s = src;
75+
size_t n = siz;
76+
size_t dlen;
77+
78+
/* Find the end of dst and adjust bytes left but don't go past end */
79+
while (n-- != 0 && *d != '\0')
80+
d++;
81+
dlen = d - dst;
82+
n = siz - dlen;
83+
84+
if (n == 0)
85+
return(dlen + strlen(s));
86+
while (*s != '\0') {
87+
if (n != 1) {
88+
*d++ = *s;
89+
n--;
90+
}
91+
s++;
92+
}
93+
*d = '\0';
94+
95+
return(dlen + (s - src)); /* count does not include NUL */
96+
}
97+
#endif
98+

0 commit comments

Comments
 (0)