iPXE
asprintf.c File Reference
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int vasprintf (char **strp, const char *fmt, va_list args)
 Write a formatted string to newly allocated memory.
int asprintf (char **strp, const char *fmt,...)
 Write a formatted string to newly allocated memory.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

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

18 {
19 size_t len;
20 va_list args_tmp;
21
22 /* Calculate length needed for string */
23 va_copy ( args_tmp, args );
24 len = ( vsnprintf ( NULL, 0, fmt, args_tmp ) + 1 );
25 va_end ( args_tmp );
26
27 /* Allocate and fill string */
28 *strp = malloc ( len );
29 if ( ! *strp )
30 return -ENOMEM;
31 return vsnprintf ( *strp, len, fmt, args );
32}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
ring len
Length.
Definition dwmac.h:226
#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
#define va_end(ap)
Definition stdarg.h:10
__builtin_va_list va_list
Definition stdarg.h:7
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Write a formatted string to a buffer.
Definition vsprintf.c:352
int ssize_t const char * fmt
Definition vsprintf.h:73

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

Referenced by __attribute__(), asprintf(), and xfer_vprintf().

◆ asprintf()

int asprintf ( char ** strp,
const char * fmt,
... )

Write a formatted string to newly allocated memory.

Parameters
strpPointer to hold allocated string
fmtFormat string
...Arguments corresponding to the format string
Return values
lenLength of formatted string

Definition at line 42 of file asprintf.c.

42 {
43 va_list args;
44 int len;
45
46 va_start ( args, fmt );
47 len = vasprintf ( strp, fmt, args );
48 va_end ( args );
49 return len;
50}
int vasprintf(char **strp, const char *fmt, va_list args)
Write a formatted string to newly allocated memory.
Definition asprintf.c:18
#define va_start(ap, last)
Definition stdarg.h:8

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

Referenced by __attribute__(), efi_block_label(), efi_local_check_volume_name(), expand_settings(), iscsi_fetch_settings(), peerdist_discovery_request(), resolve_path(), tftp_uri(), and xenstore_dump().