vdprintf.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "_stdio.h"
  8. #include <stdarg.h>
  9. int attribute_hidden __vdprintf(int filedes, const char * __restrict format, va_list arg)
  10. {
  11. FILE f;
  12. int rv;
  13. #ifdef __STDIO_BUFFERS
  14. char buf[64]; /* TODO: provide _optional_ buffering? */
  15. f.__bufend = buf + sizeof(buf);
  16. f.__bufstart = buf;
  17. __STDIO_STREAM_DISABLE_GETC(&f);
  18. __STDIO_STREAM_DISABLE_PUTC(&f);
  19. __STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
  20. #endif
  21. /* __STDIO_STREAM_RESET_GCS(&f); */
  22. #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
  23. f.__cookie = &(f.__filedes);
  24. f.__gcs.read = NULL;
  25. f.__gcs.write = _cs_write;
  26. f.__gcs.seek = NULL;
  27. f.__gcs.close = NULL;
  28. #endif
  29. f.__filedes = filedes;
  30. f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
  31. #ifdef __UCLIBC_HAS_WCHAR__
  32. f.__ungot_width[0] = 0;
  33. #endif /* __UCLIBC_HAS_WCHAR__ */
  34. #ifdef __STDIO_MBSTATE
  35. __INIT_MBSTATE(&(f.__state));
  36. #endif /* __STDIO_MBSTATE */
  37. #ifdef __UCLIBC_HAS_THREADS__
  38. f.__user_locking = 1; /* Set user locking. */
  39. __stdio_init_mutex(&f.__lock);
  40. #endif
  41. f.__nextopen = NULL;
  42. rv = __vfprintf(&f, format, arg);
  43. #ifdef __STDIO_BUFFERS
  44. /* If not buffering, then fflush is unnecessary. */
  45. if ((rv > 0) && __fflush_unlocked(&f)) {
  46. rv = -1;
  47. }
  48. #endif
  49. assert(rv >= -1);
  50. return rv;
  51. }
  52. strong_alias(__vdprintf,vdprintf)