Provide compat functions for wcsl{cpy,cat}().
This commit is contained in:
parent
684c581b32
commit
7c26144e31
6 changed files with 118 additions and 10 deletions
|
|
@ -19,7 +19,7 @@ LIBS = @LIBS@
|
|||
INSTALL = @INSTALL@
|
||||
|
||||
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@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@
|
|||
/* Define to 1 if you have the `IORegisterForSystemPower' function. */
|
||||
#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. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
|
|
@ -69,6 +72,12 @@
|
|||
/* Define to 1 if you have the `use_default_colors' function. */
|
||||
#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. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
|
|
|
|||
11
configure
vendored
11
configure
vendored
|
|
@ -2225,7 +2225,7 @@ case $host_os in
|
|||
CPPFLAGS="$CPPFLAGS -D_NETBSD_SOURCE"
|
||||
;;
|
||||
solaris*)
|
||||
CPPFLAGS="-D__EXTENSIONS__ -D_XOPEN_SOURCE=700 -D_FILE_OFFSET_BITS=64"
|
||||
CPPFLAGS="-D__EXTENSIONS__ -D_FILE_OFFSET_BITS=64"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
@ -3872,12 +3872,13 @@ fi
|
|||
|
||||
oLIBS="$LIBS"
|
||||
LIBS="$LIBS $CURSES_LIB"
|
||||
for ac_func in use_default_colors
|
||||
for ac_func in use_default_colors wcslcpy wcslcat
|
||||
do :
|
||||
ac_fn_c_check_func "$LINENO" "use_default_colors" "ac_cv_func_use_default_colors"
|
||||
if test "x$ac_cv_func_use_default_colors" = xyes; then :
|
||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||
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
|
||||
#define HAVE_USE_DEFAULT_COLORS 1
|
||||
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
|
||||
_ACEOF
|
||||
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ AC_PROG_INSTALL
|
|||
AX_WITH_CURSES
|
||||
oLIBS="$LIBS"
|
||||
LIBS="$LIBS $CURSES_LIB"
|
||||
AC_CHECK_FUNCS([use_default_colors])
|
||||
AC_CHECK_FUNCS([use_default_colors wcslcpy wcslcat])
|
||||
LIBS="$oLIBS"
|
||||
|
||||
AC_CHECK_HEADERS([IOKit/pwr_mgt/IOPMLib.h])
|
||||
|
|
|
|||
6
str.c
6
str.c
|
|
@ -194,19 +194,19 @@ wchar_t t[16];
|
|||
|
||||
if (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);
|
||||
}
|
||||
|
||||
if (tm >= 60) {
|
||||
swprintf(t, wsizeof(t), L"%dm", tm / 60);
|
||||
wcslcat(res, t, sizeof(res));
|
||||
wcslcat(res, t, wsizeof(res));
|
||||
tm %= 60;
|
||||
}
|
||||
|
||||
if (tm) {
|
||||
swprintf(t, wsizeof(t), L"%ds", tm);
|
||||
wcslcat(res, t, sizeof(res));
|
||||
wcslcat(res, t, wsizeof(res));
|
||||
}
|
||||
|
||||
return wcsdup(res);
|
||||
|
|
|
|||
98
wcslcpy.c
Normal file
98
wcslcpy.c
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue