]> pd.if.org Git - pdclib/blob - functions/stdio/vfprintf.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / stdio / vfprintf.c
1 /* vfprintf( FILE *, const char *, va_list )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <stdio.h>
8 #include <stdarg.h>
9 #include <stdint.h>
10 #include <limits.h>
11
12 #ifndef REGTEST
13 #include "_PDCLIB_io.h"
14
15 static size_t filecb(void *p, const char *buf, size_t size)
16 {
17     return _PDCLIB_fwrite_unlocked( buf, 1, size, (FILE*) p );
18 }
19
20 int _PDCLIB_vfprintf_unlocked( FILE * _PDCLIB_restrict stream,
21                        const char * _PDCLIB_restrict format,
22                        va_list arg )
23 {
24     return _vcbprintf(stream, filecb, format, arg);
25 }
26
27 int vfprintf( FILE * _PDCLIB_restrict stream,
28               const char * _PDCLIB_restrict format,
29               va_list arg )
30 {
31     _PDCLIB_flockfile( stream );
32     int r = _PDCLIB_vfprintf_unlocked( stream, format, arg );
33     _PDCLIB_funlockfile( stream );
34     return r;
35 }
36
37 #endif
38
39 #ifdef TEST
40 #define _PDCLIB_FILEID "stdio/vfprintf.c"
41 #define _PDCLIB_FILEIO
42 #include <stddef.h>
43 #include "_PDCLIB_test.h"
44
45 static int testprintf( FILE * stream, const char * format, ... )
46 {
47     int i;
48     va_list arg;
49     va_start( arg, format );
50     i = vfprintf( stream, format, arg );
51     va_end( arg );
52     return i;
53 }
54
55 int main( void )
56 {
57     FILE * target;
58     TESTCASE( ( target = tmpfile() ) != NULL );
59 #include "printf_testcases.h"
60     TESTCASE( fclose( target ) == 0 );
61     return TEST_RESULTS;
62 }
63
64 #endif