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

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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.

References efi_sputc_context::buf, container_of, printf_context::len, and efi_sputc_context::max_wlen.

Referenced by efi_vsnprintf().

                                                                            {
        struct efi_sputc_context * sctx =
                container_of ( ctx, struct efi_sputc_context, ctx );

        if ( ctx->len < sctx->max_wlen )
                sctx->buf[ctx->len] = c;
}
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.

References efi_sputc_context::buf, efi_sputc_context::ctx, efi_printf_sputc(), printf_context::handler, efi_sputc_context::max_wlen, and vcprintf().

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

                                   {
        struct efi_sputc_context sctx;
        size_t wlen;
        size_t wend;

        /* Hand off to vcprintf */
        sctx.ctx.handler = efi_printf_sputc;
        sctx.buf = wbuf;
        sctx.max_wlen = wsize;
        wlen = vcprintf ( &sctx.ctx, fmt, args );

        /* Add trailing NUL */
        if ( wsize ) {
                wend = wsize - 1;
                if ( wlen < wend )
                        wend = wlen;
                wbuf[wend] = '\0';
        }

        return wlen;
}
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.

References efi_vsnprintf(), 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().

                                                                       {
        va_list args;
        int i;

        va_start ( args, fmt );
        i = efi_vsnprintf ( wbuf, wsize, fmt, args );
        va_end ( args );
        return i;
}
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.

References efi_vsnprintf().

Referenced by efi_ssnprintf().

                                    {

        /* Treat negative buffer size as zero buffer size */
        if ( swsize < 0 )
                swsize = 0;

        /* Hand off to vsnprintf */
        return efi_vsnprintf ( wbuf, swsize, fmt, args );
}
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.

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

                                                                          {
        va_list args;
        int len;

        /* Hand off to vssnprintf */
        va_start ( args, fmt );
        len = efi_vssnprintf ( wbuf, swsize, fmt, args );
        va_end ( args );
        return len;
}