source: trunk/libs/newlib/src/newlib/libc/stdio/dprintf.c @ 577

Last change on this file since 577 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.1 KB
Line 
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/*
7FUNCTION
8<<dprintf>>, <<vdprintf>>---print to a file descriptor
9
10INDEX
11        dprintf
12INDEX
13        _dprintf_r
14INDEX
15        vdprintf
16INDEX
17        _vdprintf_r
18
19SYNOPSIS
20        #include <stdio.h>
21        #include <stdarg.h>
22        int dprintf(int <[fd]>, const char *restrict <[format]>, ...);
23        int vdprintf(int <[fd]>, const char *restrict <[format]>,
24                        va_list <[ap]>);
25        int _dprintf_r(struct _reent *<[ptr]>, int <[fd]>,
26                        const char *restrict <[format]>, ...);
27        int _vdprintf_r(struct _reent *<[ptr]>, int <[fd]>,
28                        const char *restrict <[format]>, va_list <[ap]>);
29
30DESCRIPTION
31<<dprintf>> and <<vdprintf>> allow printing a format, similarly to
32<<printf>>, but write to a file descriptor instead of to a <<FILE>>
33stream.
34
35The functions <<_dprintf_r>> and <<_vdprintf_r>> are simply
36reentrant versions of the functions above.
37
38RETURNS
39The return value and errors are exactly as for <<write>>, except that
40<<errno>> may also be set to <<ENOMEM>> if the heap is exhausted.
41
42PORTABILITY
43This function is originally a GNU extension in glibc and is not portable.
44
45Supporting OS subroutines required: <<sbrk>>, <<write>>.
46*/
47
48#include <_ansi.h>
49#include <reent.h>
50#include <stdio.h>
51#include <unistd.h>
52#include <stdarg.h>
53#include "local.h"
54
55int
56_dprintf_r (struct _reent *ptr,
57       int fd,
58       const char *__restrict format, ...)
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#ifdef _NANO_FORMATTED_IO
70int
71_diprintf_r (struct _reent *, int, const char *, ...)
72       _ATTRIBUTE ((__alias__("_dprintf_r")));
73#endif
74
75#ifndef _REENT_ONLY
76
77int
78dprintf (int fd,
79       const char *__restrict format, ...)
80{
81  va_list ap;
82  int n;
83  struct _reent *ptr = _REENT;
84
85  _REENT_SMALL_CHECK_INIT (ptr);
86  va_start (ap, format);
87  n = _vdprintf_r (ptr, fd, format, ap);
88  va_end (ap);
89  return n;
90}
91
92#ifdef _NANO_FORMATTED_IO
93int
94diprintf (int, const char *, ...)
95       _ATTRIBUTE ((__alias__("dprintf")));
96#endif
97#endif /* ! _REENT_ONLY */
Note: See TracBrowser for help on using the repository browser.