Skip to content
Snippets Groups Projects
Commit 7ad8a17d authored by Simon McVittie's avatar Simon McVittie
Browse files

utils: Add an abort-on-OOM wrapper for asprintf

parent 35e38ae5
Branches
Tags
1 merge request!311Build capsule-capture-libs from a bundled copy of libcapsule
...@@ -429,6 +429,22 @@ xcalloc( size_t n, size_t size ) ...@@ -429,6 +429,22 @@ xcalloc( size_t n, size_t size )
return ret; return ret;
} }
int
xasprintf( char **dest, const char *format, ...)
{
int ret;
va_list ap;
va_start( ap, format );
ret = vasprintf( dest, format, ap );
va_end( ap );
if( ret < 0 )
oom();
return ret;
}
/* /*
* _capsule_set_error_literal: * _capsule_set_error_literal:
* @code_dest: (out) (optional): used to return an errno value * @code_dest: (out) (optional): used to return an errno value
......
...@@ -88,6 +88,7 @@ void oom( void ) __attribute__((noreturn)); ...@@ -88,6 +88,7 @@ void oom( void ) __attribute__((noreturn));
char *xstrdup( const char *s ); char *xstrdup( const char *s );
void *xrealloc( void *ptr, size_t size ) __attribute__((alloc_size(2))); void *xrealloc( void *ptr, size_t size ) __attribute__((alloc_size(2)));
void *xcalloc( size_t n, size_t size ) __attribute__((alloc_size(1, 2), malloc)); void *xcalloc( size_t n, size_t size ) __attribute__((alloc_size(1, 2), malloc));
int xasprintf( char **s, const char *format, ...) __attribute__((format(printf, 2, 3)));
/* /*
* _capsule_steal_pointer: * _capsule_steal_pointer:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment