iPXE
Macros | Functions | Variables
stdio.h File Reference
#include <stdint.h>
#include <stdarg.h>

Go to the source code of this file.

Macros

#define sprintf(buf, fmt, ...)   snprintf ( (buf), ~( ( size_t ) 0 ), (fmt), ## __VA_ARGS__ )
 Write a formatted string to a buffer. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void putchar (int character)
 Write a single character to each console device. More...
 
int getchar (void)
 Read a single character from any console. More...
 
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. More...
 
int vsnprintf (char *buf, size_t size, const char *fmt, va_list args)
 Write a formatted string to a buffer. More...
 
int vasprintf (char **strp, const char *fmt, va_list args)
 Write a formatted string to newly allocated memory. More...
 
static int vsprintf (char *buf, const char *fmt, va_list args)
 Write a formatted string to a buffer. More...
 

Variables

int int size_t size
 
int int size_t const char * fmt
 

Macro Definition Documentation

◆ sprintf

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

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 36 of file stdio.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ putchar()

void putchar ( int  character)

Write a single character to each console device.

Parameters
characterCharacter to be written

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

Definition at line 27 of file console.c.

27  {
28  struct console_driver *console;
29 
30  /* Automatic LF -> CR,LF translation */
31  if ( character == '\n' )
32  putchar ( '\r' );
33 
34  for_each_table_entry ( console, CONSOLES ) {
35  if ( ( ! ( console->disabled & CONSOLE_DISABLED_OUTPUT ) ) &&
36  ( console_usage & console->usage ) &&
37  console->putchar )
38  console->putchar ( character );
39  }
40 }
#define CONSOLES
Console driver table.
Definition: console.h:114
void putchar(int character)
Write a single character to each console device.
Definition: console.c:27
int usage
Console usage bitmask.
Definition: console.h:101
#define CONSOLE_DISABLED_OUTPUT
Console is disabled for output.
Definition: console.h:108
void(* putchar)(int character)
Write a character to the console.
Definition: console.h:68
int console_usage
Current console usage.
Definition: console.c:11
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
int disabled
Console disabled flags.
Definition: console.h:62
A console driver.
Definition: console.h:55

References CONSOLE_DISABLED_OUTPUT, console_usage, CONSOLES, console_driver::disabled, for_each_table_entry, putchar(), console_driver::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  )

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;

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

Definition at line 82 of file console.c.

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

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

◆ __attribute__() [2/3]

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

◆ __attribute__() [3/3]

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

◆ vprintf()

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

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 449 of file vsprintf.c.

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

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

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

◆ vsnprintf()

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

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 351 of file vsprintf.c.

351  {
352  struct sputc_context sctx;
353  size_t len;
354  size_t end;
355 
356  /* Hand off to vcprintf */
357  sctx.ctx.handler = printf_sputc;
358  sctx.buf = buf;
359  sctx.max_len = size;
360  len = vcprintf ( &sctx.ctx, fmt, args );
361 
362  /* Add trailing NUL */
363  if ( size ) {
364  end = size - 1;
365  if ( len < end )
366  end = len;
367  buf[end] = '\0';
368  }
369 
370  return len;
371 }
uint32_t len
Length.
Definition: ena.h:14
uint32_t end
Ending offset.
Definition: netvsc.h:18
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
int ssize_t const char * fmt
Definition: vsprintf.h:72
Context used by vsnprintf() and friends.
Definition: vsprintf.c:316
char * buf
Buffer for formatted string (used by printf_sputc())
Definition: vsprintf.c:319
static void printf_sputc(struct printf_context *ctx, unsigned int c)
Write character to buffer.
Definition: vsprintf.c:330
size_t vcprintf(struct printf_context *ctx, const char *fmt, va_list args)
Write a formatted string to a printf context.
Definition: vsprintf.c:187

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

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

◆ vasprintf()

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

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 17 of file asprintf.c.

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

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

Referenced by asprintf(), and xfer_vprintf().

◆ vsprintf()

static 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 47 of file stdio.h.

47  {
48  return vsnprintf ( buf, ~( ( size_t ) 0 ), fmt, args );
49 }
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Write a formatted string to a buffer.
Definition: vsprintf.c:351
int int size_t const char * fmt
Definition: stdio.h:17
char * buf
Buffer for formatted string (used by printf_sputc())
Definition: vsprintf.c:319

References fmt, and vsnprintf().

Variable Documentation

◆ size

int int size_t size

Definition at line 17 of file stdio.h.

◆ fmt

int int size_t const char int const char* fmt

Definition at line 17 of file stdio.h.

Referenced by vsprintf().