mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
Add check for swprintf() and a workaround when it is missing
We use this function once in our codebase, but fortunately the workaround is relatively easy. swprintf() is not available on Cygwin so the compile failed there, but we can do a series of mbstowcs() calls that produce the same end result as the swprintf() call. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
9441fba124
commit
bec2ba5b40
@ -161,8 +161,8 @@ AC_FUNC_FORK
|
||||
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
|
||||
AC_FUNC_MKTIME
|
||||
AC_TYPE_SIGNAL
|
||||
AC_CHECK_FUNCS([realpath regcomp strcasecmp strdup strerror strnlen \
|
||||
strndup strrchr strsep strstr strverscmp uname geteuid])
|
||||
AC_CHECK_FUNCS([geteuid realpath regcomp strcasecmp strdup strerror \
|
||||
strndup strrchr strsep strstr strverscmp swprintf uname])
|
||||
|
||||
# Enable large file support if available
|
||||
AC_SYS_LARGEFILE
|
||||
|
@ -393,7 +393,17 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
|
||||
len = strlen(opr) + ((pkgname) ? strlen(pkgname) : 0) + 2;
|
||||
wcstr = calloc(len, sizeof(wchar_t));
|
||||
/* print our strings to the alloc'ed memory */
|
||||
#if defined(HAVE_SWPRINTF)
|
||||
wclen = swprintf(wcstr, len, L"%s %s", opr, pkgname);
|
||||
#else
|
||||
/* because the format string was simple, we can easily do this without
|
||||
* using swprintf, although it is probably not as safe/fast. The max
|
||||
* chars we can copy is decremented each time by subtracting the length
|
||||
* of the already printed/copied wide char string. */
|
||||
wclen = mbstowcs(wcstr, opr, len);
|
||||
wclen += mbstowcs(wcstr + wclen, " ", len - wclen);
|
||||
wclen += mbstowcs(wcstr + wclen, pkgname, len - wclen);
|
||||
#endif
|
||||
wcwid = wcswidth(wcstr, wclen);
|
||||
padwid = textlen - wcwid;
|
||||
/* if padwid is < 0, we need to trim the string so padwid = 0 */
|
||||
|
Loading…
Reference in New Issue
Block a user