Provide compat functions for wcsl{cpy,cat}().

This commit is contained in:
Felicity Tarnell 2014-03-08 13:03:19 +00:00
parent 684c581b32
commit 7c26144e31
6 changed files with 118 additions and 10 deletions

View file

@ -19,7 +19,7 @@ LIBS = @LIBS@
INSTALL = @INSTALL@ INSTALL = @INSTALL@
OBJS = tts.o wide.o entry.o ui.o functions.o commands.o bindings.o \ OBJS = tts.o wide.o entry.o ui.o functions.o commands.o bindings.o \
str.o style.o str.o style.o wcslcpy.o
prefix = @prefix@ prefix = @prefix@
exec_prefix = @exec_prefix@ exec_prefix = @exec_prefix@

View file

@ -24,6 +24,9 @@
/* Define to 1 if you have the `IORegisterForSystemPower' function. */ /* Define to 1 if you have the `IORegisterForSystemPower' function. */
#undef HAVE_IOREGISTERFORSYSTEMPOWER #undef HAVE_IOREGISTERFORSYSTEMPOWER
/* Define to 1 if you have the `m' library (-lm). */
#undef HAVE_LIBM
/* Define to 1 if you have the <memory.h> header file. */ /* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H #undef HAVE_MEMORY_H
@ -69,6 +72,12 @@
/* Define to 1 if you have the `use_default_colors' function. */ /* Define to 1 if you have the `use_default_colors' function. */
#undef HAVE_USE_DEFAULT_COLORS #undef HAVE_USE_DEFAULT_COLORS
/* Define to 1 if you have the `wcslcat' function. */
#undef HAVE_WCSLCAT
/* Define to 1 if you have the `wcslcpy' function. */
#undef HAVE_WCSLCPY
/* Define to the address where bug reports for this package should be sent. */ /* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT #undef PACKAGE_BUGREPORT

11
configure vendored
View file

@ -2225,7 +2225,7 @@ case $host_os in
CPPFLAGS="$CPPFLAGS -D_NETBSD_SOURCE" CPPFLAGS="$CPPFLAGS -D_NETBSD_SOURCE"
;; ;;
solaris*) solaris*)
CPPFLAGS="-D__EXTENSIONS__ -D_XOPEN_SOURCE=700 -D_FILE_OFFSET_BITS=64" CPPFLAGS="-D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64"
;; ;;
esac esac
@ -3872,12 +3872,13 @@ fi
oLIBS="$LIBS" oLIBS="$LIBS"
LIBS="$LIBS $CURSES_LIB" LIBS="$LIBS $CURSES_LIB"
for ac_func in use_default_colors for ac_func in use_default_colors wcslcpy wcslcat
do : do :
ac_fn_c_check_func "$LINENO" "use_default_colors" "ac_cv_func_use_default_colors" as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
if test "x$ac_cv_func_use_default_colors" = xyes; then : ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF cat >>confdefs.h <<_ACEOF
#define HAVE_USE_DEFAULT_COLORS 1 #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF _ACEOF
fi fi

View file

@ -26,7 +26,7 @@ AC_PROG_INSTALL
AX_WITH_CURSES AX_WITH_CURSES
oLIBS="$LIBS" oLIBS="$LIBS"
LIBS="$LIBS $CURSES_LIB" LIBS="$LIBS $CURSES_LIB"
AC_CHECK_FUNCS([use_default_colors]) AC_CHECK_FUNCS([use_default_colors wcslcpy wcslcat])
LIBS="$oLIBS" LIBS="$oLIBS"
AC_CHECK_HEADERS([IOKit/pwr_mgt/IOPMLib.h]) AC_CHECK_HEADERS([IOKit/pwr_mgt/IOPMLib.h])

6
str.c
View file

@ -194,19 +194,19 @@ wchar_t t[16];
if (tm >= (60 * 60)) { if (tm >= (60 * 60)) {
swprintf(t, wsizeof(t), L"%dh", tm / (60 * 60)); swprintf(t, wsizeof(t), L"%dh", tm / (60 * 60));
wcslcat(res, t, sizeof(res)); wcslcat(res, t, wsizeof(res));
tm %= (60 * 60); tm %= (60 * 60);
} }
if (tm >= 60) { if (tm >= 60) {
swprintf(t, wsizeof(t), L"%dm", tm / 60); swprintf(t, wsizeof(t), L"%dm", tm / 60);
wcslcat(res, t, sizeof(res)); wcslcat(res, t, wsizeof(res));
tm %= 60; tm %= 60;
} }
if (tm) { if (tm) {
swprintf(t, wsizeof(t), L"%ds", tm); swprintf(t, wsizeof(t), L"%ds", tm);
wcslcat(res, t, sizeof(res)); wcslcat(res, t, wsizeof(res));
} }
return wcsdup(res); return wcsdup(res);

98
wcslcpy.c Normal file
View file

@ -0,0 +1,98 @@
/* $NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */
/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE
* FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <assert.h>
#include <string.h>
#include "config.h"
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
#ifndef HAVE_WCSLCPY
size_t
wcslcpy(dst, src, siz)
wchar_t *dst;
wchar_t const *src;
size_t siz;
{
wchar_t *d = dst;
const wchar_t *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}
#endif
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
#ifndef HAVE_WCSLCAT
size_t
wcslcat(wchar_t *dst, const wchar_t *src, size_t siz)
{
wchar_t *d = dst;
const wchar_t *s = src;
size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
if (n == 0)
return(dlen + strlen(s));
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return(dlen + (s - src)); /* count does not include NUL */
}
#endif