1169695Skan/* Implement the snprintf function. 2169695Skan Copyright (C) 2003 Free Software Foundation, Inc. 3169695Skan Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>. 4169695Skan 5169695SkanThis file is part of the libiberty library. This library is free 6169695Skansoftware; you can redistribute it and/or modify it under the 7169695Skanterms of the GNU General Public License as published by the 8169695SkanFree Software Foundation; either version 2, or (at your option) 9169695Skanany later version. 10169695Skan 11169695SkanThis library is distributed in the hope that it will be useful, 12169695Skanbut WITHOUT ANY WARRANTY; without even the implied warranty of 13169695SkanMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14169695SkanGNU General Public License for more details. 15169695Skan 16169695SkanYou should have received a copy of the GNU General Public License 17169695Skanalong with GNU CC; see the file COPYING. If not, write to 18169695Skanthe Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 19169695Skan 20169695SkanAs a special exception, if you link this library with files 21169695Skancompiled with a GNU compiler to produce an executable, this does not cause 22169695Skanthe resulting executable to be covered by the GNU General Public License. 23169695SkanThis exception does not however invalidate any other reasons why 24169695Skanthe executable file might be covered by the GNU General Public License. */ 25169695Skan 26169695Skan/* 27169695Skan 28169695Skan@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, ...) 29169695Skan 30169695SkanThis function is similar to sprintf, but it will print at most @var{n} 31169695Skancharacters. On error the return value is -1, otherwise it returns the 32169695Skannumber of characters that would have been printed had @var{n} been 33169695Skansufficiently large, regardless of the actual value of @var{n}. Note 34169695Skansome pre-C99 system libraries do not implement this correctly so users 35169695Skancannot generally rely on the return value if the system version of 36169695Skanthis function is used. 37169695Skan 38169695Skan@end deftypefn 39169695Skan 40169695Skan*/ 41169695Skan 42169695Skan#include "ansidecl.h" 43169695Skan 44169695Skan#include <stdarg.h> 45169695Skan#include <stddef.h> 46169695Skan 47169695Skanint vsnprintf (char *, size_t, const char *, va_list); 48169695Skan 49169695Skanint 50169695Skansnprintf (char *s, size_t n, const char *format, ...) 51169695Skan{ 52169695Skan int result; 53169695Skan VA_OPEN (ap, format); 54169695Skan VA_FIXEDARG (ap, char *, s); 55169695Skan VA_FIXEDARG (ap, size_t, n); 56169695Skan VA_FIXEDARG (ap, const char *, format); 57169695Skan result = vsnprintf (s, n, format, ap); 58169695Skan VA_CLOSE (ap); 59169695Skan return result; 60169695Skan} 61