File: vslprintf.c

package info (click to toggle)
jitterbug 1.6.2-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 572 kB
  • ctags: 403
  • sloc: ansic: 4,965; sh: 1,376; perl: 122; makefile: 49; awk: 38
file content (59 lines) | stat: -rw-r--r-- 1,594 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* 
   The JitterBug bug tracking system
   a simple vslprintf for systems that don't have vsnprintf

   Copyright (C) Andrew Tridgell 1997

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "jitterbug.h"

#ifndef HAVE_VSNPRINTF
static FILE *nullf;
#endif

/* slprintf() and vslprintf() are much like snprintf() and vsnprintf() except that:

   1) they _always_ null terminate
   2) they work on systems that don't have vsnprintf
   3) attempts to write more than n characters (including the null) produce a fatal error
*/

int vslprintf(char *str, int n, char *format, va_list ap)
{
	int ret;

	ret = vsnprintf(str, n, format, ap);
	if (ret > n || ret < 0) {
		str[n] = 0;
		fatal("string overflow with format [%20.20s]", format);
	}
	str[ret] = 0;
	return ret;
}


int slprintf(char *str, int n, char *format, ...)
{
	va_list ap;  
	int ret;

	va_start(ap, format);
	ret = vslprintf(str,n,format,ap);
	va_end(ap);
	return ret;
}