iPXE
Data Structures | Functions
efi_strings.c File Reference
#include <stddef.h>
#include <stdarg.h>
#include <stdlib.h>
#include <errno.h>
#include <ipxe/vsprintf.h>
#include <ipxe/efi/efi_strings.h>

Go to the source code of this file.

Data Structures

struct  efi_sputc_context
 Context used by efi_vsnprintf() and friends. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static void efi_printf_sputc (struct printf_context *ctx, unsigned int c)
 Write wide character to buffer. More...
 
int efi_vsnprintf (wchar_t *wbuf, size_t wsize, const char *fmt, va_list args)
 Write a formatted string to a wide-character buffer. More...
 
int efi_snprintf (wchar_t *wbuf, size_t wsize, const char *fmt,...)
 Write a formatted string to a buffer. More...
 
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. More...
 
int efi_ssnprintf (wchar_t *wbuf, ssize_t swsize, const char *fmt,...)
 Version of efi_vsnprintf() that accepts a signed buffer size. More...
 
int efi_vasprintf (wchar_t **wstrp, const char *fmt, va_list args)
 Write a formatted string to newly allocated memory. More...
 
int efi_asprintf (wchar_t **wstrp, const char *fmt,...)
 Write a formatted string to newly allocated memory. More...
 

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ efi_printf_sputc()

static void efi_printf_sputc ( struct printf_context ctx,
unsigned int  c 
)
static

Write wide character to buffer.

Parameters
ctxContext
cCharacter

Definition at line 54 of file efi_strings.c.

54  {
55  struct efi_sputc_context * sctx =
57 
58  if ( ctx->len < sctx->max_wlen )
59  sctx->buf[ctx->len] = c;
60 }
wchar_t * buf
Buffer for formatted string (used by efi_printf_sputc())
Definition: efi_strings.c:39
struct golan_eq_context ctx
Definition: CIB_PRM.h:28
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
size_t max_wlen
Buffer length (used by efi_printf_sputc())
Definition: efi_strings.c:45
Context used by efi_vsnprintf() and friends.
Definition: efi_strings.c:35

References efi_sputc_context::buf, container_of, ctx, and efi_sputc_context::max_wlen.

Referenced by efi_vsnprintf().

◆ efi_vsnprintf()

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

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 }
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
static void efi_printf_sputc(struct printf_context *ctx, unsigned int c)
Write wide character to buffer.
Definition: efi_strings.c:54
int ssize_t const char * fmt
Definition: vsprintf.h:73
Context used by efi_vsnprintf() and friends.
Definition: efi_strings.c:35
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,
  ... 
)

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 }
#define va_end(ap)
Definition: stdarg.h:10
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
__builtin_va_list va_list
Definition: stdarg.h:7
int ssize_t const char * fmt
Definition: vsprintf.h:73
#define va_start(ap, last)
Definition: stdarg.h:8

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 
)

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 }
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
int ssize_t const char * fmt
Definition: vsprintf.h:73

References efi_vsnprintf(), and fmt.

Referenced by efi_ssnprintf().

◆ efi_ssnprintf()

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

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 }
#define va_end(ap)
Definition: stdarg.h:10
ring len
Length.
Definition: dwmac.h:231
__builtin_va_list va_list
Definition: stdarg.h:7
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.
Definition: efi_strings.c:126
int ssize_t const char * fmt
Definition: vsprintf.h:73
#define va_start(ap, last)
Definition: stdarg.h:8

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

◆ efi_vasprintf()

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

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 va_end(ap)
Definition: stdarg.h:10
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_copy(dest, src)
Definition: stdarg.h:11
#define ENOMEM
Not enough space.
Definition: errno.h:535
ring len
Length.
Definition: dwmac.h:231
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
__builtin_va_list va_list
Definition: stdarg.h:7
int ssize_t const char * fmt
Definition: vsprintf.h:73
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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,
  ... 
)

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 }
#define va_end(ap)
Definition: stdarg.h:10
int efi_vasprintf(wchar_t **wstrp, const char *fmt, va_list args)
Write a formatted string to newly allocated memory.
Definition: efi_strings.c:165
ring len
Length.
Definition: dwmac.h:231
__builtin_va_list va_list
Definition: stdarg.h:7
int ssize_t const char * fmt
Definition: vsprintf.h:73
#define va_start(ap, last)
Definition: stdarg.h:8

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

Referenced by efi_image_cmdline(), and efi_shim_cmdline().