AVR-LibC  2.3.0git
Standard C library for AVR-GCC
 

AVR-LibC Documen­tation

AVR-LibC Development Pages

Main Page

User Manual

Library Refe­rence

FAQ

Example Projects

File List

Index

Loading...
Searching...
No Matches
stdio.h
Go to the documentation of this file.
1/* Copyright (c) 2002, 2005, 2007 Joerg Wunsch
2 All rights reserved.
3
4 Portions of documentation Copyright (c) 1990, 1991, 1993
5 The Regents of the University of California.
6
7 All rights reserved.
8
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in
17 the documentation and/or other materials provided with the
18 distribution.
19
20 * Neither the name of the copyright holders nor the names of
21 contributors may be used to endorse or promote products derived
22 from this software without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE. */
35
36#ifndef _STDIO_H_
37#define _STDIO_H_ 1
38
39#ifndef __ASSEMBLER__
40
41#include <inttypes.h>
42#include <stdarg.h>
43
44#ifndef __DOXYGEN__
45#define __need_NULL
46#define __need_size_t
47#include <stddef.h>
48#endif /* !__DOXYGEN__ */
49
50/** \file */
51/** \defgroup avr_stdio <stdio.h>: Standard IO facilities
52 \code #include <stdio.h> \endcode
53
54 <h3>Introduction to the Standard IO facilities</h3>
55
56 This file declares the standard IO facilities that are implemented
57 in AVR-LibC. Due to the nature of the underlying hardware,
58 only a limited subset of standard IO is implemented. There is no
59 actual file implementation available, so only device IO can be
60 performed. Since there's no operating system, the application
61 needs to provide enough details about their devices in order to
62 make them usable by the standard IO facilities.
63
64 Due to space constraints, some functionality has not been
65 implemented at all (like some of the \c printf conversions that
66 have been left out). Nevertheless, potential users of this
67 implementation should be warned: the \c printf and \c scanf families of functions, although
68 usually associated with presumably simple things like the
69 famous "Hello, world!" program, are actually fairly complex
70 which causes their inclusion to eat up a fair amount of code space.
71 Also, they are not fast due to the nature of interpreting the
72 format string at run-time. Whenever possible, resorting to the
73 (sometimes non-standard) predetermined conversion facilities that are
74 offered by AVR-LibC will usually cost much less in terms of speed
75 and code size.
76
77 <h3>Tunable options for code size vs. feature set</h3>
78
79 In order to allow programmers a code size vs. functionality tradeoff,
80 the function vfprintf() which is the heart of the printf family can be
81 selected in different flavours using linker options. See the
82 documentation of vfprintf() for a detailed description. The same
83 applies to vfscanf() and the \c scanf family of functions.
84
85 <h3>Outline of the chosen API</h3>
86
87 The standard streams \c stdin, \c stdout, and \c stderr are
88 provided, but contrary to the C standard, since AVR-LibC has no
89 knowledge about applicable devices, these streams are not already
90 pre-initialized at application startup. Also, since there is no
91 notion of "file" whatsoever to AVR-LibC, there is no function
92 \c fopen() that could be used to associate a stream to some device.
93 (See \ref stdio_note1 "note 1".) Instead, the function \c fdevopen()
94 is provided to associate a stream to a device, where the device
95 needs to provide a function to send a character, to receive a
96 character, or both. There is no differentiation between "text" and
97 "binary" streams inside AVR-LibC. Character \c \\n is sent
98 literally down to the device's \c put() function. If the device
99 requires a carriage return (\c \\r) character to be sent before
100 the linefeed, its \c put() routine must implement this (see
101 \ref stdio_note2 "note 2").
102
103 As an alternative method to fdevopen(), the macro
104 fdev_setup_stream() might be used to setup a user-supplied FILE
105 structure.
106
107 It should be noted that the automatic conversion of a newline
108 character into a carriage return - newline sequence breaks binary
109 transfers. If binary transfers are desired, no automatic
110 conversion should be performed, but instead any string that aims
111 to issue a CR-LF sequence must use <tt>"\r\n"</tt> explicitly.
112
113 For convenience, the first call to \c fdevopen() that opens a
114 stream for reading will cause the resulting stream to be aliased
115 to \c stdin. Likewise, the first call to \c fdevopen() that opens
116 a stream for writing will cause the resulting stream to be aliased
117 to both, \c stdout, and \c stderr. Thus, if the open was done
118 with both, read and write intent, all three standard streams will
119 be identical. Note that these aliases are indistinguishable from
120 each other, thus calling \c fclose() on such a stream will also
121 effectively close all of its aliases (\ref stdio_note3 "note 3").
122
123 It is possible to tie additional user data to a stream, using
124 fdev_set_udata(). The backend put and get functions can then
125 extract this user data using fdev_get_udata(), and act
126 appropriately. For example, a single put function could be used
127 to talk to two different UARTs that way, or the put and get
128 functions could keep internal state between calls there.
129
130 <h3>Format strings in flash ROM</h3>
131
132 All the \c printf and \c scanf family functions come in three flavours:
133 the standard name, where the format string is expected to be in
134 SRAM, as well as two versions with the suffix "_P" and "_F" where the
135 format string is expected to reside in the flash ROM. The macros
136 #PSTR (explained in \ref avr_pgmspace) and #FSTR (explained in
137 \ref avr_flash "<avr/flash.h>") become very handy for declaring
138 these format strings.
139
140 \anchor stdio_without_malloc
141 <h3>Running stdio without malloc()</h3>
142
143 By default, fdevopen() requires malloc(). As this is often
144 not desired in the limited environment of a microcontroller, an
145 alternative option is provided to run completely without malloc().
146
147 The macro fdev_setup_stream() is provided to prepare a
148 user-supplied FILE buffer for operation with stdio.
149
150 <h4>Example</h4>
151
152 \code
153 #include <stdio.h>
154
155 static int uart_putchar(char c, FILE *stream);
156
157 static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
158 _FDEV_SETUP_WRITE);
159
160 static int
161 uart_putchar(char c, FILE *stream)
162 {
163
164 if (c == '\n')
165 uart_putchar('\r', stream);
166 loop_until_bit_is_set(UCSRA, UDRE);
167 UDR = c;
168 return 0;
169 }
170
171 int
172 main(void)
173 {
174 init_uart();
175 stdout = &mystdout;
176 printf("Hello, world!\n");
177
178 return 0;
179 }
180 \endcode
181
182 This example uses the initializer form FDEV_SETUP_STREAM() rather
183 than the function-like fdev_setup_stream(), so all data
184 initialization happens during C start-up.
185
186 If streams initialized that way are no longer needed, they can be
187 destroyed by first calling the macro fdev_close(), and then
188 destroying the object itself. No call to fclose() should be
189 issued for these streams. While calling fclose() itself is
190 harmless, it will cause an undefined reference to free() and thus
191 cause the linker to link the malloc module into the application.
192
193 <h3>Notes</h3>
194
195<dl>
196<dt>\anchor stdio_note1 Note 1:</dt>
197<dd>
198 It might have been possible to implement a device abstraction that
199 is compatible with \c fopen() but since this would have required
200 to parse a string, and to take all the information needed either
201 out of this string, or out of an additional table that would need to be
202 provided by the application, this approach was not taken.
203</dd>
204<dt>\anchor stdio_note2 Note 2:</dt>
205<dd>
206 This basically follows the Unix approach: if a device such as a
207 terminal needs special handling, it is in the domain of the
208 terminal device driver to provide this functionality. Thus, a
209 simple function suitable as \c put() for \c fdevopen() that talks
210 to a UART interface might look like this:
211
212 \code
213 int
214 uart_putchar(char c, FILE *stream)
215 {
216
217 if (c == '\n')
218 uart_putchar('\r', stream);
219 loop_until_bit_is_set(UCSRA, UDRE);
220 UDR = c;
221 return 0;
222 }
223 \endcode
224</dd>
225<dt>\anchor stdio_note3 Note 3:</dt>
226<dd>
227 This implementation has been chosen because the cost of maintaining
228 an alias is considerably smaller than the cost of maintaining full
229 copies of each stream. Yet, providing an implementation that offers
230 the complete set of standard streams was deemed to be useful. Not
231 only that writing \c printf() instead of <tt>fprintf(mystream, ...)</tt>
232 saves typing work, but since avr-gcc needs to resort to pass all
233 arguments of variadic functions on the stack (as opposed to passing
234 them in registers for functions that take a fixed number of
235 parameters), the ability to pass one parameter less by implying
236 \c stdin or stdout will also save some execution time.
237</dd>
238</dl>
239*/
240
241#if !defined(__DOXYGEN__)
242
243/*
244 * This is an internal structure of the library that is subject to be
245 * changed without warnings at any time. Please do *never* reference
246 * elements of it beyond by using the official interfaces provided.
247 */
248struct __file {
249 char *buf; /* buffer pointer */
250 unsigned char unget; /* ungetc() buffer */
251 uint8_t flags; /* flags, see below */
252#define __SRD 0x0001 /* OK to read */
253#define __SWR 0x0002 /* OK to write */
254#define __SSTR 0x0004 /* this is an sprintf/snprintf string */
255#define __SPGM 0x0008 /* fmt string is in progmem */
256#define __SERR 0x0010 /* found error */
257#define __SEOF 0x0020 /* found EOF */
258#define __SUNGET 0x040 /* ungetc() happened */
259#define __SMALLOC 0x80 /* handle is malloc()ed */
260#if 0
261/* possible future extensions, will require uint16_t flags */
262#define __SRW 0x0100 /* open for reading & writing */
263#define __SLBF 0x0200 /* line buffered */
264#define __SNBF 0x0400 /* unbuffered */
265#define __SMBF 0x0800 /* buf is from malloc */
266#endif
267 int size; /* size of buffer */
268 int len; /* characters read or written so far */
269 int (*put)(char, struct __file *); /* function to write one char to device */
270 int (*get)(struct __file *); /* function to read one char from device */
271 void *udata; /* User defined and accessible data. */
272};
273
274#endif /* not __DOXYGEN__ */
275
276/**@{*/
277/**
278 \c FILE is the opaque structure that is passed around between the
279 various standard IO functions.
280*/
281typedef struct __file FILE;
282
283/**
284 Stream that will be used as an input stream by the simplified
285 functions that don't take a \c stream argument.
286
287 The first stream opened with read intent using \c fdevopen()
288 will be assigned to \c stdin.
289*/
290#define stdin (__iob[0])
291
292/**
293 Stream that will be used as an output stream by the simplified
294 functions that don't take a \c stream argument.
295
296 The first stream opened with write intent using \c fdevopen()
297 will be assigned to both, \c stdin, and \c stderr.
298*/
299#define stdout (__iob[1])
300
301/**
302 Stream destined for error output. Unless specifically assigned,
303 identical to \c stdout.
304
305 If \c stderr should point to another stream, the result of
306 another \c fdevopen() must be explicitly assigned to it without
307 closing the previous \c stderr (since this would also close
308 \c stdout).
309*/
310#define stderr (__iob[2])
311
312/**
313 \c EOF declares the value that is returned by various standard IO
314 functions in case of an error. Since the AVR platform (currently)
315 doesn't contain an abstraction for actual files, its origin as
316 "end of file" is somewhat meaningless here.
317*/
318#define EOF (-1)
319
320/** This macro inserts a pointer to user defined data into a FILE
321 stream object.
322
323 The user data can be useful for tracking state in the put and get
324 functions supplied to the fdevopen() function. */
325#define fdev_set_udata(stream, u) do { (stream)->udata = u; } while(0)
326
327/** This macro retrieves a pointer to user defined data from a FILE
328 stream object. */
329#define fdev_get_udata(stream) ((stream)->udata)
330
331#if defined(__DOXYGEN__)
332/**
333 \brief Setup a user-supplied buffer as an stdio stream
334
335 This macro takes a user-supplied buffer \c stream, and sets it up
336 as a stream that is valid for stdio operations, similar to one that
337 has been obtained dynamically from fdevopen(). The buffer to setup
338 must be of type #FILE.
339
340 The arguments \c put and \c get are identical to those that need to
341 be passed to fdevopen().
342
343 The \c rwflag argument can take one of the values #_FDEV_SETUP_READ,
344 #_FDEV_SETUP_WRITE, or #_FDEV_SETUP_RW, for read, write, or read/write
345 intent, respectively.
346
347 \note No assignments to the standard streams will be performed by
348 fdev_setup_stream(). If standard streams are to be used, these
349 need to be assigned by the user. See also under
350 \ref stdio_without_malloc "Running stdio without malloc()".
351 */
352#define fdev_setup_stream(stream, put, get, rwflag)
353#else /* !DOXYGEN */
354#define fdev_setup_stream(stream, p, g, f) \
355 do { \
356 (stream)->put = p; \
357 (stream)->get = g; \
358 (stream)->flags = f; \
359 (stream)->udata = 0; \
360 } while(0)
361#endif /* DOXYGEN */
362
363#define _FDEV_SETUP_READ __SRD /**< fdev_setup_stream() with read intent */
364#define _FDEV_SETUP_WRITE __SWR /**< fdev_setup_stream() with write intent */
365#define _FDEV_SETUP_RW (__SRD|__SWR) /**< fdev_setup_stream() with read/write intent */
366
367/**
368 * Return code for an error condition during device read.
369 *
370 * To be used in the get function of fdevopen().
371 */
372#define _FDEV_ERR (-1)
373
374/**
375 * Return code for an end-of-file condition during device read.
376 *
377 * To be used in the get function of fdevopen().
378 */
379#define _FDEV_EOF (-2)
380
381#if defined(__DOXYGEN__)
382/**
383 \brief Initializer for a user-supplied stdio stream
384
385 This macro acts similar to fdev_setup_stream(), but it is to be
386 used as the initializer of a variable of type FILE.
387
388 The remaining arguments are to be used as explained in
389 fdev_setup_stream().
390 */
391#define FDEV_SETUP_STREAM(put, get, rwflag)
392#else /* !DOXYGEN */
393/* In order to work with C++, we have to mention the fields in the order
394 as they appear in struct __file. Also, designated initializers are
395 only supported since C++20. */
396#define FDEV_SETUP_STREAM(PU, GE, FL) \
397 { \
398 (char*) 0 /* buf */, \
399 0u /* unget */, \
400 FL /* flags */, \
401 0 /* size */, \
402 0 /* len */, \
403 PU /* put */, \
404 GE /* get */, \
405 (void*) 0 /* udata */ \
406 }
407#endif /* DOXYGEN */
408
409#ifdef __cplusplus
410extern "C" {
411#endif
412
413#if !defined(__DOXYGEN__)
414/*
415 * Doxygen documentation can be found in fdevopen.c.
416 */
417
418extern struct __file *__iob[];
419
420#if defined(__STDIO_FDEVOPEN_COMPAT_12)
421/*
422 * Declare prototype for the discontinued version of fdevopen() that
423 * has been in use up to AVR-LibC 1.2.x. The new implementation has
424 * some backwards compatibility with the old version.
425 */
426extern FILE *fdevopen(int (*__put)(char), int (*__get)(void),
427 int __opts __attribute__((__unused__)));
428#else /* !defined(__STDIO_FDEVOPEN_COMPAT_12) */
429/* New prototype for AVR-LibC 1.4 and above. */
430extern FILE *fdevopen(int (*__put)(char, FILE*), int (*__get)(FILE*));
431#endif /* defined(__STDIO_FDEVOPEN_COMPAT_12) */
432
433#endif /* not __DOXYGEN__ */
434
435/**
436 This function closes \c stream, and disallows and further
437 IO to and from it.
438
439 When using fdevopen() to setup the stream, a call to fclose() is
440 needed in order to free the internal resources allocated.
441
442 If the stream has been set up using fdev_setup_stream() or
443 FDEV_SETUP_STREAM(), use fdev_close() instead.
444
445 It currently always returns 0 (for success).
446*/
447extern int fclose(FILE *__stream);
448
449/**
450 This macro frees up any library resources that might be associated
451 with \c stream. It should be called if \c stream is no longer
452 needed, right before the application is going to destroy the
453 \c stream object itself.
454
455 (Currently, this macro evaluates to nothing, but this might change
456 in future versions of the library.)
457*/
458#if defined(__DOXYGEN__)
459# define fdev_close()
460#else
461# define fdev_close() ((void)0)
462#endif
463
464/**
465 \c vfprintf is the central facility of the \c printf family of
466 functions. It outputs values to \c stream under control of a
467 format string passed in \c fmt. The actual values to print are
468 passed as a variable argument list \c ap.
469
470 \c vfprintf returns the number of characters written to \c stream,
471 or \c EOF in case of an error. Currently, this will only happen
472 if \c stream has not been opened with write intent.
473
474 The format string is composed of zero or more directives: ordinary
475 characters (not \c %), which are copied unchanged to the output
476 stream; and conversion specifications, each of which results in
477 fetching zero or more subsequent arguments. Each conversion
478 specification is introduced by the \c % character. The arguments must
479 properly correspond (after type promotion) with the conversion
480 specifier. After the \c %, the following appear in sequence:
481
482 - Zero or more of the following flags:
483 <ul>
484 <li> \c # The value should be converted to an "alternate form". For
485 c, d, i, s, and u conversions, this option has no effect.
486 For o conversions, the precision of the number is
487 increased to force the first character of the output
488 string to a zero (except if a zero value is printed with
489 an explicit precision of zero). For x and X conversions,
490 a non-zero result has the string `0x' (or `0X' for X
491 conversions) prepended to it.</li>
492 <li> \c 0 (zero) Zero padding. For all conversions, the converted
493 value is padded on the left with zeros rather than blanks.
494 If a precision is given with a numeric conversion (d, i,
495 o, u, i, x, and X), the 0 flag is ignored.</li>
496 <li> \c - A negative field width flag; the converted value is to be
497 left adjusted on the field boundary. The converted value
498 is padded on the right with blanks, rather than on the
499 left with blanks or zeros. A - overrides a 0 if both are
500 given.</li>
501 <li> ' ' (space) A blank should be left before a positive number
502 produced by a signed conversion (d, or i).</li>
503 <li> \c + A sign must always be placed before a number produced by a
504 signed conversion. A + overrides a space if both are
505 used.</li>
506 </ul>
507
508 - An optional decimal digit string specifying a minimum field width.
509 If the converted value has fewer characters than the field width, it
510 will be padded with spaces on the left (or right, if the left-adjustment
511 flag has been given) to fill out the field width.
512 - An optional precision, in the form of a period . followed by an
513 optional digit string. If the digit string is omitted, the
514 precision is taken as zero. This gives the minimum number of
515 digits to appear for d, i, o, u, x, and X conversions, or the
516 maximum number of characters to be printed from a string for \c s
517 conversions.
518 - An optional \c l or \c h length modifier, that specifies that the
519 argument for the d, i, o, u, x, or X conversion is a \c "long int"
520 rather than \c int. The \c h is ignored, as \c "short int" is
521 equivalent to \c int.
522 - A character that specifies the type of conversion to be applied.
523
524 The conversion specifiers and their meanings are:
525
526 - \c diouxX The int (or appropriate variant) argument is converted
527 to signed decimal (d and i), unsigned octal (o), unsigned
528 decimal (u), or unsigned hexadecimal (x and X) notation.
529 The letters "abcdef" are used for x conversions; the
530 letters "ABCDEF" are used for X conversions. The
531 precision, if any, gives the minimum number of digits that
532 must appear; if the converted value requires fewer digits,
533 it is padded on the left with zeros.
534 - \c p The <tt>void *</tt> argument is taken as an unsigned integer,
535 and converted similarly as a <tt>%\#x</tt> command would do.
536 - \c c The \c int argument is converted to an \c "unsigned char", and the
537 resulting character is written.
538 - \c s The \c "char *" argument is expected to be a pointer to an array
539 of character type (pointer to a string). Characters from
540 the array are written up to (but not including) a
541 terminating NUL character; if a precision is specified, no
542 more than the number specified are written. If a precision
543 is given, no null character need be present; if the
544 precision is not specified, or is greater than the size of
545 the array, the array must contain a terminating NUL
546 character.
547 - \c % A \c % is written. No argument is converted. The complete
548 conversion specification is "%%".
549 - \c eE The double argument is rounded and converted in the format
550 \c "[-]d.ddde±dd" where there is one digit before the
551 decimal-point character and the number of digits after it
552 is equal to the precision; if the precision is missing, it
553 is taken as 6; if the precision is zero, no decimal-point
554 character appears. An \e E conversion uses the letter \c 'E'
555 (rather than \c 'e') to introduce the exponent. The exponent
556 always contains two digits; if the value is zero,
557 the exponent is 00.
558 - \c fF The double argument is rounded and converted to decimal notation
559 in the format \c "[-]ddd.ddd", where the number of digits after the
560 decimal-point character is equal to the precision specification.
561 If the precision is missing, it is taken as 6; if the precision
562 is explicitly zero, no decimal-point character appears. If a
563 decimal point appears, at least one digit appears before it.
564 - \c gG The double argument is converted in style \c f or \c e (or
565 \c F or \c E for \c G conversions). The precision
566 specifies the number of significant digits. If the
567 precision is missing, 6 digits are given; if the precision
568 is zero, it is treated as 1. Style \c e is used if the
569 exponent from its conversion is less than -4 or greater
570 than or equal to the precision. Trailing zeros are removed
571 from the fractional part of the result; a decimal point
572 appears only if it is followed by at least one digit.
573 - \c S Similar to the \c s format, except the pointer is expected to
574 point to a program-memory (ROM) string instead of a RAM string.
575
576 In no case does a non-existent or small field width cause truncation of a
577 numeric field; if the result of a conversion is wider than the field
578 width, the field is expanded to contain the conversion result.
579
580 Since the full implementation of all the mentioned features becomes
581 fairly large, three different flavours of vfprintf() can be
582 selected using linker options. The default vfprintf() implements
583 all the mentioned functionality except floating point conversions.
584 A minimized version of vfprintf() is available that only implements
585 the very basic integer and string conversion facilities, but only
586 the \c # additional option can be specified using conversion
587 flags (these flags are parsed correctly from the format
588 specification, but then simply ignored). This version can be
589 requested using the following \ref gcc_minusW "compiler options":
590
591 \code
592 -Wl,-u,vfprintf -lprintf_min
593 \endcode
594
595 If the full functionality including the floating point conversions
596 is required, the following options should be used:
597
598 \code
599 -Wl,-u,vfprintf -lprintf_flt -lm
600 \endcode
601
602 \par Limitations:
603 - The specified width and precision can be at most 255.
604
605 \par Notes:
606 - For floating-point conversions, if you link default or minimized
607 version of vfprintf(), the symbol \c ? will be output and double
608 argument will be skipped. So you output below will not be crashed.
609 For default version the width field and the "pad to left" ( symbol
610 minus ) option will work in this case.
611 - The \c hh length modifier is ignored (\c char argument is
612 promouted to \c int). More exactly, this realization does not check
613 the number of \c h symbols.
614 - But the \c ll length modifier will to abort the output, as this
615 realization does not operate \c long \c long arguments.
616 - The variable width or precision field (an asterisk \c * symbol)
617 is not realized and will to abort the output.
618
619 */
620
621extern int vfprintf(FILE *__stream, const char *__fmt, va_list __ap);
622
623/**
624 Variant of \c vfprintf() that uses a \c fmt string that resides
625 in program memory. See also #vfprintf_F.
626*/
627extern int vfprintf_P(FILE *__stream, const char *__fmt, va_list __ap);
628
629/**
630 The function \c fputc sends the character \c c (though given as type
631 \c int) to \c stream. It returns the character, or \c EOF in case
632 an error occurred.
633*/
634extern int fputc(int __c, FILE *__stream);
635
636#if !defined(__DOXYGEN__)
637
638/* putc() function implementation, required by standard */
639extern int putc(int __c, FILE *__stream);
640
641/* putchar() function implementation, required by standard */
642extern int putchar(int __c);
643
644#endif /* not __DOXYGEN__ */
645
646/**
647 The macro \c putc used to be a "fast" macro implementation with a
648 functionality identical to fputc(). For space constraints, in
649 AVR-LibC, it is just an alias for \c fputc.
650*/
651#define putc(__c, __stream) fputc(__c, __stream)
652
653/**
654 The macro \c putchar sends character \c c to \c stdout.
655*/
656#define putchar(__c) fputc(__c, stdout)
657
658/**
659 The function \c printf performs formatted output to stream
660 \c stdout. See \c vfprintf() for details.
661*/
662extern int printf(const char *__fmt, ...);
663
664/**
665 Variant of \c printf() that uses a \c fmt string that resides
666 in program memory. See also #printf_F.
667*/
668extern int printf_P(const char *__fmt, ...);
669
670/**
671 The function \c vprintf performs formatted output to stream
672 \c stdout, taking a variable argument list as in vfprintf().
673
674 See vfprintf() for details.
675*/
676extern int vprintf(const char *__fmt, va_list __ap);
677
678/**
679 Variant of \c printf() that sends the formatted characters
680 to string \c s.
681*/
682extern int sprintf(char *__s, const char *__fmt, ...);
683
684/**
685 Variant of \c sprintf() that uses a \c fmt string that resides
686 in program memory. See also #sprintf_F.
687*/
688extern int sprintf_P(char *__s, const char *__fmt, ...);
689
690/**
691 Like \c sprintf(), but instead of assuming \c s to be of infinite
692 size, no more than \c n characters (including the trailing NUL
693 character) will be converted to \c s.
694
695 Returns the number of characters that would have been written to
696 \c s if there were enough space.
697*/
698extern int snprintf(char *__s, size_t __n, const char *__fmt, ...);
699
700/**
701 Variant of \c snprintf() that uses a \c fmt string that resides
702 in program memory. See also #snprintf_F.
703*/
704extern int snprintf_P(char *__s, size_t __n, const char *__fmt, ...);
705
706/**
707 Like \c sprintf() but takes a variable argument list for the
708 arguments.
709*/
710extern int vsprintf(char *__s, const char *__fmt, va_list __ap);
711
712/**
713 Variant of \c vsprintf() that uses a \c fmt string that resides
714 in program memory. See also #vsprintf_F.
715*/
716extern int vsprintf_P(char *__s, const char *__fmt, va_list __ap);
717
718/**
719 Like \c vsprintf(), but instead of assuming \c s to be of infinite
720 size, no more than \c n characters (including the trailing NUL
721 character) will be converted to \c s.
722
723 Returns the number of characters that would have been written to
724 \c s if there were enough space.
725*/
726extern int vsnprintf(char *__s, size_t __n, const char *__fmt, va_list __ap);
727
728/**
729 Variant of \c vsnprintf() that uses a \c fmt string that resides
730 in program memory. See also #vsnprintf_F.
731*/
732extern int vsnprintf_P(char *__s, size_t __n, const char *__fmt, va_list __ap);
733/**
734 The function \c fprintf performs formatted output to \c stream.
735 See \c vfprintf() for details.
736*/
737extern int fprintf(FILE *__stream, const char *__fmt, ...);
738
739/**
740 Variant of \c fprintf() that uses a \c fmt string that resides
741 in program memory. See also #fprintf_F.
742*/
743extern int fprintf_P(FILE *__stream, const char *__fmt, ...);
744
745/**
746 Write the string pointed to by \c str to stream \c stream.
747
748 Returns 0 on success and EOF on error.
749*/
750extern int fputs(const char *__str, FILE *__stream);
751
752/**
753 Variant of fputs() where \c str resides in program memory.
754 See also #fputs_F.
755*/
756extern int fputs_P(const char *__str, FILE *__stream);
757
758/**
759 Write the string pointed to by \c str, and a trailing newline
760 character, to \c stdout.
761*/
762extern int puts(const char *__str);
763
764/**
765 Variant of puts() where \c str resides in program memory.
766 See also #puts_F.
767*/
768extern int puts_P(const char *__str);
769
770/**
771 Write \c nmemb objects, \c size bytes each, to \c stream.
772 The first byte of the first object is referenced by \c ptr.
773
774 Returns the number of objects successfully written, i. e.
775 \c nmemb unless an output error occurred.
776 */
777extern size_t fwrite(const void *__ptr, size_t __size, size_t __nmemb,
778 FILE *__stream);
779
780/**
781 The function \c fgetc reads a character from \c stream. It returns
782 the character, or \c EOF in case end-of-file was encountered or an
783 error occurred. The routines feof() or ferror() must be used to
784 distinguish between both situations.
785*/
786extern int fgetc(FILE *__stream);
787
788#if !defined(__DOXYGEN__)
789
790/* getc() function implementation, required by standard */
791extern int getc(FILE *__stream);
792
793/* getchar() function implementation, required by standard */
794extern int getchar(void);
795
796#endif /* not __DOXYGEN__ */
797
798/**
799 The macro \c getc used to be a "fast" macro implementation with a
800 functionality identical to fgetc(). For space constraints, in
801 AVR-LibC, it is just an alias for \c fgetc.
802*/
803#define getc(__stream) fgetc(__stream)
804
805/**
806 The macro \c getchar reads a character from \c stdin. Return
807 values and error handling is identical to fgetc().
808*/
809#define getchar() fgetc(stdin)
810
811/**
812 The ungetc() function pushes the character \c c (converted to an
813 unsigned char) back onto the input stream pointed to by \c stream.
814 The pushed-back character will be returned by a subsequent read on
815 the stream.
816
817 Currently, only a single character can be pushed back onto the
818 stream.
819
820 The ungetc() function returns the character pushed back after the
821 conversion, or \c EOF if the operation fails. If the value of the
822 argument \c c character equals \c EOF, the operation will fail and
823 the stream will remain unchanged.
824*/
825extern int ungetc(int __c, FILE *__stream);
826
827/**
828 Read at most <tt>size - 1</tt> bytes from \c stream, until a
829 newline character was encountered, and store the characters in the
830 buffer pointed to by \c str. Unless an error was encountered while
831 reading, the string will then be terminated with a \c NUL
832 character.
833
834 If an error was encountered, the function returns NULL and sets the
835 error flag of \c stream, which can be tested using ferror().
836 Otherwise, a pointer to the string will be returned. */
837extern char *fgets(char *__str, int __size, FILE *__stream);
838
839/**
840 Similar to fgets() except that it will operate on stream \c stdin,
841 and the trailing newline (if any) will not be stored in the string.
842 It is the caller's responsibility to provide enough storage to hold
843 the characters read. */
844extern char *gets(char *__str);
845
846/**
847 Read \c nmemb objects, \c size bytes each, from \c stream,
848 to the buffer pointed to by \c ptr.
849
850 Returns the number of objects successfully read, i. e.
851 \c nmemb unless an input error occurred or end-of-file was
852 encountered. feof() and ferror() must be used to distinguish
853 between these two conditions.
854 */
855extern size_t fread(void *__ptr, size_t __size, size_t __nmemb,
856 FILE *__stream);
857
858/**
859 Clear the error and end-of-file flags of \c stream.
860 */
861extern void clearerr(FILE *__stream);
862
863
864/**
865 Test the end-of-file flag of \c stream. This flag can only be cleared
866 by a call to clearerr().
867 */
868extern int feof(FILE *__stream);
869
870
871/**
872 Test the error flag of \c stream. This flag can only be cleared
873 by a call to clearerr().
874 */
875extern int ferror(FILE *__stream);
876
877
878extern int vfscanf(FILE *__stream, const char *__fmt, va_list __ap);
879
880/**
881 Variant of vfscanf() using a \c fmt string in program memory.
882 See also #vfscanf_F.
883 */
884extern int vfscanf_P(FILE *__stream, const char *__fmt, va_list __ap);
885
886/**
887 The function \c fscanf performs formatted input, reading the
888 input data from \c stream.
889
890 See vfscanf() for details.
891 */
892extern int fscanf(FILE *__stream, const char *__fmt, ...);
893
894/**
895 Variant of fscanf() using a \c fmt string in program memory.
896 See also #fscanf_F.
897 */
898extern int fscanf_P(FILE *__stream, const char *__fmt, ...);
899
900/**
901 The function \c scanf performs formatted input from stream \c stdin.
902
903 See vfscanf() for details.
904 */
905extern int scanf(const char *__fmt, ...);
906
907/**
908 Variant of scanf() where \c fmt resides in program memory.
909 See also #scanf_F.
910 */
911extern int scanf_P(const char *__fmt, ...);
912
913/**
914 The function \c vscanf performs formatted input from stream
915 \c stdin, taking a variable argument list as in vfscanf().
916
917 See vfscanf() for details.
918*/
919extern int vscanf(const char *__fmt, va_list __ap);
920
921/**
922 The function \c sscanf performs formatted input, reading the
923 input data from the buffer pointed to by \c buf.
924
925 See vfscanf() for details.
926 */
927extern int sscanf(const char *__buf, const char *__fmt, ...);
928
929/**
930 Variant of sscanf() using a \c fmt string in program memory.
931 See also #sscanf_F.
932 */
933extern int sscanf_P(const char *__buf, const char *__fmt, ...);
934
935/**
936 Flush \c stream.
937
938 This is a null operation provided for source-code compatibility
939 only, as the standard IO implementation currently does not perform
940 any buffering.
941 */
942extern int fflush(FILE *stream);
943
944#ifndef __DOXYGEN__
945/* only mentioned for libstdc++ support, not implemented in library */
946#define BUFSIZ 1024
947#define _IONBF 0
948__extension__ typedef long long fpos_t;
949extern int fgetpos(FILE *stream, fpos_t *pos);
950extern FILE *fopen(const char *path, const char *mode);
951extern FILE *freopen(const char *path, const char *mode, FILE *stream);
952extern FILE *fdopen(int, const char *);
953extern int fseek(FILE *stream, long offset, int whence);
954extern int fsetpos(FILE *stream, fpos_t *pos);
955extern long ftell(FILE *stream);
956extern int fileno(FILE *);
957extern void perror(const char *s);
958extern int remove(const char *pathname);
959extern int rename(const char *oldpath, const char *newpath);
960extern void rewind(FILE *stream);
961extern void setbuf(FILE *stream, char *buf);
962extern int setvbuf(FILE *stream, char *buf, int mode, size_t size);
963extern FILE *tmpfile(void);
964extern char *tmpnam (char *s);
965#endif /* !__DOXYGEN__ */
966
967#ifdef __cplusplus
968}
969#endif
970
971/**@}*/
972
973#ifndef __DOXYGEN__
974/*
975 * The following constants are currently not used by AVR-LibC's
976 * stdio subsystem. They are defined here since the gcc build
977 * environment expects them to be here.
978 */
979#define SEEK_SET 0
980#define SEEK_CUR 1
981#define SEEK_END 2
982
983#endif
984
985#endif /* __ASSEMBLER */
986
987#endif /* _STDIO_H_ */
unsigned char uint8_t
Definition: stdint.h:81
int vprintf(const char *__fmt, va_list __ap)
Definition: vprintf.c:35
int fscanf(FILE *__stream, const char *__fmt,...)
Definition: fscanf.c:35
int fprintf(FILE *__stream, const char *__fmt,...)
Definition: fprintf.c:35
int scanf_P(const char *__fmt,...)
Definition: scanf_p.c:36
int vsprintf(char *__s, const char *__fmt, va_list __ap)
Definition: vsprintf.c:37
int vsnprintf(char *__s, size_t __n, const char *__fmt, va_list __ap)
Definition: vsnprintf.c:36
int fputs(const char *__str, FILE *__stream)
Definition: fputs.c:35
#define putc(__c, __stream)
Definition: stdio.h:651
int sprintf_P(char *__s, const char *__fmt,...)
Definition: sprintf_p.c:37
int puts(const char *__str)
Definition: puts.c:35
int fprintf_P(FILE *__stream, const char *__fmt,...)
Definition: fprintf_p.c:36
int fputs_P(const char *__str, FILE *__stream)
Definition: fputs_p.c:38
int scanf(const char *__fmt,...)
Definition: scanf.c:35
int printf_P(const char *__fmt,...)
Definition: printf_p.c:36
int feof(FILE *__stream)
Definition: feof.c:37
int printf(const char *__fmt,...)
Definition: printf.c:35
FILE * fdevopen(int(*put)(char, FILE *), int(*get)(FILE *))
Definition: fdevopen.c:84
int snprintf_P(char *__s, size_t __n, const char *__fmt,...)
Definition: snprintf_p.c:36
size_t fread(void *__ptr, size_t __size, size_t __nmemb, FILE *__stream)
Definition: fread.c:35
int sscanf(const char *__buf, const char *__fmt,...)
Definition: sscanf.c:37
int vfprintf_P(FILE *__stream, const char *__fmt, va_list __ap)
Definition: vfprintf_p.c:36
int sprintf(char *__s, const char *__fmt,...)
Definition: sprintf.c:37
#define putchar(__c)
Definition: stdio.h:656
int vfscanf(FILE *__stream, const char *__fmt, va_list __ap)
Definition: vfscanf.c:741
char * gets(char *__str)
Definition: gets.c:35
int vfscanf_P(FILE *__stream, const char *__fmt, va_list __ap)
Definition: vfscanf_p.c:36
int snprintf(char *__s, size_t __n, const char *__fmt,...)
Definition: snprintf.c:36
int fscanf_P(FILE *__stream, const char *__fmt,...)
Definition: fscanf_p.c:36
int fgetc(FILE *__stream)
Definition: fgetc.c:35
int vscanf(const char *__fmt, va_list __ap)
Definition: vscanf.c:35
int vfprintf(FILE *__stream, const char *__fmt, va_list __ap)
Definition: vfprintf.c:126
int ferror(FILE *__stream)
Definition: ferror.c:37
void clearerr(FILE *__stream)
Definition: clearerr.c:37
int puts_P(const char *__str)
Definition: puts_p.c:38
int ungetc(int __c, FILE *__stream)
Definition: ungetc.c:35
int vsprintf_P(char *__s, const char *__fmt, va_list __ap)
Definition: vsprintf_p.c:37
#define getchar()
Definition: stdio.h:809
int vsnprintf_P(char *__s, size_t __n, const char *__fmt, va_list __ap)
Definition: vsnprintf_p.c:36
#define getc(__stream)
Definition: stdio.h:803
int fclose(FILE *__stream)
Definition: fclose.c:37
int fflush(FILE *stream)
Definition: fflush.c:35
char * fgets(char *__str, int __size, FILE *__stream)
Definition: fgets.c:35
size_t fwrite(const void *__ptr, size_t __size, size_t __nmemb, FILE *__stream)
Definition: fwrite.c:35
int sscanf_P(const char *__buf, const char *__fmt,...)
Definition: sscanf_p.c:37
struct __file FILE
Definition: stdio.h:281
int fputc(int __c, FILE *__stream)
Definition: fputc.c:35