AVR Libc Home Page AVRs AVR Libc Development Pages
Main Page User Manual Reference FAQ Example Projects

stdio.h

Go to the documentation of this file.
01	1 Copyright (c) 2002, 2005, 2007 Joerg Wunsch
022All rights reserved. 033 044Portions of documentation Copyright (c) 1990, 1991, 1993 055The Regents of the University of California. 066 077All rights reserved. 088 099Redistribution and use in source and binary forms, with or without 1010modification, are permitted provided that the following conditions are met: 1111 1212* Redistributions of source code must retain the above copyright 1313notice, this list of conditions and the following disclaimer. 1414 1515* Redistributions in binary form must reproduce the above copyright 1616notice, this list of conditions and the following disclaimer in 1717the documentation and/or other materials provided with the 1818distribution. 1919 2020* Neither the name of the copyright holders nor the names of 2121contributors may be used to endorse or promote products derived 2222from this software without specific prior written permission. 2323 2424THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2525AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2626IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2727ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2828LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2929CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3030SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3131INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3232CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3333ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3434POSSIBILITY OF SUCH DAMAGE. 3535 3636$Id: stdio.h 2503 2016-02-07 22:59:47Z joerg_wunsch $ 3737*/ 3838 3939#ifndef _STDIO_H_ 4040#define _STDIO_H_ 1 4141 4242#ifndef __ASSEMBLER__ 4343 4444#include <inttypes.h> 4545#include <stdarg.h> 4646 4747#ifndef __DOXYGEN__ 4848#define __need_NULL 4949#define __need_size_t 5050#include <stddef.h> 5151#endif /* !__DOXYGEN__ */ 5252 5353/** \file */ 5454/** \defgroup avr_stdio <stdio.h>: Standard IO facilities 5555\code #include <stdio.h> \endcode 5656 5757<h3>Introduction to the Standard IO facilities</h3> 5858 5959This file declares the standard IO facilities that are implemented 6060in \c avr-libc. Due to the nature of the underlying hardware, 6161only a limited subset of standard IO is implemented. There is no 6262actual file implementation available, so only device IO can be 6363performed. Since there's no operating system, the application 6464needs to provide enough details about their devices in order to 6565make them usable by the standard IO facilities. 6666 6767Due to space constraints, some functionality has not been 6868implemented at all (like some of the \c printf conversions that 6969have been left out). Nevertheless, potential users of this 7070implementation should be warned: the \c printf and \c scanf families of functions, although 7171usually associated with presumably simple things like the 7272famous "Hello, world!" program, are actually fairly complex 7373which causes their inclusion to eat up a fair amount of code space. 7474Also, they are not fast due to the nature of interpreting the 7575format string at run-time. Whenever possible, resorting to the 7676(sometimes non-standard) predetermined conversion facilities that are 7777offered by avr-libc will usually cost much less in terms of speed 7878and code size. 7979 8080<h3>Tunable options for code size vs. feature set</h3> 8181 8282In order to allow programmers a code size vs. functionality tradeoff, 8383the function vfprintf() which is the heart of the printf family can be 8484selected in different flavours using linker options. See the 8585documentation of vfprintf() for a detailed description. The same 8686applies to vfscanf() and the \c scanf family of functions. 8787 8888<h3>Outline of the chosen API</h3> 8989 9090The standard streams \c stdin, \c stdout, and \c stderr are 9191provided, but contrary to the C standard, since avr-libc has no 9292knowledge about applicable devices, these streams are not already 9393pre-initialized at application startup. Also, since there is no 9494notion of "file" whatsoever to avr-libc, there is no function 9595\c fopen() that could be used to associate a stream to some device. 9696(See \ref stdio_note1 "note 1".) Instead, the function \c fdevopen() 9797is provided to associate a stream to a device, where the device 9898needs to provide a function to send a character, to receive a 9999character, or both. There is no differentiation between "text" and 100100"binary" streams inside avr-libc. Character \c \\n is sent 101101literally down to the device's \c put() function. If the device 102102requires a carriage return (\c \\r) character to be sent before 103103the linefeed, its \c put() routine must implement this (see 104104\ref stdio_note2 "note 2"). 105105 106106As an alternative method to fdevopen(), the macro 107107fdev_setup_stream() might be used to setup a user-supplied FILE 108108structure. 109109 110110It should be noted that the automatic conversion of a newline 111111character into a carriage return - newline sequence breaks binary 112112transfers. If binary transfers are desired, no automatic 113113conversion should be performed, but instead any string that aims 114114to issue a CR-LF sequence must use <tt>"\r\n"</tt> explicitly. 115115 116116For convenience, the first call to \c fdevopen() that opens a 117117stream for reading will cause the resulting stream to be aliased 118118to \c stdin. Likewise, the first call to \c fdevopen() that opens 119119a stream for writing will cause the resulting stream to be aliased 120120to both, \c stdout, and \c stderr. Thus, if the open was done 121121with both, read and write intent, all three standard streams will 122122be identical. Note that these aliases are indistinguishable from 123123each other, thus calling \c fclose() on such a stream will also 124124effectively close all of its aliases (\ref stdio_note3 "note 3"). 125125 126126It is possible to tie additional user data to a stream, using 127127fdev_set_udata(). The backend put and get functions can then 128128extract this user data using fdev_get_udata(), and act 129129appropriately. For example, a single put function could be used 130130to talk to two different UARTs that way, or the put and get 131131functions could keep internal state between calls there. 132132 133133<h3>Format strings in flash ROM</h3> 134134 135135All the \c printf and \c scanf family functions come in two flavours: the 136136standard name, where the format string is expected to be in 137137SRAM, as well as a version with the suffix "_P" where the format 138138string is expected to reside in the flash ROM. The macro 139139\c PSTR (explained in \ref avr_pgmspace) becomes very handy 140140for declaring these format strings. 141141 142142\anchor stdio_without_malloc 143143<h3>Running stdio without malloc()</h3> 144144 145145By default, fdevopen() requires malloc(). As this is often 146146not desired in the limited environment of a microcontroller, an 147147alternative option is provided to run completely without malloc(). 148148 149149The macro fdev_setup_stream() is provided to prepare a 150150user-supplied FILE buffer for operation with stdio. 151151 152152<h4>Example</h4> 153153 154154\code 155155#include <stdio.h> 156156 157157static int uart_putchar(char c, FILE *stream); 158158 159159static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, 160160_FDEV_SETUP_WRITE); 161161 162162static int 163163uart_putchar(char c, FILE *stream) 164164{ 165165 166166if (c == '\n') 167167uart_putchar('\r', stream); 168168loop_until_bit_is_set(UCSRA, UDRE); 169169UDR = c; 170170return 0; 171171} 172172 173173int 174174main(void) 175175{ 176176init_uart(); 177177stdout = &mystdout; 178178printf("Hello, world!\n"); 179179 180180return 0; 181181} 182182\endcode 183183 184184This example uses the initializer form FDEV_SETUP_STREAM() rather 185185than the function-like fdev_setup_stream(), so all data 186186initialization happens during C start-up. 187187 188188If streams initialized that way are no longer needed, they can be 189189destroyed by first calling the macro fdev_close(), and then 190190destroying the object itself. No call to fclose() should be 191191issued for these streams. While calling fclose() itself is 192192harmless, it will cause an undefined reference to free() and thus 193193cause the linker to link the malloc module into the application. 194194 195195<h3>Notes</h3> 196196 197197\anchor stdio_note1 \par Note 1: 198198It might have been possible to implement a device abstraction that 199199is compatible with \c fopen() but since this would have required 200200to parse a string, and to take all the information needed either 201201out of this string, or out of an additional table that would need to be 202202provided by the application, this approach was not taken. 203203 204204\anchor stdio_note2 \par Note 2: 205205This basically follows the Unix approach: if a device such as a 206206terminal needs special handling, it is in the domain of the 207207terminal device driver to provide this functionality. Thus, a 208208simple function suitable as \c put() for \c fdevopen() that talks 209209to a UART interface might look like this: 210210 211211\code 212212int 213213uart_putchar(char c, FILE *stream) 214214{ 215215 216216if (c == '\n') 217217uart_putchar('\r'); 218218loop_until_bit_is_set(UCSRA, UDRE); 219219UDR = c; 220220return 0; 221221} 222222\endcode 223223 224224\anchor stdio_note3 \par Note 3: 225225This implementation has been chosen because the cost of maintaining 226226an alias is considerably smaller than the cost of maintaining full 227227copies of each stream. Yet, providing an implementation that offers 228228the complete set of standard streams was deemed to be useful. Not 229229only that writing \c printf() instead of <tt>fprintf(mystream, ...)</tt> 230230saves typing work, but since avr-gcc needs to resort to pass all 231231arguments of variadic functions on the stack (as opposed to passing 232232them in registers for functions that take a fixed number of 233233parameters), the ability to pass one parameter less by implying 234234\c stdin or stdout will also save some execution time. 235235*/ 236236 237237#if !defined(__DOXYGEN__) 238238 239239/* 240240* This is an internal structure of the library that is subject to be 241241* changed without warnings at any time. Please do *never* reference 242242* elements of it beyond by using the official interfaces provided. 243243*/ 244244struct __file { 245245char *buf; /* buffer pointer */ 246246unsigned char unget; /* ungetc() buffer */ 247247uint8_t flags; /* flags, see below */ 248248#define __SRD 0x0001 /* OK to read */ 249249#define __SWR 0x0002 /* OK to write */ 250250#define __SSTR 0x0004 /* this is an sprintf/snprintf string */ 251251#define __SPGM 0x0008 /* fmt string is in progmem */ 252252#define __SERR 0x0010 /* found error */ 253253#define __SEOF 0x0020 /* found EOF */ 254254#define __SUNGET 0x040 /* ungetc() happened */ 255255#define __SMALLOC 0x80 /* handle is malloc()ed */ 256256#if 0 257257/* possible future extensions, will require uint16_t flags */ 258258#define __SRW 0x0100 /* open for reading & writing */ 259259#define __SLBF 0x0200 /* line buffered */ 260260#define __SNBF 0x0400 /* unbuffered */ 261261#define __SMBF 0x0800 /* buf is from malloc */ 262262#endif 263263int size; /* size of buffer */ 264264int len; /* characters read or written so far */ 265265int (*put)(char, struct __file *); /* function to write one char to device */ 266266int (*get)(struct __file *); /* function to read one char from device */ 267267void *udata; /* User defined and accessible data. */ 268268}; 269269 270270#endif /* not __DOXYGEN__ */ 271271 272272/*@{*/ 273273/** 274274\c FILE is the opaque structure that is passed around between the 275275various standard IO functions. 276276*/ 277 277 typedef struct __file FILE; 278278 279279/** 280280Stream that will be used as an input stream by the simplified 281281functions that don't take a \c stream argument. 282282 283283The first stream opened with read intent using \c fdevopen() 284284will be assigned to \c stdin. 285285*/ 286 286#define stdin (__iob[0]) 287287 288288/** 289289Stream that will be used as an output stream by the simplified 290290functions that don't take a \c stream argument. 291291 292292The first stream opened with write intent using \c fdevopen() 293293will be assigned to both, \c stdin, and \c stderr. 294294*/ 295 295#define stdout (__iob[1]) 296296 297297/** 298298Stream destined for error output. Unless specifically assigned, 299299identical to \c stdout. 300300 301301If \c stderr should point to another stream, the result of 302302another \c fdevopen() must be explicitly assigned to it without 303303closing the previous \c stderr (since this would also close 304304\c stdout). 305305*/ 306 306#define stderr (__iob[2]) 307307 308308/** 309309\c EOF declares the value that is returned by various standard IO 310310functions in case of an error. Since the AVR platform (currently) 311311doesn't contain an abstraction for actual files, its origin as 312312"end of file" is somewhat meaningless here. 313313*/ 314 314#define EOF (-1) 315315 316316/** This macro inserts a pointer to user defined data into a FILE 317317stream object. 318318 319319The user data can be useful for tracking state in the put and get 320320functions supplied to the fdevopen() function. */ 321 321#define fdev_set_udata(stream, u) do { (stream)->udata = u; } while(0) 322322 323323/** This macro retrieves a pointer to user defined data from a FILE 324324stream object. */ 325 325#define fdev_get_udata(stream) ((stream)->udata) 326326 327327#if defined(__DOXYGEN__) 328328/** 329329\brief Setup a user-supplied buffer as an stdio stream 330330 331331This macro takes a user-supplied buffer \c stream, and sets it up 332332as a stream that is valid for stdio operations, similar to one that 333333has been obtained dynamically from fdevopen(). The buffer to setup 334334must be of type FILE. 335335 336336The arguments \c put and \c get are identical to those that need to 337337be passed to fdevopen(). 338338 339339The \c rwflag argument can take one of the values _FDEV_SETUP_READ, 340340_FDEV_SETUP_WRITE, or _FDEV_SETUP_RW, for read, write, or read/write 341341intent, respectively. 342342 343343\note No assignments to the standard streams will be performed by 344344fdev_setup_stream(). If standard streams are to be used, these 345345need to be assigned by the user. See also under 346346\ref stdio_without_malloc "Running stdio without malloc()". 347347*/ 348 348#define fdev_setup_stream(stream, put, get, rwflag) 349349#else /* !DOXYGEN */ 350350#define fdev_setup_stream(stream, p, g, f) \ 351351do { \ 352352(stream)->put = p; \ 353353(stream)->get = g; \ 354354(stream)->flags = f; \ 355355(stream)->udata = 0; \ 356356} while(0) 357357#endif /* DOXYGEN */ 358358 359 359#define _FDEV_SETUP_READ __SRD /**< fdev_setup_stream() with read intent */ 360 360#define _FDEV_SETUP_WRITE __SWR /**< fdev_setup_stream() with write intent */ 361 361#define _FDEV_SETUP_RW (__SRD|__SWR) /**< fdev_setup_stream() with read/write intent */ 362362 363363/** 364364* Return code for an error condition during device read. 365365* 366366* To be used in the get function of fdevopen(). 367367*/ 368 368#define _FDEV_ERR (-1) 369369 370370/** 371371* Return code for an end-of-file condition during device read. 372372* 373373* To be used in the get function of fdevopen(). 374374*/ 375 375#define _FDEV_EOF (-2) 376376 377377#if defined(__DOXYGEN__) 378378/** 379379\brief Initializer for a user-supplied stdio stream 380380 381381This macro acts similar to fdev_setup_stream(), but it is to be 382382used as the initializer of a variable of type FILE. 383383 384384The remaining arguments are to be used as explained in 385385fdev_setup_stream(). 386386*/ 387 387#define FDEV_SETUP_STREAM(put, get, rwflag) 388388#else /* !DOXYGEN */ 389389#define FDEV_SETUP_STREAM(p, g, f) \ 390390{ \ 391391.put = p, \ 392392.get = g, \ 393393.flags = f, \ 394394.udata = 0, \ 395395} 396396#endif /* DOXYGEN */ 397397 398398#ifdef __cplusplus 399399extern "C" { 400400#endif 401401 402402#if !defined(__DOXYGEN__) 403403/* 404404* Doxygen documentation can be found in fdevopen.c. 405405*/ 406406 407407extern struct __file *__iob[]; 408408 409409#if defined(__STDIO_FDEVOPEN_COMPAT_12) 410410/* 411411* Declare prototype for the discontinued version of fdevopen() that 412412* has been in use up to avr-libc 1.2.x. The new implementation has 413413* some backwards compatibility with the old version. 414414*/ 415415extern FILE *fdevopen(int (*__put)(char), int (*__get)(void), 416416int __opts __attribute__((unused))); 417417#else /* !defined(__STDIO_FDEVOPEN_COMPAT_12) */ 418418/* New prototype for avr-libc 1.4 and above. */ 419419extern FILE *fdevopen(int (*__put)(char, FILE*), int (*__get)(FILE*)); 420420#endif /* defined(__STDIO_FDEVOPEN_COMPAT_12) */ 421421 422422#endif /* not __DOXYGEN__ */ 423423 424424/** 425425This function closes \c stream, and disallows and further 426426IO to and from it. 427427 428428When using fdevopen() to setup the stream, a call to fclose() is 429429needed in order to free the internal resources allocated. 430430 431431If the stream has been set up using fdev_setup_stream() or 432432FDEV_SETUP_STREAM(), use fdev_close() instead. 433433 434434It currently always returns 0 (for success). 435435*/ 436436extern int fclose(FILE *__stream); 437437 438438/** 439439This macro frees up any library resources that might be associated 440440with \c stream. It should be called if \c stream is no longer 441441needed, right before the application is going to destroy the 442442\c stream object itself. 443443 444444(Currently, this macro evaluates to nothing, but this might change 445445in future versions of the library.) 446446*/ 447447#if defined(__DOXYGEN__) 448 448# define fdev_close() 449449#else 450450# define fdev_close() ((void)0) 451451#endif 452452 453453/** 454454\c vfprintf is the central facility of the \c printf family of 455455functions. It outputs values to \c stream under control of a 456456format string passed in \c fmt. The actual values to print are 457457passed as a variable argument list \c ap. 458458 459459\c vfprintf returns the number of characters written to \c stream, 460460or \c EOF in case of an error. Currently, this will only happen 461461if \c stream has not been opened with write intent. 462462 463463The format string is composed of zero or more directives: ordinary 464464characters (not \c %), which are copied unchanged to the output 465465stream; and conversion specifications, each of which results in 466466fetching zero or more subsequent arguments. Each conversion 467467specification is introduced by the \c % character. The arguments must 468468properly correspond (after type promotion) with the conversion 469469specifier. After the \c %, the following appear in sequence: 470470 471471- Zero or more of the following flags: 472472<ul> 473473<li> \c # The value should be converted to an "alternate form". For 474474c, d, i, s, and u conversions, this option has no effect. 475475For o conversions, the precision of the number is 476476increased to force the first character of the output 477477string to a zero (except if a zero value is printed with 478478an explicit precision of zero). For x and X conversions, 479479a non-zero result has the string `0x' (or `0X' for X 480480conversions) prepended to it.</li> 481481<li> \c 0 (zero) Zero padding. For all conversions, the converted 482482value is padded on the left with zeros rather than blanks. 483483If a precision is given with a numeric conversion (d, i, 484484o, u, i, x, and X), the 0 flag is ignored.</li> 485485<li> \c - A negative field width flag; the converted value is to be 486486left adjusted on the field boundary. The converted value 487487is padded on the right with blanks, rather than on the 488488left with blanks or zeros. A - overrides a 0 if both are 489489given.</li> 490490<li> ' ' (space) A blank should be left before a positive number 491491produced by a signed conversion (d, or i).</li> 492492<li> \c + A sign must always be placed before a number produced by a 493493signed conversion. A + overrides a space if both are 494494used.</li> 495495</ul> 496496497497- An optional decimal digit string specifying a minimum field width. 498498If the converted value has fewer characters than the field width, it 499499will be padded with spaces on the left (or right, if the left-adjustment 500500flag has been given) to fill out the field width. 501501- An optional precision, in the form of a period . followed by an 502502optional digit string. If the digit string is omitted, the 503503precision is taken as zero. This gives the minimum number of 504504digits to appear for d, i, o, u, x, and X conversions, or the 505505maximum number of characters to be printed from a string for \c s 506506conversions. 507507- An optional \c l or \c h length modifier, that specifies that the 508508argument for the d, i, o, u, x, or X conversion is a \c "long int" 509509rather than \c int. The \c h is ignored, as \c "short int" is 510510equivalent to \c int. 511511- A character that specifies the type of conversion to be applied. 512512 513513The conversion specifiers and their meanings are: 514514 515515- \c diouxX The int (or appropriate variant) argument is converted 516516to signed decimal (d and i), unsigned octal (o), unsigned 517517decimal (u), or unsigned hexadecimal (x and X) notation. 518518The letters "abcdef" are used for x conversions; the 519519letters "ABCDEF" are used for X conversions. The 520520precision, if any, gives the minimum number of digits that 521521must appear; if the converted value requires fewer digits, 522522it is padded on the left with zeros. 523523- \c p The <tt>void *</tt> argument is taken as an unsigned integer, 524524and converted similarly as a <tt>%\#x</tt> command would do. 525525- \c c The \c int argument is converted to an \c "unsigned char", and the 526526resulting character is written. 527527- \c s The \c "char *" argument is expected to be a pointer to an array 528528of character type (pointer to a string). Characters from 529529the array are written up to (but not including) a 530530terminating NUL character; if a precision is specified, no 531531more than the number specified are written. If a precision 532532is given, no null character need be present; if the 533533precision is not specified, or is greater than the size of 534534the array, the array must contain a terminating NUL 535535character. 536536- \c % A \c % is written. No argument is converted. The complete 537537conversion specification is "%%". 538538- \c eE The double argument is rounded and converted in the format 539539\c "[-]d.ddde±dd" where there is one digit before the 540540decimal-point character and the number of digits after it 541541is equal to the precision; if the precision is missing, it 542542is taken as 6; if the precision is zero, no decimal-point 543543character appears. An \e E conversion uses the letter \c 'E' 544544(rather than \c 'e') to introduce the exponent. The exponent 545545always contains two digits; if the value is zero, 546546the exponent is 00. 547547- \c fF The double argument is rounded and converted to decimal notation 548548in the format \c "[-]ddd.ddd", where the number of digits after the 549549decimal-point character is equal to the precision specification. 550550If the precision is missing, it is taken as 6; if the precision 551551is explicitly zero, no decimal-point character appears. If a 552552decimal point appears, at least one digit appears before it. 553553- \c gG The double argument is converted in style \c f or \c e (or 554554\c F or \c E for \c G conversions). The precision 555555specifies the number of significant digits. If the 556556precision is missing, 6 digits are given; if the precision 557557is zero, it is treated as 1. Style \c e is used if the 558558exponent from its conversion is less than -4 or greater 559559than or equal to the precision. Trailing zeros are removed 560560from the fractional part of the result; a decimal point 561561appears only if it is followed by at least one digit. 562562- \c S Similar to the \c s format, except the pointer is expected to 563563point to a program-memory (ROM) string instead of a RAM string. 564564 565565In no case does a non-existent or small field width cause truncation of a 566566numeric field; if the result of a conversion is wider than the field 567567width, the field is expanded to contain the conversion result. 568568 569569Since the full implementation of all the mentioned features becomes 570570fairly large, three different flavours of vfprintf() can be 571571selected using linker options. The default vfprintf() implements 572572all the mentioned functionality except floating point conversions. 573573A minimized version of vfprintf() is available that only implements 574574the very basic integer and string conversion facilities, but only 575575the \c # additional option can be specified using conversion 576576flags (these flags are parsed correctly from the format 577577specification, but then simply ignored). This version can be 578578requested using the following \ref gcc_minusW "compiler options": 579579 580580\code 581581-Wl,-u,vfprintf -lprintf_min 582582\endcode 583583 584584If the full functionality including the floating point conversions 585585is required, the following options should be used: 586586 587587\code 588588-Wl,-u,vfprintf -lprintf_flt -lm 589589\endcode 590590 591591\par Limitations: 592592- The specified width and precision can be at most 255. 593593 594594\par Notes: 595595- For floating-point conversions, if you link default or minimized 596596version of vfprintf(), the symbol \c ? will be output and double 597597argument will be skiped. So you output below will not be crashed. 598598For default version the width field and the "pad to left" ( symbol 599599minus ) option will work in this case. 600600- The \c hh length modifier is ignored (\c char argument is 601601promouted to \c int). More exactly, this realization does not check 602602the number of \c h symbols. 603603- But the \c ll length modifier will to abort the output, as this 604604realization does not operate \c long \c long arguments. 605605- The variable width or precision field (an asterisk \c * symbol) 606606is not realized and will to abort the output. 607607 608608*/ 609609 610610extern int vfprintf(FILE *__stream, const char *__fmt, va_list __ap); 611611 612612/** 613613Variant of \c vfprintf() that uses a \c fmt string that resides 614614in program memory. 615615*/ 616616extern int vfprintf_P(FILE *__stream, const char *__fmt, va_list __ap); 617617 618618/** 619619The function \c fputc sends the character \c c (though given as type 620620\c int) to \c stream. It returns the character, or \c EOF in case 621621an error occurred. 622622*/ 623623extern int fputc(int __c, FILE *__stream); 624624 625625#if !defined(__DOXYGEN__) 626626 627627/* putc() function implementation, required by standard */ 628628extern int putc(int __c, FILE *__stream); 629629 630630/* putchar() function implementation, required by standard */ 631631extern int putchar(int __c); 632632 633633#endif /* not __DOXYGEN__ */ 634634 635635/** 636636The macro \c putc used to be a "fast" macro implementation with a 637637functionality identical to fputc(). For space constraints, in 638638\c avr-libc, it is just an alias for \c fputc. 639639*/ 640 640#define putc(__c, __stream) fputc(__c, __stream) 641641 642642/** 643643The macro \c putchar sends character \c c to \c stdout. 644644*/ 645 645#define putchar(__c) fputc(__c, stdout) 646646 647647/** 648648The function \c printf performs formatted output to stream 649649\c stdout. See \c vfprintf() for details. 650650*/ 651651extern int printf(const char *__fmt, ...); 652652 653653/** 654654Variant of \c printf() that uses a \c fmt string that resides 655655in program memory. 656656*/ 657657extern int printf_P(const char *__fmt, ...); 658658 659659/** 660660The function \c vprintf performs formatted output to stream 661661\c stdout, taking a variable argument list as in vfprintf(). 662662 663663See vfprintf() for details. 664664*/ 665665extern int vprintf(const char *__fmt, va_list __ap); 666666 667667/** 668668Variant of \c printf() that sends the formatted characters 669669to string \c s. 670670*/ 671671extern int sprintf(char *__s, const char *__fmt, ...); 672672 673673/** 674674Variant of \c sprintf() that uses a \c fmt string that resides 675675in program memory. 676676*/ 677677extern int sprintf_P(char *__s, const char *__fmt, ...); 678678 679679/** 680680Like \c sprintf(), but instead of assuming \c s to be of infinite 681681size, no more than \c n characters (including the trailing NUL 682682character) will be converted to \c s. 683683 684684Returns the number of characters that would have been written to 685685\c s if there were enough space. 686686*/ 687687extern int snprintf(char *__s, size_t __n, const char *__fmt, ...); 688688 689689/** 690690Variant of \c snprintf() that uses a \c fmt string that resides 691691in program memory. 692692*/ 693693extern int snprintf_P(char *__s, size_t __n, const char *__fmt, ...); 694694 695695/** 696696Like \c sprintf() but takes a variable argument list for the 697697arguments. 698698*/ 699699extern int vsprintf(char *__s, const char *__fmt, va_list ap); 700700 701701/** 702702Variant of \c vsprintf() that uses a \c fmt string that resides 703703in program memory. 704704*/ 705705extern int vsprintf_P(char *__s, const char *__fmt, va_list ap); 706706 707707/** 708708Like \c vsprintf(), but instead of assuming \c s to be of infinite 709709size, no more than \c n characters (including the trailing NUL 710710character) will be converted to \c s. 711711 712712Returns the number of characters that would have been written to 713713\c s if there were enough space. 714714*/ 715715extern int vsnprintf(char *__s, size_t __n, const char *__fmt, va_list ap); 716716 717717/** 718718Variant of \c vsnprintf() that uses a \c fmt string that resides 719719in program memory. 720720*/ 721721extern int vsnprintf_P(char *__s, size_t __n, const char *__fmt, va_list ap); 722722/** 723723The function \c fprintf performs formatted output to \c stream. 724724See \c vfprintf() for details. 725725*/ 726726extern int fprintf(FILE *__stream, const char *__fmt, ...); 727727 728728/** 729729Variant of \c fprintf() that uses a \c fmt string that resides 730730in program memory. 731731*/ 732732extern int fprintf_P(FILE *__stream, const char *__fmt, ...); 733733 734734/** 735735Write the string pointed to by \c str to stream \c stream. 736736 737737Returns 0 on success and EOF on error. 738738*/ 739739extern int fputs(const char *__str, FILE *__stream); 740740 741741/** 742742Variant of fputs() where \c str resides in program memory. 743743*/ 744744extern int fputs_P(const char *__str, FILE *__stream); 745745 746746/** 747747Write the string pointed to by \c str, and a trailing newline 748748character, to \c stdout. 749749*/ 750750extern int puts(const char *__str); 751751 752752/** 753753Variant of puts() where \c str resides in program memory. 754754*/ 755755extern int puts_P(const char *__str); 756756 757757/** 758758Write \c nmemb objects, \c size bytes each, to \c stream. 759759The first byte of the first object is referenced by \c ptr. 760760 761761Returns the number of objects successfully written, i. e. 762762\c nmemb unless an output error occured. 763763*/ 764764extern size_t fwrite(const void *__ptr, size_t __size, size_t __nmemb, 765765FILE *__stream); 766766 767767/** 768768The function \c fgetc reads a character from \c stream. It returns 769769the character, or \c EOF in case end-of-file was encountered or an 770770error occurred. The routines feof() or ferror() must be used to 771771distinguish between both situations. 772772*/ 773773extern int fgetc(FILE *__stream); 774774 775775#if !defined(__DOXYGEN__) 776776 777777/* getc() function implementation, required by standard */ 778778extern int getc(FILE *__stream); 779779 780780/* getchar() function implementation, required by standard */ 781781extern int getchar(void); 782782 783783#endif /* not __DOXYGEN__ */ 784784 785785/** 786786The macro \c getc used to be a "fast" macro implementation with a 787787functionality identical to fgetc(). For space constraints, in 788788\c avr-libc, it is just an alias for \c fgetc. 789789*/ 790 790#define getc(__stream) fgetc(__stream) 791791 792792/** 793793The macro \c getchar reads a character from \c stdin. Return 794794values and error handling is identical to fgetc(). 795795*/ 796 796#define getchar() fgetc(stdin) 797797 798798/** 799799The ungetc() function pushes the character \c c (converted to an 800800unsigned char) back onto the input stream pointed to by \c stream. 801801The pushed-back character will be returned by a subsequent read on 802802the stream. 803803 804804Currently, only a single character can be pushed back onto the 805805stream. 806806807807The ungetc() function returns the character pushed back after the 808808conversion, or \c EOF if the operation fails. If the value of the 809809argument \c c character equals \c EOF, the operation will fail and 810810the stream will remain unchanged. 811811*/ 812812extern int ungetc(int __c, FILE *__stream); 813813 814814/** 815815Read at most <tt>size - 1</tt> bytes from \c stream, until a 816816newline character was encountered, and store the characters in the 817817buffer pointed to by \c str. Unless an error was encountered while 818818reading, the string will then be terminated with a \c NUL 819819character. 820820 821821If an error was encountered, the function returns NULL and sets the 822822error flag of \c stream, which can be tested using ferror(). 823823Otherwise, a pointer to the string will be returned. */ 824824extern char *fgets(char *__str, int __size, FILE *__stream); 825825 826826/** 827827Similar to fgets() except that it will operate on stream \c stdin, 828828and the trailing newline (if any) will not be stored in the string. 829829It is the caller's responsibility to provide enough storage to hold 830830the characters read. */ 831831extern char *gets(char *__str); 832832 833833/** 834834Read \c nmemb objects, \c size bytes each, from \c stream, 835835to the buffer pointed to by \c ptr. 836836 837837Returns the number of objects successfully read, i. e. 838838\c nmemb unless an input error occured or end-of-file was 839839encountered. feof() and ferror() must be used to distinguish 840840between these two conditions. 841841*/ 842842extern size_t fread(void *__ptr, size_t __size, size_t __nmemb, 843843FILE *__stream); 844844 845845/** 846846Clear the error and end-of-file flags of \c stream. 847847*/ 848848extern void clearerr(FILE *__stream); 849849 850850#if !defined(__DOXYGEN__) 851851/* fast inlined version of clearerr() */ 852852#define clearerror(s) do { (s)->flags &= ~(__SERR | __SEOF); } while(0) 853853#endif /* !defined(__DOXYGEN__) */ 854854 855855/** 856856Test the end-of-file flag of \c stream. This flag can only be cleared 857857by a call to clearerr(). 858858*/ 859859extern int feof(FILE *__stream); 860860 861861#if !defined(__DOXYGEN__) 862862/* fast inlined version of feof() */ 863863#define feof(s) ((s)->flags & __SEOF) 864864#endif /* !defined(__DOXYGEN__) */ 865865 866866/** 867867Test the error flag of \c stream. This flag can only be cleared 868868by a call to clearerr(). 869869*/ 870870extern int ferror(FILE *__stream); 871871 872872#if !defined(__DOXYGEN__) 873873/* fast inlined version of ferror() */ 874874#define ferror(s) ((s)->flags & __SERR) 875875#endif /* !defined(__DOXYGEN__) */ 876876 877877extern int vfscanf(FILE *__stream, const char *__fmt, va_list __ap); 878878 879879/** 880880Variant of vfscanf() using a \c fmt string in program memory. 881881*/ 882882extern int vfscanf_P(FILE *__stream, const char *__fmt, va_list __ap); 883883 884884/** 885885The function \c fscanf performs formatted input, reading the 886886input data from \c stream. 887887 888888See vfscanf() for details. 889889*/ 890890extern int fscanf(FILE *__stream, const char *__fmt, ...); 891891 892892/** 893893Variant of fscanf() using a \c fmt string in program memory. 894894*/ 895895extern int fscanf_P(FILE *__stream, const char *__fmt, ...); 896896 897897/** 898898The function \c scanf performs formatted input from stream \c stdin. 899899 900900See vfscanf() for details. 901901*/ 902902extern int scanf(const char *__fmt, ...); 903903 904904/** 905905Variant of scanf() where \c fmt resides in program memory. 906906*/ 907907extern int scanf_P(const char *__fmt, ...); 908908 909909/** 910910The function \c vscanf performs formatted input from stream 911911\c stdin, taking a variable argument list as in vfscanf(). 912912 913913See vfscanf() for details. 914914*/ 915915extern int vscanf(const char *__fmt, va_list __ap); 916916 917917/** 918918The function \c sscanf performs formatted input, reading the 919919input data from the buffer pointed to by \c buf. 920920 921921See vfscanf() for details. 922922*/ 923923extern int sscanf(const char *__buf, const char *__fmt, ...); 924924 925925/** 926926Variant of sscanf() using a \c fmt string in program memory. 927927*/ 928928extern int sscanf_P(const char *__buf, const char *__fmt, ...); 929929 930930#if defined(__DOXYGEN__) 931931/** 932932Flush \c stream. 933933 934934This is a null operation provided for source-code compatibility 935935only, as the standard IO implementation currently does not perform 936936any buffering. 937937*/ 938938extern int fflush(FILE *stream); 939939#else 940940static __inline__ int fflush(FILE *stream __attribute__((unused))) 941941{ 942942return 0; 943943} 944944#endif 945945 946946#ifndef __DOXYGEN__ 947947/* only mentioned for libstdc++ support, not implemented in library */ 948948#define BUFSIZ 1024 949949#define _IONBF 0 950950__extension__ typedef long long fpos_t; 951951extern int fgetpos(FILE *stream, fpos_t *pos); 952952extern FILE *fopen(const char *path, const char *mode); 953953extern FILE *freopen(const char *path, const char *mode, FILE *stream); 954954extern FILE *fdopen(int, const char *); 955955extern int fseek(FILE *stream, long offset, int whence); 956956extern int fsetpos(FILE *stream, fpos_t *pos); 957957extern long ftell(FILE *stream); 958958extern int fileno(FILE *); 959959extern void perror(const char *s); 960960extern int remove(const char *pathname); 961961extern int rename(const char *oldpath, const char *newpath); 962962extern void rewind(FILE *stream); 963963extern void setbuf(FILE *stream, char *buf); 964964extern int setvbuf(FILE *stream, char *buf, int mode, size_t size); 965965extern FILE *tmpfile(void); 966966extern char *tmpnam (char *s); 967967#endif /* !__DOXYGEN__ */ 968968 969969#ifdef __cplusplus 970970} 971971#endif 972972 973973/*@}*/ 974974 975975#ifndef __DOXYGEN__ 976976/* 977977* The following constants are currently not used by avr-libc's 978978* stdio subsystem. They are defined here since the gcc build 979979* environment expects them to be here. 980980*/ 981981#define SEEK_SET 0 982982#define SEEK_CUR 1 983983#define SEEK_END 2 984984 985985#endif 986986 987987#endif /* __ASSEMBLER */ 988988 989989#endif /* _STDLIB_H_ */

vfscanf int vfscanf(FILE *__stream, const char *__fmt, va_list __ap)

Definition: vfscanf.c:704

vprintf int vprintf(const char *__fmt, va_list __ap)

Definition: vprintf.c:38

fwrite size_t fwrite(const void *__ptr, size_t __size, size_t __nmemb, FILE *__stream)

Definition: fwrite.c:38

scanf int scanf(const char *__fmt,...)

Definition: scanf.c:38

getc #define getc(__stream)

Definition: stdio.h:790

FILE struct __file FILE

Definition: stdio.h:277

vscanf int vscanf(const char *__fmt, va_list __ap)

Definition: vscanf.c:38

fflush int fflush(FILE *stream)

puts_P int puts_P(const char *__str)

Definition: puts_p.c:41

fclose int fclose(FILE *__stream)

Definition: fclose.c:40

sprintf int sprintf(char *__s, const char *__fmt,...)

Definition: sprintf.c:40

snprintf_P int snprintf_P(char *__s, size_t __n, const char *__fmt,...)

Definition: snprintf_p.c:39

vfscanf_P int vfscanf_P(FILE *__stream, const char *__fmt, va_list __ap)

Definition: vfscanf_p.c:38

vsnprintf int vsnprintf(char *__s, size_t __n, const char *__fmt, va_list ap)

Definition: vsnprintf.c:39

putc #define putc(__c, __stream)

Definition: stdio.h:640

sscanf int sscanf(const char *__buf, const char *__fmt,...)

Definition: sscanf.c:40

ferror int ferror(FILE *__stream)

Definition: ferror.c:40

puts int puts(const char *__str)

Definition: puts.c:38

printf_P int printf_P(const char *__fmt,...)

Definition: printf_p.c:39

vsprintf int vsprintf(char *__s, const char *__fmt, va_list ap)

Definition: vsprintf.c:40

__attribute__ static __inline void __attribute__((__always_inline__)) __power_all_enable()

Definition: power.h:1148

fdevopen FILE * fdevopen(int(*put)(char, FILE *), int(*get)(FILE *))

Definition: fdevopen.c:87

scanf_P int scanf_P(const char *__fmt,...)

Definition: scanf_p.c:39

vsprintf_P int vsprintf_P(char *__s, const char *__fmt, va_list ap)

Definition: vsprintf_p.c:40

gets char * gets(char *__str)

Definition: gets.c:38

vfprintf_P int vfprintf_P(FILE *__stream, const char *__fmt, va_list __ap)

Definition: vfprintf_p.c:38

fputs_P int fputs_P(const char *__str, FILE *__stream)

Definition: fputs_p.c:41

clearerr void clearerr(FILE *__stream)

Definition: clearerr.c:40

fputs int fputs(const char *__str, FILE *__stream)

Definition: fputs.c:38

snprintf int snprintf(char *__s, size_t __n, const char *__fmt,...)

Definition: snprintf.c:39

putchar #define putchar(__c)

Definition: stdio.h:645

uint8_t unsigned char uint8_t

Definition: stdint.h:83

fprintf_P int fprintf_P(FILE *__stream, const char *__fmt,...)

Definition: fprintf_p.c:39

inttypes.h

feof int feof(FILE *__stream)

Definition: feof.c:40

fputc int fputc(int __c, FILE *__stream)

Definition: fputc.c:38

fprintf int fprintf(FILE *__stream, const char *__fmt,...)

Definition: fprintf.c:38

fgets char * fgets(char *__str, int __size, FILE *__stream)

Definition: fgets.c:38

fgetc int fgetc(FILE *__stream)

Definition: fgetc.c:38

fread size_t fread(void *__ptr, size_t __size, size_t __nmemb, FILE *__stream)

Definition: fread.c:38

ungetc int ungetc(int __c, FILE *__stream)

Definition: ungetc.c:38

sscanf_P int sscanf_P(const char *__buf, const char *__fmt,...)

Definition: sscanf_p.c:40

getchar #define getchar()

Definition: stdio.h:796

vsnprintf_P int vsnprintf_P(char *__s, size_t __n, const char *__fmt, va_list ap)

Definition: vsnprintf_p.c:39

fscanf int fscanf(FILE *__stream, const char *__fmt,...)

Definition: fscanf.c:38

fscanf_P int fscanf_P(FILE *__stream, const char *__fmt,...)

Definition: fscanf_p.c:39

printf int printf(const char *__fmt,...)

Definition: printf.c:38

sprintf_P int sprintf_P(char *__s, const char *__fmt,...)

Definition: sprintf_p.c:40

vfprintf int vfprintf(FILE *__stream, const char *__fmt, va_list __ap)

Definition: vfprintf.c:286