home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / db / clib / snprintf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-02  |  783 b   |  58 lines

  1. #include <sys/types.h>
  2.  
  3. /*
  4. #include <sys/cdefs.h>
  5.  
  6. #include <compat.h>
  7. */
  8.  
  9. #ifdef __STDC__
  10. #include <stdarg.h>
  11. #else
  12. #include <varargs.h>
  13. #endif
  14.  
  15. int
  16. #ifdef __STDC__
  17. snprintf(char *str, size_t n, const char *fmt, ...)
  18. #else
  19. snprintf(str, n, fmt, va_alist)
  20.     char *str;
  21.     size_t n;
  22.     const char *fmt;
  23.     va_dcl
  24. #endif
  25. {
  26.     va_list ap;
  27.     char *rp;
  28.     int rval;
  29. #ifdef __STDC__
  30.     va_start(ap, fmt);
  31. #else
  32.     va_start(ap);
  33. #endif
  34. #ifdef VSPRINTF_CHARSTAR
  35.     rp = vsprintf(str, fmt, ap);
  36.     va_end(ap);
  37.     return (strlen(rp));
  38. #else
  39.     rval = vsprintf(str, fmt, ap);
  40.     va_end(ap);
  41.     return (rval);
  42. #endif
  43. }
  44.  
  45. int
  46. vsnprintf(str, n, fmt, ap)
  47.     char *str;
  48.     size_t n;
  49.     const char *fmt;
  50.     va_list ap;
  51. {
  52. #ifdef VSPRINTF_CHARSTAR
  53.     return (strlen(vsprintf(str, fmt, ap)));
  54. #else
  55.     return (vsprintf(str, fmt, ap));
  56. #endif
  57. }
  58.