sprintf.c
Upload User: qaz666999
Upload Date: 2022-08-06
Package Size: 2570k
Code Size: 1k
Category:

Algorithm

Development Platform:

Unix_Linux

  1. /* gmp_sprintf -- formatted output to an unrestricted string.
  2. Copyright 2001 Free Software Foundation, Inc.
  3. This file is part of the GNU MP Library.
  4. The GNU MP Library is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or (at your
  7. option) any later version.
  8. The GNU MP Library is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
  14. #include "config.h"
  15. #if HAVE_STDARG
  16. #include <stdarg.h>
  17. #else
  18. #include <varargs.h>
  19. #endif
  20. #include <string.h>    /* for strlen */
  21. #include "gmp.h"
  22. #include "gmp-impl.h"
  23. int
  24. #if HAVE_STDARG
  25. gmp_sprintf (char *buf, const char *fmt, ...)
  26. #else
  27. gmp_sprintf (va_alist)
  28.      va_dcl
  29. #endif
  30. {
  31. #if WANT_ASSERT
  32.   int      fmtlen = strlen(fmt);
  33. #endif
  34.   va_list  ap;
  35.   int      ret;
  36. #if HAVE_STDARG
  37.   va_start (ap, fmt);
  38. #else
  39.   char       *buf;
  40.   const char *fmt;
  41.   va_start (ap);
  42.   buf = va_arg (ap, char *);
  43.   fmt = va_arg (ap, const char *);
  44. #endif
  45.   ret = __gmp_doprnt (&__gmp_sprintf_funs, &buf, fmt, ap);
  46.   va_end (ap);
  47.   ASSERT (! MEM_OVERLAP_P (buf, strlen(buf)+1, fmt, fmtlen+1));
  48.   return ret;
  49. }