Ticket 1551: Update GPL version from 2 to 3
[midnight-commander.git] / src / vfs / smbfs / helpers / lib / slprintf.c
blob6ca11967e6d9e6e6d3c7c927bbeda44f540e97e0
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 snprintf replacement
6 Copyright (C) Andrew Tridgell 1998
8 Copyright (C) 2011
9 The Free Software Foundation, Inc.
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include "includes.h"
29 extern int DEBUGLEVEL;
32 /* this is like vsnprintf but the 'n' limit does not include
33 the terminating null. So if you have a 1024 byte buffer then
34 pass 1023 for n */
35 int vslprintf(char *str, int n, const char *format, va_list ap)
37 int ret = vsnprintf(str, n, format, ap);
38 if (ret > n || ret < 0) {
39 str[n] = 0;
40 return -1;
42 str[ret] = 0;
43 return ret;
46 #ifdef HAVE_STDARG_H
47 int slprintf(char *str, int n, const char *format, ...)
49 #else
50 int slprintf(va_alist)
51 va_dcl
53 char *str, *format;
54 int n;
55 #endif
56 va_list ap;
57 int ret;
59 #ifdef HAVE_STDARG_H
60 va_start(ap, format);
61 #else
62 va_start(ap);
63 str = va_arg(ap,char *);
64 n = va_arg(ap,int);
65 format = va_arg(ap,char *);
66 #endif
68 ret = vslprintf(str,n,format,ap);
69 va_end(ap);
70 return ret;