File: xasprintf.c

package info (click to toggle)
partconf 1.52
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 152 kB
  • sloc: ansic: 933; makefile: 48
file content (23 lines) | stat: -rw-r--r-- 414 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#define _GNU_SOURCE
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

char *
xasprintf(const char *format, ...)
{
    va_list args;
    char *result;

    va_start(args, format);
    if (vasprintf(&result, format, args) < 0) {
        if (errno == ENOMEM) {
            fputs("Out of memory!\n", stderr);
            abort();
        }
        return NULL;
    }

    return result;
}