Subversion Repositories Kolibri OS

Rev

Rev 4872 | Rev 4921 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* Copyright 2005, 2007 Shaun Jackman
  2.  * Permission to use, copy, modify, and distribute this software
  3.  * is freely granted, provided that this notice is preserved.
  4.  */
  5.  
  6. /*
  7. FUNCTION
  8. <<dprintf>>, <<vdprintf>>---print to a file descriptor
  9.  
  10. INDEX
  11.         dprintf
  12. INDEX
  13.         _dprintf_r
  14. INDEX
  15.         vdprintf
  16. INDEX
  17.         _vdprintf_r
  18.  
  19. ANSI_SYNOPSIS
  20.         #include <stdio.h>
  21.         #include <stdarg.h>
  22.         int dprintf(int <[fd]>, const char *<[format]>, ...);
  23.         int vdprintf(int <[fd]>, const char *<[format]>, va_list <[ap]>);
  24.         int _dprintf_r(struct _reent *<[ptr]>, int <[fd]>,
  25.                         const char *<[format]>, ...);
  26.         int _vdprintf_r(struct _reent *<[ptr]>, int <[fd]>,
  27.                         const char *<[format]>, va_list <[ap]>);
  28.  
  29. DESCRIPTION
  30. <<dprintf>> and <<vdprintf>> allow printing a format, similarly to
  31. <<printf>>, but write to a file descriptor instead of to a <<FILE>>
  32. stream.
  33.  
  34. The functions <<_dprintf_r>> and <<_vdprintf_r>> are simply
  35. reentrant versions of the functions above.
  36.  
  37. RETURNS
  38. The return value and errors are exactly as for <<write>>, except that
  39. <<errno>> may also be set to <<ENOMEM>> if the heap is exhausted.
  40.  
  41. PORTABILITY
  42. This function is originally a GNU extension in glibc and is not portable.
  43.  
  44. Supporting OS subroutines required: <<sbrk>>, <<write>>.
  45. */
  46.  
  47. #include <_ansi.h>
  48. #include <reent.h>
  49. #include <stdio.h>
  50. #include <unistd.h>
  51. #include <stdarg.h>
  52. #include "local.h"
  53.  
  54. int
  55. _DEFUN(_dprintf_r, (ptr, fd, format),
  56.        struct _reent *ptr _AND
  57.        int fd _AND
  58.        const char *format _DOTS)
  59. {
  60.         va_list ap;
  61.         int n;
  62.         _REENT_SMALL_CHECK_INIT (ptr);
  63.         va_start (ap, format);
  64.         n = _vdprintf_r (ptr, fd, format, ap);
  65.         va_end (ap);
  66.         return n;
  67. }
  68.  
  69. #ifndef _REENT_ONLY
  70.  
  71. int
  72. _DEFUN(dprintf, (fd, format),
  73.        int fd _AND
  74.        const char *format _DOTS)
  75. {
  76.   va_list ap;
  77.   int n;
  78.   struct _reent *ptr = _REENT;
  79.  
  80.   _REENT_SMALL_CHECK_INIT (ptr);
  81.   va_start (ap, format);
  82.   n = _vdprintf_r (ptr, fd, format, ap);
  83.   va_end (ap);
  84.   return n;
  85. }
  86.  
  87. #endif /* ! _REENT_ONLY */
  88.