Browse code

drop internal snprintf implementation

git-svn: trunk@3518

Tomasz Kojm authored on 2008/01/22 02:38:42
Showing 8 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Jan 21 18:16:53 CET 2008 (tk)
2
+---------------------------------
3
+  * configure,libclamav: drop internal snprintf implementation
4
+
1 5
 Mon Jan 21 18:09:47 CET 2008 (tk)
2 6
 ---------------------------------
3 7
   * libclamunrar_iface/unrar_iface.h: add missing #pragma pack direct.  (bb#769)
... ...
@@ -3,9 +3,6 @@
3 3
 /* enable bind8 compatibility */
4 4
 #undef BIND_8_COMPAT
5 5
 
6
-/* Define if your snprintf is busted */
7
-#undef BROKEN_SNPRINTF
8
-
9 6
 /* "build clamd" */
10 7
 #undef BUILD_CLAMD
11 8
 
... ...
@@ -12103,73 +12103,6 @@ _ACEOF
12103 12103
 fi
12104 12104
 
12105 12105
 
12106
-if test "x$ac_cv_func_snprintf" = "xyes" ; then
12107
-        { echo "$as_me:$LINENO: checking whether snprintf correctly terminates long strings" >&5
12108
-echo $ECHO_N "checking whether snprintf correctly terminates long strings... $ECHO_C" >&6; }
12109
-        if test "$cross_compiling" = yes; then
12110
-
12111
-			{ echo "$as_me:$LINENO: result: cross-compiling, assumed ok" >&5
12112
-echo "${ECHO_T}cross-compiling, assumed ok" >&6; }
12113
-
12114
-
12115
-else
12116
-  cat >conftest.$ac_ext <<_ACEOF
12117
-/* confdefs.h.  */
12118
-_ACEOF
12119
-cat confdefs.h >>conftest.$ac_ext
12120
-cat >>conftest.$ac_ext <<_ACEOF
12121
-/* end confdefs.h.  */
12122
-
12123
-#include <stdio.h>
12124
-int main(void){char b[5];snprintf(b,5,"123456789");return(b[4]!='\0');}
12125
-
12126
-_ACEOF
12127
-rm -f conftest$ac_exeext
12128
-if { (ac_try="$ac_link"
12129
-case "(($ac_try" in
12130
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
12131
-  *) ac_try_echo=$ac_try;;
12132
-esac
12133
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
12134
-  (eval "$ac_link") 2>&5
12135
-  ac_status=$?
12136
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
12137
-  (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
12138
-  { (case "(($ac_try" in
12139
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
12140
-  *) ac_try_echo=$ac_try;;
12141
-esac
12142
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
12143
-  (eval "$ac_try") 2>&5
12144
-  ac_status=$?
12145
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
12146
-  (exit $ac_status); }; }; then
12147
-  { echo "$as_me:$LINENO: result: yes" >&5
12148
-echo "${ECHO_T}yes" >&6; }
12149
-else
12150
-  echo "$as_me: program exited with status $ac_status" >&5
12151
-echo "$as_me: failed program was:" >&5
12152
-sed 's/^/| /' conftest.$ac_ext >&5
12153
-
12154
-( exit $ac_status )
12155
-
12156
-                        { echo "$as_me:$LINENO: result: no" >&5
12157
-echo "${ECHO_T}no" >&6; }
12158
-
12159
-cat >>confdefs.h <<\_ACEOF
12160
-#define BROKEN_SNPRINTF 1
12161
-_ACEOF
12162
-
12163
-                        { echo "$as_me:$LINENO: WARNING: ****** Your snprintf() function is broken, complain to your vendor" >&5
12164
-echo "$as_me: WARNING: ****** Your snprintf() function is broken, complain to your vendor" >&2;}
12165
-
12166
-fi
12167
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
12168
-fi
12169
-
12170
-
12171
-fi
12172
-
12173 12106
 have_pthreads=no
12174 12107
 if test "${ac_cv_header_pthread_h+set}" = set; then
12175 12108
   { echo "$as_me:$LINENO: checking for pthread.h" >&5
... ...
@@ -249,26 +249,6 @@ AC_CHECK_FUNCS(poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat
249 249
 AC_FUNC_MMAP
250 250
 AC_FUNC_FSEEKO
251 251
 
252
-dnl Check for broken snprintf (code by Phil Oleson <oz*nixil.net>)
253
-if test "x$ac_cv_func_snprintf" = "xyes" ; then
254
-        AC_MSG_CHECKING([whether snprintf correctly terminates long strings])
255
-        AC_TRY_RUN(
256
-                [
257
-#include <stdio.h>
258
-int main(void){char b[5];snprintf(b,5,"123456789");return(b[4]!='\0');}
259
-                ],
260
-                [AC_MSG_RESULT(yes)],
261
-                [
262
-                        AC_MSG_RESULT(no)
263
-                        AC_DEFINE(BROKEN_SNPRINTF,1,[Define if your snprintf is busted])
264
-                        AC_MSG_WARN([****** Your snprintf() function is broken, complain to your vendor])
265
-                ],
266
-		[
267
-			AC_MSG_RESULT([cross-compiling, assumed ok])
268
-		]
269
-        )
270
-fi
271
-
272 252
 have_pthreads=no
273 253
 AC_CHECK_HEADER(pthread.h,[have_pthreads=yes],)
274 254
 
... ...
@@ -69,8 +69,6 @@ libclamav_la_SOURCES = \
69 69
 	mbox.h \
70 70
 	message.c \
71 71
 	message.h \
72
-	snprintf.c \
73
-	snprintf.h \
74 72
 	table.c \
75 73
 	table.h \
76 74
 	text.c \
... ...
@@ -79,16 +79,16 @@ LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES)
79 79
 am_libclamav_la_OBJECTS = matcher-ac.lo matcher-bm.lo matcher.lo \
80 80
 	md5.lo others.lo readdb.lo cvd.lo dsig.lo str.lo scanners.lo \
81 81
 	textdet.lo filetypes.lo rtf.lo blob.lo mbox.lo message.lo \
82
-	snprintf.lo table.lo text.lo ole2_extract.lo vba_extract.lo \
83
-	msexpand.lo pe.lo upx.lo htmlnorm.lo chmunpack.lo rebuildpe.lo \
84
-	petite.lo wwunpack.lo unsp.lo aspack.lo packlibs.lo fsg.lo \
85
-	mew.lo upack.lo line.lo untar.lo unzip.lo inflate64.lo \
86
-	special.lo binhex.lo is_tar.lo tnef.lo autoit.lo strlcpy.lo \
87
-	regcomp.lo regerror.lo regexec.lo regfree.lo unarj.lo bzlib.lo \
88
-	nulsft.lo pdf.lo spin.lo yc.lo elf.lo sis.lo uuencode.lo \
89
-	phishcheck.lo phish_domaincheck_db.lo phish_whitelist.lo \
90
-	regex_list.lo mspack.lo cab.lo entconv.lo hashtab.lo dconf.lo \
91
-	lzma_iface.lo explode.lo
82
+	table.lo text.lo ole2_extract.lo vba_extract.lo msexpand.lo \
83
+	pe.lo upx.lo htmlnorm.lo chmunpack.lo rebuildpe.lo petite.lo \
84
+	wwunpack.lo unsp.lo aspack.lo packlibs.lo fsg.lo mew.lo \
85
+	upack.lo line.lo untar.lo unzip.lo inflate64.lo special.lo \
86
+	binhex.lo is_tar.lo tnef.lo autoit.lo strlcpy.lo regcomp.lo \
87
+	regerror.lo regexec.lo regfree.lo unarj.lo bzlib.lo nulsft.lo \
88
+	pdf.lo spin.lo yc.lo elf.lo sis.lo uuencode.lo phishcheck.lo \
89
+	phish_domaincheck_db.lo phish_whitelist.lo regex_list.lo \
90
+	mspack.lo cab.lo entconv.lo hashtab.lo dconf.lo lzma_iface.lo \
91
+	explode.lo
92 92
 libclamav_la_OBJECTS = $(am_libclamav_la_OBJECTS)
93 93
 libclamav_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
94 94
 	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
... ...
@@ -293,8 +293,6 @@ libclamav_la_SOURCES = \
293 293
 	mbox.h \
294 294
 	message.c \
295 295
 	message.h \
296
-	snprintf.c \
297
-	snprintf.h \
298 296
 	table.c \
299 297
 	table.h \
300 298
 	text.c \
... ...
@@ -550,7 +548,6 @@ distclean-compile:
550 550
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rtf.Plo@am__quote@
551 551
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/scanners.Plo@am__quote@
552 552
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sis.Plo@am__quote@
553
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snprintf.Plo@am__quote@
554 553
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/special.Plo@am__quote@
555 554
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/spin.Plo@am__quote@
556 555
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str.Plo@am__quote@
557 556
deleted file mode 100644
... ...
@@ -1,658 +0,0 @@
1
-/*
2
- * Copyright Patrick Powell 1995
3
- * This code is based on code written by Patrick Powell (papowell@astart.com)
4
- * It may be used for any purpose as long as this notice remains intact
5
- * on all source code distributions
6
- */
7
-
8
-/**************************************************************
9
- * Original:
10
- * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
11
- * A bombproof version of doprnt (dopr) included.
12
- * Sigh.  This sort of thing is always nasty do deal with.  Note that
13
- * the version here does not include floating point...
14
- *
15
- * snprintf() is used instead of sprintf() as it does limit checks
16
- * for string length.  This covers a nasty loophole.
17
- *
18
- * The other functions are there to prevent NULL pointers from
19
- * causing nast effects.
20
- *
21
- * More Recently:
22
- *  Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43
23
- *  This was ugly.  It is still ugly.  I opted out of floating point
24
- *  numbers, but the formatter understands just about everything
25
- *  from the normal C string format, at least as far as I can tell from
26
- *  the Solaris 2.5 printf(3S) man page.
27
- *
28
- *  Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1
29
- *    Ok, added some minimal floating point support, which means this
30
- *    probably requires libm on most operating systems.  Don't yet
31
- *    support the exponent (e,E) and sigfig (g,G).  Also, fmtint()
32
- *    was pretty badly broken, it just wasn't being exercised in ways
33
- *    which showed it, so that's been fixed.  Also, formated the code
34
- *    to mutt conventions, and removed dead code left over from the
35
- *    original.  Also, there is now a builtin-test, just compile with:
36
- *           gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
37
- *    and run snprintf for results.
38
- * 
39
- *  Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i
40
- *    The PGP code was using unsigned hexadecimal formats. 
41
- *    Unfortunately, unsigned formats simply didn't work.
42
- *
43
- *  Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8
44
- *    The original code assumed that both snprintf() and vsnprintf() were
45
- *    missing.  Some systems only have snprintf() but not vsnprintf(), so
46
- *    the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
47
- *
48
- *  Ben Lindstrom <mouring@eviladmin.org> 09/27/00 for OpenSSH
49
- *    Welcome to the world of %lld and %qd support.  With other
50
- *    long long support.  This is needed for sftp-server to work
51
- *    right.
52
- *
53
- *  Ben Lindstrom <mouring@eviladmin.org> 02/12/01 for OpenSSH
54
- *    Removed all hint of VARARGS stuff and banished it to the void,
55
- *    and did a bit of KNF style work to make things a bit more
56
- *    acceptable.  Consider stealing from mutt or enlightenment.
57
- **************************************************************/
58
-
59
-#if HAVE_CONFIG_H
60
-#include "clamav-config.h"
61
-#endif
62
-
63
-#if defined(BROKEN_SNPRINTF)		/* For those with broken snprintf() */
64
-# undef HAVE_SNPRINTF
65
-# undef HAVE_VSNPRINTF
66
-#endif
67
-
68
-#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
69
-
70
-#include <sys/types.h>
71
-#include <stdarg.h>
72
-
73
-static void
74
-dopr(char *buffer, size_t maxlen, const char *format, va_list args);
75
-
76
-static void 
77
-fmtstr(char *buffer, size_t *currlen, size_t maxlen, char *value, int flags, 
78
-    int min, int max);
79
-
80
-static void 
81
-fmtint(char *buffer, size_t *currlen, size_t maxlen, long value, int base, 
82
-    int min, int max, int flags);
83
-
84
-static void 
85
-fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue, 
86
-    int min, int max, int flags);
87
-
88
-static void
89
-dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
90
-
91
-/*
92
- * dopr(): poor man's version of doprintf
93
- */
94
-
95
-/* format read states */
96
-#define DP_S_DEFAULT 0
97
-#define DP_S_FLAGS   1
98
-#define DP_S_MIN     2
99
-#define DP_S_DOT     3
100
-#define DP_S_MAX     4
101
-#define DP_S_MOD     5
102
-#define DP_S_CONV    6
103
-#define DP_S_DONE    7
104
-
105
-/* format flags - Bits */
106
-#define DP_F_MINUS 	(1 << 0)
107
-#define DP_F_PLUS  	(1 << 1)
108
-#define DP_F_SPACE 	(1 << 2)
109
-#define DP_F_NUM   	(1 << 3)
110
-#define DP_F_ZERO  	(1 << 4)
111
-#define DP_F_UP    	(1 << 5)
112
-#define DP_F_UNSIGNED 	(1 << 6)
113
-
114
-/* Conversion Flags */
115
-#define DP_C_SHORT     1
116
-#define DP_C_LONG      2
117
-#define DP_C_LDOUBLE   3
118
-#define DP_C_LONG_LONG 4
119
-
120
-#define char_to_int(p) (p - '0')
121
-#define abs_val(p) (p < 0 ? -p : p)
122
-
123
-#ifndef MAX
124
-#define MAX(a,b) ((a > b) ? a : b)
125
-#endif
126
-
127
-static void 
128
-dopr(char *buffer, size_t maxlen, const char *format, va_list args)
129
-{
130
-	char *strvalue, ch;
131
-	long value;
132
-	long double fvalue;
133
-	int min = 0, max = -1, state = DP_S_DEFAULT, flags = 0, cflags = 0;
134
-	size_t currlen = 0;
135
-  
136
-	ch = *format++;
137
-
138
-	while (state != DP_S_DONE) {
139
-		if ((ch == '\0') || (currlen >= maxlen)) 
140
-			state = DP_S_DONE;
141
-
142
-		switch(state) {
143
-		case DP_S_DEFAULT:
144
-			if (ch == '%') 
145
-				state = DP_S_FLAGS;
146
-			else 
147
-				dopr_outch(buffer, &currlen, maxlen, ch);
148
-			ch = *format++;
149
-			break;
150
-		case DP_S_FLAGS:
151
-			switch (ch) {
152
-			case '-':
153
-				flags |= DP_F_MINUS;
154
-				ch = *format++;
155
-				break;
156
-			case '+':
157
-				flags |= DP_F_PLUS;
158
-				ch = *format++;
159
-				break;
160
-			case ' ':
161
-				flags |= DP_F_SPACE;
162
-				ch = *format++;
163
-				break;
164
-			case '#':
165
-				flags |= DP_F_NUM;
166
-				ch = *format++;
167
-				break;
168
-			case '0':
169
-				flags |= DP_F_ZERO;
170
-				ch = *format++;
171
-				break;
172
-			default:
173
-				state = DP_S_MIN;
174
-				break;
175
-			}
176
-			break;
177
-		case DP_S_MIN:
178
-			if (isdigit((unsigned char)ch)) {
179
-				min = 10 * min + char_to_int (ch);
180
-				ch = *format++;
181
-			} else if (ch == '*') {
182
-				min = va_arg (args, int);
183
-				ch = *format++;
184
-				state = DP_S_DOT;
185
-			} else 
186
-				state = DP_S_DOT;
187
-			break;
188
-		case DP_S_DOT:
189
-			if (ch == '.') {
190
-				state = DP_S_MAX;
191
-				ch = *format++;
192
-			} else 
193
-				state = DP_S_MOD;
194
-			break;
195
-		case DP_S_MAX:
196
-			if (isdigit((unsigned char)ch)) {
197
-				if (max < 0)
198
-					max = 0;
199
-				max = 10 * max + char_to_int(ch);
200
-				ch = *format++;
201
-			} else if (ch == '*') {
202
-				max = va_arg (args, int);
203
-				ch = *format++;
204
-				state = DP_S_MOD;
205
-			} else 
206
-				state = DP_S_MOD;
207
-			break;
208
-		case DP_S_MOD:
209
-			switch (ch) {
210
-			case 'h':
211
-				cflags = DP_C_SHORT;
212
-				ch = *format++;
213
-				break;
214
-			case 'l':
215
-				cflags = DP_C_LONG;
216
-				ch = *format++;
217
-				if (ch == 'l') {
218
-					cflags = DP_C_LONG_LONG;
219
-					ch = *format++;
220
-				}
221
-				break;
222
-			case 'q':
223
-				cflags = DP_C_LONG_LONG;
224
-				ch = *format++;
225
-				break;
226
-			case 'L':
227
-				cflags = DP_C_LDOUBLE;
228
-				ch = *format++;
229
-				break;
230
-			default:
231
-				break;
232
-			}
233
-			state = DP_S_CONV;
234
-			break;
235
-		case DP_S_CONV:
236
-			switch (ch) {
237
-			case 'd':
238
-			case 'i':
239
-				if (cflags == DP_C_SHORT) 
240
-					value = va_arg(args, int);
241
-				else if (cflags == DP_C_LONG)
242
-					value = va_arg(args, long int);
243
-				else if (cflags == DP_C_LONG_LONG)
244
-					value = va_arg (args, long long);
245
-				else
246
-					value = va_arg (args, int);
247
-				fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags);
248
-				break;
249
-			case 'o':
250
-				flags |= DP_F_UNSIGNED;
251
-				if (cflags == DP_C_SHORT)
252
-					value = va_arg(args, unsigned int);
253
-				else if (cflags == DP_C_LONG)
254
-					value = va_arg(args, unsigned long int);
255
-				else if (cflags == DP_C_LONG_LONG)
256
-					value = va_arg(args, unsigned long long);
257
-				else
258
-					value = va_arg(args, unsigned int);
259
-				fmtint(buffer, &currlen, maxlen, value, 8, min, max, flags);
260
-				break;
261
-			case 'u':
262
-				flags |= DP_F_UNSIGNED;
263
-				if (cflags == DP_C_SHORT)
264
-					value = va_arg(args, unsigned int);
265
-				else if (cflags == DP_C_LONG)
266
-					value = va_arg(args, unsigned long int);
267
-				else if (cflags == DP_C_LONG_LONG)
268
-					value = va_arg(args, unsigned long long);
269
-				else
270
-					value = va_arg(args, unsigned int);
271
-				fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
272
-				break;
273
-			case 'X':
274
-				flags |= DP_F_UP;
275
-			case 'x':
276
-				flags |= DP_F_UNSIGNED;
277
-				if (cflags == DP_C_SHORT)
278
-					value = va_arg(args, unsigned int);
279
-				else if (cflags == DP_C_LONG)
280
-					value = va_arg(args, unsigned long int);
281
-				else if (cflags == DP_C_LONG_LONG)
282
-					value = va_arg(args, unsigned long long);
283
-				else
284
-					value = va_arg(args, unsigned int);
285
-				fmtint(buffer, &currlen, maxlen, value, 16, min, max, flags);
286
-				break;
287
-			case 'f':
288
-				if (cflags == DP_C_LDOUBLE)
289
-					fvalue = va_arg(args, long double);
290
-				else
291
-					fvalue = va_arg(args, double);
292
-				/* um, floating point? */
293
-				fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags);
294
-				break;
295
-			case 'E':
296
-				flags |= DP_F_UP;
297
-			case 'e':
298
-				if (cflags == DP_C_LDOUBLE)
299
-					fvalue = va_arg(args, long double);
300
-				else
301
-					fvalue = va_arg(args, double);
302
-				break;
303
-			case 'G':
304
-				flags |= DP_F_UP;
305
-			case 'g':
306
-				if (cflags == DP_C_LDOUBLE)
307
-					fvalue = va_arg(args, long double);
308
-				else
309
-					fvalue = va_arg(args, double);
310
-				break;
311
-			case 'c':
312
-				dopr_outch(buffer, &currlen, maxlen, va_arg(args, int));
313
-				break;
314
-			case 's':
315
-				strvalue = va_arg(args, char *);
316
-				if (max < 0) 
317
-					max = maxlen; /* ie, no max */
318
-				fmtstr(buffer, &currlen, maxlen, strvalue, flags, min, max);
319
-				break;
320
-			case 'p':
321
-				strvalue = va_arg(args, void *);
322
-				fmtint(buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
323
-				break;
324
-			case 'n':
325
-				if (cflags == DP_C_SHORT) {
326
-					short int *num;
327
-					num = va_arg(args, short int *);
328
-					*num = currlen;
329
-				} else if (cflags == DP_C_LONG) {
330
-					long int *num;
331
-					num = va_arg(args, long int *);
332
-					*num = currlen;
333
-				} else if (cflags == DP_C_LONG_LONG) {
334
-					long long *num;
335
-					num = va_arg(args, long long *);
336
-					*num = currlen;
337
-				} else {
338
-					int *num;
339
-					num = va_arg(args, int *);
340
-					*num = currlen;
341
-				}
342
-				break;
343
-			case '%':
344
-				dopr_outch(buffer, &currlen, maxlen, ch);
345
-				break;
346
-			case 'w': /* not supported yet, treat as next char */
347
-				ch = *format++;
348
-				break;
349
-			default: /* Unknown, skip */
350
-			break;
351
-			}
352
-			ch = *format++;
353
-			state = DP_S_DEFAULT;
354
-			flags = cflags = min = 0;
355
-			max = -1;
356
-			break;
357
-		case DP_S_DONE:
358
-			break;
359
-		default: /* hmm? */
360
-			break; /* some picky compilers need this */
361
-		}
362
-	}
363
-	if (currlen < maxlen - 1) 
364
-		buffer[currlen] = '\0';
365
-	else 
366
-		buffer[maxlen - 1] = '\0';
367
-}
368
-
369
-static void
370
-fmtstr(char *buffer, size_t *currlen, size_t maxlen,
371
-    char *value, int flags, int min, int max)
372
-{
373
-	int cnt = 0, padlen, strln;     /* amount to pad */
374
-  
375
-	if (value == 0) 
376
-		value = "<NULL>";
377
-
378
-	for (strln = 0; value[strln]; ++strln); /* strlen */
379
-	padlen = min - strln;
380
-	if (padlen < 0) 
381
-		padlen = 0;
382
-	if (flags & DP_F_MINUS) 
383
-		padlen = -padlen; /* Left Justify */
384
-
385
-	while ((padlen > 0) && (cnt < max)) {
386
-		dopr_outch(buffer, currlen, maxlen, ' ');
387
-		--padlen;
388
-		++cnt;
389
-	}
390
-	while (*value && (cnt < max)) {
391
-		dopr_outch(buffer, currlen, maxlen, *value++);
392
-		++cnt;
393
-	}
394
-	while ((padlen < 0) && (cnt < max)) {
395
-		dopr_outch(buffer, currlen, maxlen, ' ');
396
-		++padlen;
397
-		++cnt;
398
-	}
399
-}
400
-
401
-/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
402
-
403
-static void 
404
-fmtint(char *buffer, size_t *currlen, size_t maxlen,
405
-    long value, int base, int min, int max, int flags)
406
-{
407
-	unsigned long uvalue;
408
-	char convert[20];
409
-	int signvalue = 0, place = 0, caps = 0;
410
-	int spadlen = 0; /* amount to space pad */
411
-	int zpadlen = 0; /* amount to zero pad */
412
-  
413
-	if (max < 0)
414
-		max = 0;
415
-
416
-	uvalue = value;
417
-
418
-	if (!(flags & DP_F_UNSIGNED)) {
419
-		if (value < 0) {
420
-			signvalue = '-';
421
-			uvalue = -value;
422
-		} else if (flags & DP_F_PLUS)  /* Do a sign (+/i) */
423
-			signvalue = '+';
424
-		else if (flags & DP_F_SPACE)
425
-			signvalue = ' ';
426
-	}
427
-  
428
-	if (flags & DP_F_UP) 
429
-		caps = 1; /* Should characters be upper case? */
430
-	do {
431
-		convert[place++] =
432
-		    (caps ? "0123456789ABCDEF" : "0123456789abcdef")
433
-		    [uvalue % (unsigned)base];
434
-		uvalue = (uvalue / (unsigned)base );
435
-	} while (uvalue && (place < 20));
436
-	if (place == 20) 
437
-		place--;
438
-	convert[place] = 0;
439
-
440
-	zpadlen = max - place;
441
-	spadlen = min - MAX(max, place) - (signvalue ? 1 : 0);
442
-	if (zpadlen < 0)
443
-		zpadlen = 0;
444
-	if (spadlen < 0)
445
-		spadlen = 0;
446
-	if (flags & DP_F_ZERO) {
447
-		zpadlen = MAX(zpadlen, spadlen);
448
-		spadlen = 0;
449
-	}
450
-	if (flags & DP_F_MINUS) 
451
-		spadlen = -spadlen; /* Left Justifty */
452
-
453
-	/* Spaces */
454
-	while (spadlen > 0) {
455
-		dopr_outch(buffer, currlen, maxlen, ' ');
456
-		--spadlen;
457
-	}
458
-
459
-	/* Sign */
460
-	if (signvalue) 
461
-		dopr_outch(buffer, currlen, maxlen, signvalue);
462
-
463
-	/* Zeros */
464
-	if (zpadlen > 0) {
465
-		while (zpadlen > 0) {
466
-			dopr_outch(buffer, currlen, maxlen, '0');
467
-			--zpadlen;
468
-		}
469
-	}
470
-
471
-	/* Digits */
472
-	while (place > 0) 
473
-		dopr_outch(buffer, currlen, maxlen, convert[--place]);
474
-  
475
-	/* Left Justified spaces */
476
-	while (spadlen < 0) {
477
-		dopr_outch (buffer, currlen, maxlen, ' ');
478
-		++spadlen;
479
-	}
480
-}
481
-
482
-static long double 
483
-pow10(int exp)
484
-{
485
-	long double result = 1;
486
-
487
-	while (exp) {
488
-		result *= 10;
489
-		exp--;
490
-	}
491
-  
492
-	return result;
493
-}
494
-
495
-static long 
496
-round(long double value)
497
-{
498
-	long intpart = value;
499
-
500
-	value -= intpart;
501
-	if (value >= 0.5)
502
-		intpart++;
503
-
504
-	return intpart;
505
-}
506
-
507
-static void 
508
-fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue, 
509
-      int min, int max, int flags)
510
-{
511
-	char iconvert[20], fconvert[20];
512
-	int signvalue = 0, iplace = 0, fplace = 0;
513
-	int padlen = 0; /* amount to pad */
514
-	int zpadlen = 0, caps = 0;
515
-	long intpart, fracpart;
516
-	long double ufvalue;
517
-  
518
-	/* 
519
-	 * AIX manpage says the default is 0, but Solaris says the default
520
-	 * is 6, and sprintf on AIX defaults to 6
521
-	 */
522
-	if (max < 0)
523
-		max = 6;
524
-
525
-	ufvalue = abs_val(fvalue);
526
-
527
-	if (fvalue < 0)
528
-		signvalue = '-';
529
-	else if (flags & DP_F_PLUS)  /* Do a sign (+/i) */
530
-		signvalue = '+';
531
-	else if (flags & DP_F_SPACE)
532
-		signvalue = ' ';
533
-
534
-	intpart = ufvalue;
535
-
536
-	/* 
537
-	 * Sorry, we only support 9 digits past the decimal because of our 
538
-	 * conversion method
539
-	 */
540
-	if (max > 9)
541
-		max = 9;
542
-
543
-	/* We "cheat" by converting the fractional part to integer by
544
-	 * multiplying by a factor of 10
545
-	 */
546
-	fracpart = round((pow10 (max)) * (ufvalue - intpart));
547
-
548
-	if (fracpart >= pow10 (max)) {
549
-		intpart++;
550
-		fracpart -= pow10 (max);
551
-	}
552
-
553
-	/* Convert integer part */
554
-	do {
555
-		iconvert[iplace++] =
556
-		    (caps ? "0123456789ABCDEF" : "0123456789abcdef")
557
-		    [intpart % 10];
558
-		intpart = (intpart / 10);
559
-	} while(intpart && (iplace < 20));
560
-	if (iplace == 20) 
561
-		iplace--;
562
-	iconvert[iplace] = 0;
563
-
564
-	/* Convert fractional part */
565
-	do {
566
-		fconvert[fplace++] =
567
-		    (caps ? "0123456789ABCDEF" : "0123456789abcdef")
568
-		    [fracpart % 10];
569
-		fracpart = (fracpart / 10);
570
-	} while(fracpart && (fplace < 20));
571
-	if (fplace == 20) 
572
-		fplace--;
573
-	fconvert[fplace] = 0;
574
-
575
-	/* -1 for decimal point, another -1 if we are printing a sign */
576
-	padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); 
577
-	zpadlen = max - fplace;
578
-	if (zpadlen < 0)
579
-		zpadlen = 0;
580
-	if (padlen < 0) 
581
-		padlen = 0;
582
-	if (flags & DP_F_MINUS) 
583
-		padlen = -padlen; /* Left Justifty */
584
-
585
-	if ((flags & DP_F_ZERO) && (padlen > 0)) {
586
-		if (signvalue) {
587
-			dopr_outch(buffer, currlen, maxlen, signvalue);
588
-			--padlen;
589
-			signvalue = 0;
590
-		}
591
-		while (padlen > 0) {
592
-			dopr_outch(buffer, currlen, maxlen, '0');
593
-			--padlen;
594
-		}
595
-	}
596
-	while (padlen > 0) {
597
-		dopr_outch(buffer, currlen, maxlen, ' ');
598
-		--padlen;
599
-	}
600
-	if (signvalue) 
601
-		dopr_outch(buffer, currlen, maxlen, signvalue);
602
-
603
-	while (iplace > 0) 
604
-		dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]);
605
-
606
-	/*
607
-	 * Decimal point.  This should probably use locale to find the 
608
-	 * correct char to print out.
609
-	 */
610
-	dopr_outch(buffer, currlen, maxlen, '.');
611
-
612
-	while (fplace > 0) 
613
-		dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]);
614
-
615
-	while (zpadlen > 0) {
616
-		dopr_outch(buffer, currlen, maxlen, '0');
617
-		--zpadlen;
618
-	}
619
-
620
-	while (padlen < 0) {
621
-		dopr_outch(buffer, currlen, maxlen, ' ');
622
-		++padlen;
623
-	}
624
-}
625
-
626
-static void 
627
-dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
628
-{
629
-	if (*currlen < maxlen)
630
-		buffer[(*currlen)++] = c;
631
-}
632
-#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
633
-
634
-#ifndef HAVE_VSNPRINTF
635
-int 
636
-vsnprintf(char *str, size_t count, const char *fmt, va_list args)
637
-{
638
-	str[0] = 0;
639
-	dopr(str, count, fmt, args);
640
-
641
-	return(strlen(str));
642
-}
643
-#endif /* !HAVE_VSNPRINTF */
644
-
645
-#ifndef HAVE_SNPRINTF
646
-int 
647
-snprintf(char *str,size_t count,const char *fmt,...)
648
-{
649
-	va_list ap;
650
-
651
-	va_start(ap, fmt);
652
-	(void) vsnprintf(str, count, fmt, ap);
653
-	va_end(ap);
654
-
655
-	return(strlen(str));
656
-}
657
-
658
-#endif /* !HAVE_SNPRINTF */
659 1
deleted file mode 100644
... ...
@@ -1,16 +0,0 @@
1
-#ifndef _SNPRINTF_H
2
-#define _SNPRINTF_H
3
-
4
-#include "clamav-config.h"
5
-
6
-#include <sys/types.h> /* For size_t */
7
-
8
-#ifndef HAVE_SNPRINTF
9
-int snprintf(char *str, size_t count, const char *fmt, ...);
10
-#endif /* !HAVE_SNPRINTF */
11
-
12
-#ifndef HAVE_VSNPRINTF
13
-int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
14
-#endif /* !HAVE_SNPRINTF */
15
-
16
-#endif /* _SNPRINTF_H */