make proto
[Samba/gbeck.git] / source / lib / slprintf.c
blobbe81b4aa120edf6d5a78b00e34fa07b1e70a9c7e
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 snprintf replacement
5 Copyright (C) Andrew Tridgell 1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 extern int DEBUGLEVEL;
27 /* this is like vsnprintf but the 'n' limit does not include
28 the terminating null. So if you have a 1024 byte buffer then
29 pass 1023 for n */
30 int vslprintf(char *str, int n, char *format, va_list ap)
32 int ret = vsnprintf(str, n, format, ap);
33 if (ret > n || ret < 0) {
34 str[n] = 0;
35 return -1;
37 str[ret] = 0;
38 return ret;
41 #ifdef HAVE_STDARG_H
42 int slprintf(char *str, int n, char *format, ...)
44 #else
45 int slprintf(va_alist)
46 va_dcl
48 char *str, *format;
49 int n;
50 #endif
51 va_list ap;
52 int ret;
54 #ifdef HAVE_STDARG_H
55 va_start(ap, format);
56 #else
57 va_start(ap);
58 str = va_arg(ap,char *);
59 n = va_arg(ap,int);
60 format = va_arg(ap,char *);
61 #endif
63 ret = vslprintf(str,n,format,ap);
64 va_end(ap);
65 return ret;
68 /* this is rather line fprintf, except that it works on a file descriptor
69 and is limited to one pstring of output */
70 #ifdef HAVE_STDARG_H
71 int fdprintf(int fd, char *format, ...)
73 #else
74 int fdprintf(va_alist)
75 va_dcl
77 int fd;
78 char *format;
79 #endif
80 va_list ap;
81 pstring str;
83 #ifdef HAVE_STDARG_H
84 va_start(ap, format);
85 #else
86 va_start(ap);
87 fd = va_arg(ap,int);
88 format = va_arg(ap,char *);
89 #endif
90 str[0] = 0;
92 vslprintf(str,sizeof(str),format,ap);
93 va_end(ap);
94 return write(fd, str, strlen(str));