X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fvasnprintf.c;h=9c701f1c6140872b58721dbc8f9cbcf4b62c0b90;hb=55da53d0db0c7a9fd82b2abc809560b3089df6a5;hp=7aac42bcd5749424d1915907d890bc9d006da38e;hpb=87b04f998fd3e668027074b5b5d37205d3cdfec3;p=gnulib.git diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 7aac42bcd..9c701f1c6 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -1,20 +1,19 @@ /* vsprintf with automatic memory allocation. Copyright (C) 1999, 2002-2003 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published - by the Free Software Foundation; either version 2, or (at your option) + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - USA. */ + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Tell glibc's to provide a prototype for snprintf(). This must come before because may include @@ -40,12 +39,30 @@ #include "printf-parse.h" /* For those losing systems which don't have 'alloca' we have to add - some additional code emulating it. */ -#ifdef HAVE_ALLOCA + some additional code emulating it. */ +#ifdef HAVE_ALLOCA # define freea(p) /* nothing */ #else -# define alloca(n) malloc (n) -# define freea(p) free (p) +# define alloca(n) malloc (n) +# define freea(p) free (p) +#endif + +#ifdef HAVE_WCHAR_T +# ifdef HAVE_WCSLEN +# define local_wcslen wcslen +# else + /* Solaris 2.5.1 has wcslen() in a separate library libw.so. To avoid + a dependency towards this library, here is a local substitute. */ +static size_t +local_wcslen (const wchar_t *s) +{ + const wchar_t *ptr; + + for (ptr = s; *ptr != (wchar_t) 0; ptr++) + ; + return ptr - s; +} +# endif #endif char * @@ -369,7 +386,7 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) # ifdef HAVE_WCHAR_T if (type == TYPE_WIDE_STRING) tmp_length = - wcslen (a.arg[dp->arg_index].a.a_wide_string) + local_wcslen (a.arg[dp->arg_index].a.a_wide_string) * MB_CUR_MAX; else # endif @@ -510,7 +527,7 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) retcount = 0; #if HAVE_SNPRINTF -#define SNPRINTF_BUF(arg) \ +# define SNPRINTF_BUF(arg) \ switch (prefix_count) \ { \ case 0: \ @@ -530,7 +547,7 @@ vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args) abort (); \ } #else -#define SNPRINTF_BUF(arg) \ +# define SNPRINTF_BUF(arg) \ switch (prefix_count) \ { \ case 0: \