home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / snprintf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  1.8 KB  |  96 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: snprintf.c,v 1.1 1996/12/11 14:27:09 aros Exp $
  4.  
  5.     Desc: ANSI C function snprintf()
  6.     Lang: english
  7. */
  8.  
  9. /*****************************************************************************
  10.  
  11.     NAME */
  12. #include <stdio.h>
  13.  
  14.     int snprintf (
  15.  
  16. /*  SYNOPSIS */
  17.     char       * str,
  18.     size_t         n,
  19.     const char * format,
  20.     ...)
  21.  
  22. /*  FUNCTION
  23.     Formats a list of arguments and writes them into the string str.
  24.  
  25.     INPUTS
  26.     str - The formatted string is written into this variable. You
  27.         must make sure that it is large enough to contain the
  28.         result.
  29.     n - At most n characters are written into the string. This
  30.         includes the final 0.
  31.     format - Format string as described above
  32.     ... - Arguments for the format string
  33.  
  34.     RESULT
  35.     The number of characters written into the string. If this is
  36.     -1, then there was not enough room. The 0 byte at the end is not
  37.     included.
  38.  
  39.     NOTES
  40.  
  41.     EXAMPLE
  42.  
  43.     BUGS
  44.  
  45.     SEE ALSO
  46.     fprintf(), vprintf(), vfprintf(), snprintf(), vsprintf(),
  47.     vnsprintf()
  48.  
  49.     INTERNALS
  50.  
  51.     HISTORY
  52.     11.12.1996 digulla created
  53.  
  54. ******************************************************************************/
  55. {
  56.     int     retval;
  57.     va_list args;
  58.  
  59.     va_start (args, format);
  60.  
  61.     retval = vsnprintf (str, n, format, args);
  62.  
  63.     va_end (args);
  64.  
  65.     return retval;
  66. } /* snprintf */
  67.  
  68. #ifdef TEST
  69. #include <stdio.h>
  70.  
  71. int main (int argc, char ** argv)
  72. {
  73.     char buffer[11];
  74.     int  rc;
  75.  
  76.     printf ("snprintf test\n");
  77.  
  78.     rc = snprintf (buffer, sizeof (buffer), "%10d", 5);
  79.  
  80.     if (rc < sizeof (buffer))
  81.     printf ("rc=%d, buffer=\"%s\"\n", rc, buffer);
  82.     else
  83.     printf ("rc=%d\n", rc);
  84.  
  85.     rc = snprintf (buffer, sizeof (buffer), "%11d", 5);
  86.  
  87.     if (rc < sizeof (buffer))
  88.     printf ("rc=%d, buffer=\"%s\"\n", rc, buffer);
  89.     else
  90.     printf ("rc=%d\n", rc);
  91.  
  92.     return 0;
  93. } /* main */
  94.  
  95. #endif /* TEST */
  96.