slprintf.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. Unix SMB/Netbios implementation.
  3. Version 1.9.
  4. snprintf replacement
  5. Copyright (C) Andrew Tridgell 1998
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. */
  18. #include "includes.h"
  19. extern int DEBUGLEVEL;
  20. /* this is like vsnprintf but the 'n' limit does not include
  21. the terminating null. So if you have a 1024 byte buffer then
  22. pass 1023 for n */
  23. int vslprintf(char *str, int n, const char *format, va_list ap)
  24. {
  25. int ret = vsnprintf(str, n, format, ap);
  26. if (ret > n || ret < 0) {
  27. str[n] = 0;
  28. return -1;
  29. }
  30. str[ret] = 0;
  31. return ret;
  32. }
  33. #ifdef HAVE_STDARG_H
  34. int slprintf(char *str, int n, const char *format, ...)
  35. {
  36. #else
  37. int slprintf(va_alist)
  38. va_dcl
  39. {
  40. char *str, *format;
  41. int n;
  42. #endif
  43. va_list ap;
  44. int ret;
  45. #ifdef HAVE_STDARG_H
  46. va_start(ap, format);
  47. #else
  48. va_start(ap);
  49. str = va_arg(ap,char *);
  50. n = va_arg(ap,int);
  51. format = va_arg(ap,char *);
  52. #endif
  53. ret = vslprintf(str,n,format,ap);
  54. va_end(ap);
  55. return ret;
  56. }