iPXE
stdio.h File Reference
#include <stdint.h>
#include <stdarg.h>

Go to the source code of this file.

Macros

#define sprintf(buf, fmt, ...)
 Write a formatted string to a buffer.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int putchar (int character)
 Write a single character to each console device.
int getchar (void)
 Read a single character from any console.
int __attribute__ ((format(printf, 1, 2))) printf(const char *fmt
int int __attribute__ ((format(printf, 3, 4))) snprintf(char *buf
int int size_t const char int __attribute__ ((format(printf, 2, 3))) asprintf(char **strp
int int size_t const char int const char int vprintf (const char *fmt, va_list args)
 Write a formatted string to the console.
int vsnprintf (char *buf, size_t size, const char *fmt, va_list args)
 Write a formatted string to a buffer.
int vasprintf (char **strp, const char *fmt, va_list args)
 Write a formatted string to newly allocated memory.
static int vsprintf (char *buf, const char *fmt, va_list args)
 Write a formatted string to a buffer.

Variables

int int size_t size
int int size_t const char * fmt

Macro Definition Documentation

◆ sprintf

#define sprintf ( buf,
fmt,
... )
Value:
snprintf ( (buf), ~( ( size_t ) 0 ), (fmt), ## __VA_ARGS__ )
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383
int ssize_t const char * fmt
Definition vsprintf.h:73

Write a formatted string to a buffer.

Parameters
bufBuffer into which to write the string
fmtFormat string
...Arguments corresponding to the format string
Return values
lenLength of formatted string

Definition at line 37 of file stdio.h.

37#define sprintf( buf, fmt, ... ) \
38 snprintf ( (buf), ~( ( size_t ) 0 ), (fmt), ## __VA_ARGS__ )

Referenced by bigint_ntoa_raw(), bios_ansi_seq(), concat_args(), efi_snp_hii_fetch(), eth_ntoa(), inet6_ntoa(), inet_ntoa(), ipair_tag(), isa_id_string(), usbkbd_consume(), and uuid_ntoa().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ putchar()

int putchar ( int character)
extern

Write a single character to each console device.

Parameters
characterCharacter to be written
Return values
characterCharacter written

The character is written out to all enabled console devices, using each device's console_driver::putchar() method.

Definition at line 29 of file console.c.

29 {
30 struct console_driver *console;
31
32 /* Automatic LF -> CR,LF translation */
33 if ( character == '\n' )
34 putchar ( '\r' );
35
36 for_each_table_entry ( console, CONSOLES ) {
37 if ( ( ! ( console->disabled & CONSOLE_DISABLED_OUTPUT ) ) &&
38 ( console_usage & console->usage ) &&
39 console->putchar )
40 console->putchar ( character );
41 }
42
43 return character;
44}
int console_usage
Current console usage.
Definition console.c:12
int putchar(int character)
Write a single character to each console device.
Definition console.c:29
#define CONSOLE_DISABLED_OUTPUT
Console is disabled for output.
Definition console.h:109
#define CONSOLES
Console driver table.
Definition console.h:115
A console driver.
Definition console.h:56
void(* putchar)(int character)
Write a character to the console.
Definition console.h:69
int usage
Console usage bitmask.
Definition console.h:102
int disabled
Console disabled flags.
Definition console.h:63
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

References CONSOLE_DISABLED_OUTPUT, console_usage, CONSOLES, console_driver::disabled, for_each_table_entry, console_driver::putchar, putchar(), and console_driver::usage.

Referenced by ansiscr_putc(), clrline(), eepro_poll(), epic100_open(), falcon_init_xmac(), get_eeprom_data(), int21(), monojob_clear(), print_user_string(), printf_putchar(), putchar(), readline_history(), and sync_console().

◆ getchar()

int getchar ( void )
extern

Read a single character from any console.

Return values
characterCharacter read from a console.

A character will be read from the first enabled console device that has input available using that console's console_driver::getchar() method. If no console has input available to be read, this method will block. To perform a non-blocking read, use something like

int key = iskey() ? getchar() : -1;
union @162305117151260234136356364136041353210355154177 key
Sense key.
Definition scsi.h:3
int getchar(void)
Read a single character from any console.
Definition console.c:86
int iskey(void)
Check for available input on any console.
Definition console.c:131

The character read will not be echoed back to any console.

Definition at line 86 of file console.c.

86 {
87 struct console_driver *console;
88 int character;
89
90 while ( 1 ) {
91 console = has_input();
92 if ( console && console->getchar ) {
93 character = console->getchar ();
94 break;
95 }
96
97 /* Doze for a while (until the next interrupt). This works
98 * fine, because the keyboard is interrupt-driven, and the
99 * timer interrupt (approx. every 50msec) takes care of the
100 * serial port, which is read by polling. This reduces the
101 * power dissipation of a modern CPU considerably, and also
102 * makes Etherboot waiting for user interaction waste a lot
103 * less CPU time in a VMware session.
104 */
105 cpu_nap();
106
107 /* Keep processing background tasks while we wait for
108 * input.
109 */
110 step();
111 }
112
113 /* CR -> LF translation */
114 if ( character == '\r' )
115 character = '\n';
116
117 return character;
118}
static struct console_driver * has_input(void)
Check to see if any input is available on any console.
Definition console.c:55
void cpu_nap(void)
Sleep with interrupts enabled until next CPU interrupt.
void step(void)
Single-step a single process.
Definition process.c:99
int(* getchar)(void)
Read a character from the console.
Definition console.h:79

References cpu_nap(), console_driver::getchar, has_input(), and step().

Referenced by ansiscr_getc(), dbg_more(), dbg_pause(), getchar_timeout(), int21(), keypress_interrupted(), loopback_wait(), and monojob_wait().

◆ __attribute__() [1/3]

int __attribute__ ( (format(printf, 1, 2)) ) const
extern

References fmt, format, and printf().

◆ __attribute__() [2/3]

int int __attribute__ ( (format(printf, 3, 4)) )
extern

References __attribute__, format, and printf().

◆ __attribute__() [3/3]

int int size_t const char int __attribute__ ( (format(printf, 2, 3)) )
extern

◆ vprintf()

int int size_t const char int const char int vprintf ( const char * fmt,
va_list args )
extern

Write a formatted string to the console.

Parameters
fmtFormat string
argsArguments corresponding to the format string
Return values
lenLength of formatted string

Definition at line 450 of file vsprintf.c.

450 {
451 struct printf_context ctx;
452
453 /* Hand off to vcprintf */
454 ctx.handler = printf_putchar;
455 return vcprintf ( &ctx, fmt, args );
456}
struct golan_eq_context ctx
Definition CIB_PRM.h:0
A printf context.
Definition vsprintf.h:48
static void printf_putchar(struct printf_context *ctx __unused, unsigned int c)
Write character to console.
Definition vsprintf.c:438
size_t vcprintf(struct printf_context *ctx, const char *fmt, va_list args)
Write a formatted string to a printf context.
Definition vsprintf.c:188

References ctx, fmt, printf_putchar(), and vcprintf().

Referenced by __attribute__(), dbg_printf(), log_vprintf(), and printf().

◆ vsnprintf()

int vsnprintf ( char * buf,
size_t size,
const char * fmt,
va_list args )
extern

Write a formatted string to a buffer.

Parameters
bufBuffer into which to write the string
sizeSize of buffer
fmtFormat string
argsArguments corresponding to the format string
Return values
lenLength of formatted string

If the buffer is too small to contain the string, the returned length is the length that would have been written had enough space been available.

Definition at line 352 of file vsprintf.c.

352 {
353 struct sputc_context sctx;
354 size_t len;
355 size_t end;
356
357 /* Hand off to vcprintf */
358 sctx.ctx.handler = printf_sputc;
359 sctx.buf = buf;
360 sctx.max_len = size;
361 len = vcprintf ( &sctx.ctx, fmt, args );
362
363 /* Add trailing NUL */
364 if ( size ) {
365 end = size - 1;
366 if ( len < end )
367 end = len;
368 buf[end] = '\0';
369 }
370
371 return len;
372}
ring len
Length.
Definition dwmac.h:226
uint16_t size
Buffer size.
Definition dwmac.h:3
uint32_t end
Ending offset.
Definition netvsc.h:7
Context used by vsnprintf() and friends.
Definition vsprintf.c:317
char * buf
Buffer for formatted string (used by printf_sputc())
Definition vsprintf.c:320
static void printf_sputc(struct printf_context *ctx, unsigned int c)
Write character to buffer.
Definition vsprintf.c:331

References sputc_context::buf, sputc_context::ctx, end, fmt, printf_context::handler, len, sputc_context::max_len, printf_sputc(), size, and vcprintf().

Referenced by __attribute__(), ipair_tx(), snprintf(), snprintf_okx(), vasprintf(), vmsg(), vsprintf(), and vssnprintf().

◆ vasprintf()

int vasprintf ( char ** strp,
const char * fmt,
va_list args )
extern

Write a formatted string to newly allocated memory.

Parameters
strpPointer to hold allocated string
fmtFormat string
argsArguments corresponding to the format string
Return values
lenLength of formatted string

Definition at line 18 of file asprintf.c.

18 {
19 size_t len;
20 va_list args_tmp;
21
22 /* Calculate length needed for string */
23 va_copy ( args_tmp, args );
24 len = ( vsnprintf ( NULL, 0, fmt, args_tmp ) + 1 );
25 va_end ( args_tmp );
26
27 /* Allocate and fill string */
28 *strp = malloc ( len );
29 if ( ! *strp )
30 return -ENOMEM;
31 return vsnprintf ( *strp, len, fmt, args );
32}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define ENOMEM
Not enough space.
Definition errno.h:535
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:621
#define va_copy(dest, src)
Definition stdarg.h:11
#define va_end(ap)
Definition stdarg.h:10
__builtin_va_list va_list
Definition stdarg.h:7
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Write a formatted string to a buffer.
Definition vsprintf.c:352

References ENOMEM, fmt, len, malloc(), NULL, va_copy, va_end, and vsnprintf().

Referenced by __attribute__(), asprintf(), and xfer_vprintf().

◆ vsprintf()

int vsprintf ( char * buf,
const char * fmt,
va_list args )
inlinestatic

Write a formatted string to a buffer.

Parameters
bufBuffer into which to write the string
fmtFormat string
argsArguments corresponding to the format string
Return values
lenLength of formatted string

Definition at line 48 of file stdio.h.

48 {
49 return vsnprintf ( buf, ~( ( size_t ) 0 ), fmt, args );
50}
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Write a formatted string to a buffer.
Definition vsprintf.c:352

References fmt, and vsnprintf().

Variable Documentation

◆ size

int int size_t size

Definition at line 18 of file stdio.h.

◆ fmt

int int size_t const char int const char* fmt

Definition at line 18 of file stdio.h.