File: xmalloc.c

package info (click to toggle)
kbd-chooser 1.71
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 852 kB
  • sloc: ansic: 4,333; yacc: 777; lex: 131; makefile: 122; sh: 33
file content (68 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (7)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Error-free versions of some libc routines
 * We also move all printf-calling routines here; 
 * they are only called in the debug version; in other versions, we just die.
 *
 */

#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <debian-installer.h>
#include "nls.h"

extern char *filename;
extern int line_nr;

static void
nomem(void) {
	di_error (": Out of memory\n");
	exit(1);
}


void *
xmalloc(size_t sz) {
	void *p = malloc(sz);
	if (p == NULL)
		nomem();
	return p;
}

void *
xrealloc(void *pp, size_t sz) {
	void *p = realloc(pp, sz);
	if (p == NULL)
		nomem();
	return p;
}

char *
xstrdup(const char *p) {
	char *q = strdup(p);
	if (q == NULL)
		nomem();
	return q;
}

/* fatal errors - change to varargs next time */
void
lkfatal(const char *s) {
	di_error (" %s:%d: %s\n", filename, line_nr, s);
	exit(1);
}

void
lkfatal0(const char *s, int d) {
	di_error( " %s:%d: ", filename, line_nr );
	di_error( s, d);
	exit(1);
}

void
lkfatal1(const char *s, const char *s2) {
	di_error("%s:%d: ", filename, line_nr);
	di_error( s, s2);
	exit(1);
}