root/libglibc/snprintf.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. snprintf

   1 /* Copyright (C) 1991, 1995, 1997, 1998 Free Software Foundation, Inc.
   2    This file is part of the GNU C Library.
   3 
   4    The GNU C Library is free software; you can redistribute it and/or
   5    modify it under the terms of the GNU Library General Public License as
   6    published by the Free Software Foundation; either version 2 of the
   7    License, or (at your option) any later version.
   8 
   9    The GNU C Library is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12    Library General Public License for more details.
  13 
  14    You should have received a copy of the GNU Library General Public
  15    License along with the GNU C Library; see the file COPYING.LIB.  If not,
  16    write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  17    Boston, MA  02110-1301  USA. */
  18 
  19 #ifdef HAVE_CONFIG_H
  20 #include <config.h>
  21 #endif
  22 #include <stdarg.h>
  23 #include <stdio.h>
  24 
  25 /*
  26  * drived from GNU C Library and modified at 2001/10/09.
  27  *
  28  * This is the simplest version of snprintf, that is, it just exits after
  29  * writing over MAXLEN characters. It is used in the system which doesn't
  30  * have snprintf(3).
  31  */
  32 
  33 #ifndef HAVE_SNPRINTF
  34 /* Write formatted output into S, according to the format
  35    string FORMAT, writing no more than MAXLEN characters.  */
  36 /* VARARGS3 */
  37 int
  38 snprintf (char *s, size_t maxlen, const char *format, ...)
  39 {
  40   va_list arg;
  41   int done;
  42 
  43   va_start (arg, format);
  44 /*  done = __vsnprintf (s, maxlen, format, arg); */
  45   done = vsprintf (s, format, arg);
  46   if (done >= maxlen) {
  47     fprintf(stderr, "This program exit because vsprintf(3) destroy memory.\n");
  48     fprintf(stderr, "You should install snprintf(3) instead.\n");
  49     exit(1);
  50   }
  51   va_end (arg);
  52 
  53   return done;
  54 }
  55 #endif /* HAVE_SNPRINTF */

/* [previous][next][first][last][top][bottom][index][help] */