]> pd.if.org Git - pdclib.old/blob - functions/stdio/fprintf.c
421ca5273f8e153f763c12b0b4399e1f008c1b2a
[pdclib.old] / functions / stdio / fprintf.c
1 /* $Id$ */
2
3 /* fprintf( FILE *, const char *, ... )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdio.h>
10 #include <stdarg.h>
11
12 #ifndef REGTEST
13
14 int fprintf_unlocked( struct _PDCLIB_file_t * _PDCLIB_restrict stream, 
15                       const char * _PDCLIB_restrict format, ... )
16 {
17     int rc;
18     va_list ap;
19     va_start( ap, format );
20     rc = vfprintf( stream, format, ap );
21     va_end( ap );
22     return rc;
23 }
24
25 int fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream,
26              const char * _PDCLIB_restrict format, ... )
27 {
28     int rc;
29     va_list ap;
30     va_start( ap, format );
31     flockfile( stream );
32     rc = vfprintf_unlocked( stream, format, ap );
33     funlockfile( stream );
34     va_end( ap );
35     return rc;
36 }
37
38 #endif
39
40 #ifdef TEST
41 #define _PDCLIB_FILEID "stdio/fprintf.c"
42 #define _PDCLIB_FILEIO
43
44 #include <_PDCLIB_test.h>
45
46 #define testprintf( stream, ... ) fprintf( stream, __VA_ARGS__ )
47
48 int main( void )
49 {
50     FILE * target;
51     TESTCASE( ( target = tmpfile() ) != NULL );
52 #include "printf_testcases.h"
53     TESTCASE( fclose( target ) == 0 );
54     return TEST_RESULTS;
55 }
56
57 #endif
58