Add pancyrillic font
[platform/upstream/kbd.git] / src / xmalloc.c
1 /* Error-free versions of some libc routines */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <sysexits.h>
7 #include "kbd.h"
8 #include "nls.h"
9 #include "xmalloc.h"
10
11 extern char *progname;
12
13 static void __attribute__ ((noreturn))
14 nomem(void) {
15         fprintf(stderr, _("%s: out of memory\n"), progname);
16         exit(EX_OSERR);
17 }
18
19 void *
20 xmalloc(size_t sz) {
21         void *p = malloc(sz);
22         if (p == NULL)
23                 nomem();
24         return p;
25 }
26
27 void *
28 xrealloc(void *pp, size_t sz) {
29         void *p = realloc(pp, sz);
30         if (p == NULL)
31                 nomem();
32         return p;
33 }
34
35 char *
36 xstrdup(char *p) {
37         char *q = strdup(p);
38         if (q == NULL)
39                 nomem();
40         return q;
41 }
42
43 char *
44 xstrndup(char *p, size_t n) {
45         char *q = strndup(p, n);
46         if (q == NULL)
47                 nomem();
48         return q;
49 }
50
51 void *
52 xfree(void *p) {
53         if (p != NULL)
54                 free(p);
55         return NULL;
56 }