iPXE
Functions
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)
 
int vasprintf (char **strp, const char *fmt, va_list args)
 Write a formatted string to newly allocated memory. More...
 
int asprintf (char **strp, const char *fmt,...)
 Write a formatted string to newly allocated memory. More...
 

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

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

17  {
18  size_t len;
19  va_list args_tmp;
20 
21  /* Calculate length needed for string */
22  va_copy ( args_tmp, args );
23  len = ( vsnprintf ( NULL, 0, fmt, args_tmp ) + 1 );
24  va_end ( args_tmp );
25 
26  /* Allocate and fill string */
27  *strp = malloc ( len );
28  if ( ! *strp )
29  return -ENOMEM;
30  return vsnprintf ( *strp, len, fmt, args );
31 }
#define va_end(ap)
Definition: stdarg.h:9
#define va_copy(dest, src)
Definition: stdarg.h:10
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
uint32_t len
Length.
Definition: ena.h:14
__builtin_va_list va_list
Definition: stdarg.h:6
int ssize_t const char * fmt
Definition: vsprintf.h:72
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
Write a formatted string to a buffer.
Definition: vsprintf.c:351

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

Referenced by 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 41 of file asprintf.c.

41  {
42  va_list args;
43  int len;
44 
45  va_start ( args, fmt );
46  len = vasprintf ( strp, fmt, args );
47  va_end ( args );
48  return len;
49 }
#define va_end(ap)
Definition: stdarg.h:9
int vasprintf(char **strp, const char *fmt, va_list args)
Write a formatted string to newly allocated memory.
Definition: asprintf.c:17
uint32_t len
Length.
Definition: ena.h:14
__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 fmt, len, va_end, va_start, and vasprintf().

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