netinet/in.h: add IPPROTO_MH
[uclibc-ng.git] / libc / stdio / vdprintf.c
blob46b8dfe399534ff6a74c6d96906385c887415bdf
1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org>
3 * GNU Library General Public License (LGPL) version 2 or later.
5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
6 */
8 #include <features.h>
10 #ifdef __USE_GNU
11 #include "_stdio.h"
12 #include <stdarg.h>
15 int vdprintf(int filedes, const char * __restrict format, va_list arg)
17 FILE f;
18 int rv;
19 #ifdef __STDIO_BUFFERS
20 char buf[64]; /* TODO: provide _optional_ buffering? */
22 f.__bufend = (unsigned char *) buf + sizeof(buf);
23 f.__bufstart = (unsigned char *) buf;
24 __STDIO_STREAM_DISABLE_GETC(&f);
25 __STDIO_STREAM_DISABLE_PUTC(&f);
26 __STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
27 #endif
29 f.__filedes = filedes;
30 f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
32 #ifdef __UCLIBC_HAS_WCHAR__
33 f.__ungot_width[0] = 0;
34 #endif
35 #ifdef __STDIO_MBSTATE
36 __INIT_MBSTATE(&(f.__state));
37 #endif
39 /* _vfprintf_internal doesn't do any locking, locking init is here
40 * only because of fflush_unlocked. TODO? */
41 #if (defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__)) && defined(__UCLIBC_HAS_THREADS__)
42 f.__user_locking = 1; /* Set user locking. */
43 STDIO_INIT_MUTEX(f.__lock);
44 #endif
45 f.__nextopen = NULL;
47 #ifdef __USE_OLD_VFPRINTF__
48 rv = vfprintf(&f, format, arg);
49 #else
50 rv = _vfprintf_internal(&f, format, arg);
51 #endif
53 #ifdef __STDIO_BUFFERS
54 /* If not buffering, then fflush is unnecessary. */
55 if ((rv > 0) && fflush_unlocked(&f)) {
56 rv = -1;
58 #endif
60 assert(rv >= -1);
62 return rv;
64 libc_hidden_def(vdprintf)
65 #endif