OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / stdio / vdprintf.c
1 /* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
2  *
3  * GNU Library General Public License (LGPL) version 2 or later.
4  *
5  * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
6  */
7
8 #include "_stdio.h"
9 #include <stdarg.h>
10
11 libc_hidden_proto(vfprintf)
12 libc_hidden_proto(fflush_unlocked)
13
14 int vdprintf(int filedes, const char * __restrict format, va_list arg)
15 {
16         FILE f;
17         int rv;
18 #ifdef __STDIO_BUFFERS
19         char buf[64];                           /* TODO: provide _optional_ buffering? */
20
21         f.__bufend = buf + sizeof(buf);
22         f.__bufstart = buf;
23         __STDIO_STREAM_DISABLE_GETC(&f);
24         __STDIO_STREAM_DISABLE_PUTC(&f);
25         __STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
26 #endif
27
28 /*      __STDIO_STREAM_RESET_GCS(&f); */
29 #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
30         f.__cookie = &(f.__filedes);
31         f.__gcs.read = NULL;
32         f.__gcs.write = _cs_write;
33         f.__gcs.seek = NULL;
34         f.__gcs.close = NULL;
35 #endif
36
37         f.__filedes = filedes;
38         f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
39
40 #ifdef __UCLIBC_HAS_WCHAR__
41         f.__ungot_width[0] = 0;
42 #endif /* __UCLIBC_HAS_WCHAR__ */
43 #ifdef __STDIO_MBSTATE
44         __INIT_MBSTATE(&(f.__state));
45 #endif /* __STDIO_MBSTATE */
46
47 #ifdef __UCLIBC_HAS_THREADS__
48         f.__user_locking = 1;           /* Set user locking. */
49         __stdio_init_mutex(&f.__lock);
50 #endif
51         f.__nextopen = NULL;
52
53         rv = vfprintf(&f, format, arg);
54
55 #ifdef __STDIO_BUFFERS
56         /* If not buffering, then fflush is unnecessary. */
57         if ((rv > 0) && fflush_unlocked(&f)) {
58                 rv = -1;
59         }
60 #endif
61
62         assert(rv >= -1);
63
64         return rv;
65 }
66 libc_hidden_proto(vdprintf)
67 libc_hidden_def(vdprintf)