diff --git a/libio/stdio.h b/libio/stdio.h index 754301f..db05fd6 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -394,6 +394,14 @@ __END_NAMESPACE_C99 #endif #ifdef __USE_GNU +# include +/* Locale convenience functions */ +extern int snprintf_l (char *__restrict __s, locale_t loc, size_t __maxlen, + const char *__restrict __format, ...) + __THROWNL __attribute__ ((__format__ (__printf__, 4, 5))); +#endif + +#ifdef __USE_GNU /* Write formatted output to a string dynamically allocated with `malloc'. Store the address of the string in *PTR. */ extern int vasprintf (char **__restrict __ptr, const char *__restrict __f, diff --git a/stdio-common/Makefile b/stdio-common/Makefile index 658804b..1113692 100644 --- a/stdio-common/Makefile +++ b/stdio-common/Makefile @@ -37,7 +37,8 @@ routines := \ flockfile ftrylockfile funlockfile \ isoc99_scanf isoc99_vscanf isoc99_fscanf isoc99_vfscanf isoc99_sscanf \ isoc99_vsscanf \ - psiginfo + psiginfo \ + snprintf_l include ../Makeconfig diff --git a/stdio-common/snprintf_l.c b/stdio-common/snprintf_l.c new file mode 100644 index 0000000..ab40193 --- /dev/null +++ b/stdio-common/snprintf_l.c @@ -0,0 +1,41 @@ +/* Copyright (C) 1991-2013 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a) + +/* Write formatted output into S, according to the format + string FORMAT, writing no more than MAXLEN characters. */ +/* VARARGS3 */ +int +__snprintf_l (char *s, locale_t loc, size_t maxlen, const char *format, ...) +{ + va_list arg; + int done; + locale_t old_loc = uselocale (loc); + + va_start (arg, format); + done = __vsnprintf (s, maxlen, format, arg); + va_end (arg); + + uselocale (old_loc); + return done; +} +ldbl_weak_alias (__snprintf_l, snprintf_l)