iPXE
efi_strings.h File Reference

EFI strings. More...

#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>

Go to the source code of this file.

Macros

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

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int efi_vsnprintf (wchar_t *wbuf, size_t wsize, const char *fmt, va_list args)
 Write a formatted string to a wide-character buffer.
int efi_snprintf (wchar_t *wbuf, size_t wsize, const char *fmt,...)
 Write a formatted string to a buffer.
int efi_vssnprintf (wchar_t *wbuf, ssize_t swsize, const char *fmt, va_list args)
 Version of efi_vsnprintf() that accepts a signed buffer size.
int efi_ssnprintf (wchar_t *wbuf, ssize_t swsize, const char *fmt,...)
 Version of efi_vsnprintf() that accepts a signed buffer size.
int efi_vasprintf (wchar_t **strp, const char *fmt, va_list args)
 Write a formatted string to newly allocated memory.
int efi_asprintf (wchar_t **strp, const char *fmt,...)
 Write a formatted string to newly allocated memory.
static int efi_vsprintf (wchar_t *buf, const char *fmt, va_list args)
 Write a formatted string to a wide-character buffer.

Detailed Description

EFI strings.

Definition in file efi_strings.h.

Macro Definition Documentation

◆ efi_sprintf

#define efi_sprintf ( buf,
fmt,
... )
Value:
efi_snprintf ( (buf), ~( ( size_t ) 0 ), (fmt), ## __VA_ARGS__ )
int efi_snprintf(wchar_t *wbuf, size_t wsize, const char *fmt,...)
Write a formatted string to a buffer.
int ssize_t const char * fmt
Definition vsprintf.h:73

Write a formatted string to a buffer.

Parameters
wbufBuffer into which to write the string
fmtFormat string
...Arguments corresponding to the format string
Return values
wlenLength of formatted string (in wide characters)

Definition at line 46 of file efi_strings.h.

46#define efi_sprintf( buf, fmt, ... ) \
47 efi_snprintf ( (buf), ~( ( size_t ) 0 ), (fmt), ## __VA_ARGS__ )

Referenced by efi_block_exec().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

References fmt.

◆ efi_vsnprintf()

int efi_vsnprintf ( wchar_t * wbuf,
size_t wsize,
const char * fmt,
va_list args )
extern

Write a formatted string to a wide-character buffer.

Parameters
wbufBuffer into which to write the string
wsizeSize of buffer (in wide characters)
fmtFormat string
argsArguments corresponding to the format string
Return values
wlenLength of formatted string (in wide characters)

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 75 of file efi_strings.c.

76 {
77 struct efi_sputc_context sctx;
78 size_t wlen;
79 size_t wend;
80
81 /* Hand off to vcprintf */
83 sctx.buf = wbuf;
84 sctx.max_wlen = wsize;
85 wlen = vcprintf ( &sctx.ctx, fmt, args );
86
87 /* Add trailing NUL */
88 if ( wsize ) {
89 wend = wsize - 1;
90 if ( wlen < wend )
91 wend = wlen;
92 wbuf[wend] = '\0';
93 }
94
95 return wlen;
96}
static void efi_printf_sputc(struct printf_context *ctx, unsigned int c)
Write wide character to buffer.
Definition efi_strings.c:54
Context used by efi_vsnprintf() and friends.
Definition efi_strings.c:35
struct printf_context ctx
printf context
Definition efi_strings.c:37
void(* handler)(struct printf_context *ctx, unsigned int c)
Character handler.
Definition vsprintf.h:58
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 efi_sputc_context::buf, efi_sputc_context::ctx, efi_printf_sputc(), fmt, printf_context::handler, efi_sputc_context::max_wlen, and vcprintf().

Referenced by efi_ifr_string(), efi_snprintf(), efi_vasprintf(), efi_vsprintf(), and efi_vssnprintf().

◆ efi_snprintf()

int efi_snprintf ( wchar_t * wbuf,
size_t wsize,
const char * fmt,
... )
extern

Write a formatted string to a buffer.

Parameters
wbufBuffer into which to write the string
wsizeSize of buffer (in wide characters)
fmtFormat string
...Arguments corresponding to the format string
Return values
wlenLength of formatted string (in wide characters)

Definition at line 107 of file efi_strings.c.

107 {
108 va_list args;
109 int i;
110
111 va_start ( args, fmt );
112 i = efi_vsnprintf ( wbuf, wsize, fmt, args );
113 va_end ( args );
114 return i;
115}
int efi_vsnprintf(wchar_t *wbuf, size_t wsize, const char *fmt, va_list args)
Write a formatted string to a wide-character buffer.
Definition efi_strings.c:75
#define va_end(ap)
Definition stdarg.h:10
#define va_start(ap, last)
Definition stdarg.h:8
__builtin_va_list va_list
Definition stdarg.h:7

References efi_vsnprintf(), fmt, va_end, and va_start.

Referenced by efi_block_filename(), efi_boot_path(), efi_file_varlen(), efi_image_path(), efi_local_open_resolved(), efi_snp_hii_append(), efi_snp_probe(), and efivars_fetch().

◆ efi_vssnprintf()

int efi_vssnprintf ( wchar_t * wbuf,
ssize_t swsize,
const char * fmt,
va_list args )
extern

Version of efi_vsnprintf() that accepts a signed buffer size.

Parameters
wbufBuffer into which to write the string
swsizeSize of buffer (in wide characters)
fmtFormat string
argsArguments corresponding to the format string
Return values
wlenLength of formatted string (in wide characters)

Definition at line 126 of file efi_strings.c.

127 {
128
129 /* Treat negative buffer size as zero buffer size */
130 if ( swsize < 0 )
131 swsize = 0;
132
133 /* Hand off to vsnprintf */
134 return efi_vsnprintf ( wbuf, swsize, fmt, args );
135}

References efi_vsnprintf(), and fmt.

Referenced by efi_ssnprintf().

◆ efi_ssnprintf()

int efi_ssnprintf ( wchar_t * wbuf,
ssize_t swsize,
const char * fmt,
... )
extern

Version of efi_vsnprintf() that accepts a signed buffer size.

Parameters
wbufBuffer into which to write the string
swsizeSize of buffer (in wide characters)
fmtFormat string
...Arguments corresponding to the format string
Return values
wlenLength of formatted string (in wide characters)

Definition at line 146 of file efi_strings.c.

146 {
147 va_list args;
148 int len;
149
150 /* Hand off to vssnprintf */
151 va_start ( args, fmt );
152 len = efi_vssnprintf ( wbuf, swsize, fmt, args );
153 va_end ( args );
154 return len;
155}
ring len
Length.
Definition dwmac.h:226
int efi_vssnprintf(wchar_t *wbuf, ssize_t swsize, const char *fmt, va_list args)
Version of efi_vsnprintf() that accepts a signed buffer size.

References efi_vssnprintf(), fmt, len, va_end, and va_start.

◆ efi_vasprintf()

int efi_vasprintf ( wchar_t ** wstrp,
const char * fmt,
va_list args )
extern

Write a formatted string to newly allocated memory.

Parameters
wstrpPointer to hold allocated string
fmtFormat string
argsArguments corresponding to the format string
Return values
lenLength of formatted string (in wide characters)

Definition at line 165 of file efi_strings.c.

165 {
166 size_t len;
167 va_list args_tmp;
168
169 /* Calculate length needed for string */
170 va_copy ( args_tmp, args );
171 len = ( efi_vsnprintf ( NULL, 0, fmt, args_tmp ) + 1 );
172 va_end ( args_tmp );
173
174 /* Allocate and fill string */
175 *wstrp = malloc ( len * sizeof ( **wstrp ) );
176 if ( ! *wstrp )
177 return -ENOMEM;
178 return efi_vsnprintf ( *wstrp, len, fmt, args );
179}
#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

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

Referenced by efi_asprintf().

◆ efi_asprintf()

int efi_asprintf ( wchar_t ** wstrp,
const char * fmt,
... )
extern

Write a formatted string to newly allocated memory.

Parameters
wstrpPointer to hold allocated string
fmtFormat string
...Arguments corresponding to the format string
Return values
lenLength of formatted string (in wide characters)

Definition at line 189 of file efi_strings.c.

189 {
190 va_list args;
191 int len;
192
193 va_start ( args, fmt );
194 len = efi_vasprintf ( wstrp, fmt, args );
195 va_end ( args );
196 return len;
197}
int efi_vasprintf(wchar_t **wstrp, const char *fmt, va_list args)
Write a formatted string to newly allocated memory.

References efi_vasprintf(), fmt, len, va_end, and va_start.

Referenced by efi_image_cmdline(), and efi_shim_cmdline().

◆ efi_vsprintf()

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

Write a formatted string to a wide-character buffer.

Parameters
wbufBuffer into which to write the string
fmtFormat string
argsArguments corresponding to the format string
Return values
wlenLength of formatted string (in wide characters)

Definition at line 34 of file efi_strings.h.

34 {
35 return efi_vsnprintf ( buf, ~( ( size_t ) 0 ), fmt, args );
36}
int efi_vsnprintf(wchar_t *wbuf, size_t wsize, const char *fmt, va_list args)
Write a formatted string to a wide-character buffer.
Definition efi_strings.c:75

References efi_vsnprintf(), and fmt.