File: wrapper.c

package info (click to toggle)
ndctl 82-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,460 kB
  • sloc: ansic: 42,027; sh: 3,974; makefile: 28
file content (39 lines) | stat: -rw-r--r-- 693 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2005 Junio C Hamano. All rights reserved.
// Copyright (C) 2005 Linus Torvalds. All rights reserved.

/* originally copied from perf and git */

/*
 * Various trivial helper wrappers around standard functions
 */
#include <string.h>
#include <stdlib.h>

#include <util/util.h>

char *xstrdup(const char *str)
{
	char *ret = strdup(str);
	if (!ret) {
		ret = strdup(str);
		if (!ret)
			die("Out of memory, strdup failed");
	}
	return ret;
}

void *xrealloc(void *ptr, size_t size)
{
	void *ret;

	if (!size) {
		free(ptr);
		return malloc(1);
	}

	ret = realloc(ptr, size);
	if (!ret)
		die("Out of memory, realloc failed");
	return ret;
}