iPXE
Data Structures | Functions
efi_strings.c File Reference
#include <stddef.h>
#include <stdarg.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)
 
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...
 

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

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

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

References efi_sputc_context::buf, c, 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 72 of file efi_strings.c.

73  {
74  struct efi_sputc_context sctx;
75  size_t wlen;
76  size_t wend;
77 
78  /* Hand off to vcprintf */
80  sctx.buf = wbuf;
81  sctx.max_wlen = wsize;
82  wlen = vcprintf ( &sctx.ctx, fmt, args );
83 
84  /* Add trailing NUL */
85  if ( wsize ) {
86  wend = wsize - 1;
87  if ( wlen < wend )
88  wend = wlen;
89  wbuf[wend] = '\0';
90  }
91 
92  return wlen;
93 }
struct printf_context ctx
printf context
Definition: efi_strings.c:34
void(* handler)(struct printf_context *ctx, unsigned int c)
Character handler.
Definition: vsprintf.h:57
static void efi_printf_sputc(struct printf_context *ctx, unsigned int c)
Write wide character to buffer.
Definition: efi_strings.c:51
int ssize_t const char * fmt
Definition: vsprintf.h:72
Context used by efi_vsnprintf() and friends.
Definition: efi_strings.c:32
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 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_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 104 of file efi_strings.c.

104  {
105  va_list args;
106  int i;
107 
108  va_start ( args, fmt );
109  i = efi_vsnprintf ( wbuf, wsize, fmt, args );
110  va_end ( args );
111  return i;
112 }
#define va_end(ap)
Definition: stdarg.h:9
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:72
__builtin_va_list va_list
Definition: stdarg.h:6
int ssize_t const char * fmt
Definition: vsprintf.h:72
#define va_start(ap, last)
Definition: stdarg.h:7

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

Referenced by efi_block_hook(), efi_file_varlen(), efi_image_cmdline(), efi_image_path(), efi_local_open_resolved(), efi_snp_hii_append(), and efi_snp_probe().

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

124  {
125 
126  /* Treat negative buffer size as zero buffer size */
127  if ( swsize < 0 )
128  swsize = 0;
129 
130  /* Hand off to vsnprintf */
131  return efi_vsnprintf ( wbuf, swsize, fmt, args );
132 }
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:72
int ssize_t const char * fmt
Definition: vsprintf.h:72

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

143  {
144  va_list args;
145  int len;
146 
147  /* Hand off to vssnprintf */
148  va_start ( args, fmt );
149  len = efi_vssnprintf ( wbuf, swsize, fmt, args );
150  va_end ( args );
151  return len;
152 }
#define va_end(ap)
Definition: stdarg.h:9
uint32_t len
Length.
Definition: ena.h:14
__builtin_va_list va_list
Definition: stdarg.h:6
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:123
int ssize_t const char * fmt
Definition: vsprintf.h:72
#define va_start(ap, last)
Definition: stdarg.h:7

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