-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
66 lines (58 loc) · 854 Bytes
/
Copy pathutils.c
File metadata and controls
66 lines (58 loc) · 854 Bytes
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
/* SPDX-License-Identifier: MIT */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
#include "sctui.h"
int
align(int num, int min, int max)
{
if (num > max)
num = max;
if (num < min)
num = min;
return num;
}
void
die(const char *msg, ...)
{
va_list ap;
if (global_sctui.init)
sctui_fini();
va_start(ap, msg);
vfprintf(stderr, msg, ap);
va_end(ap);
exit(1);
}
void *
ecalloc(size_t nmenb, size_t size)
{
void *p = calloc(nmenb, size);
if (!p)
die("failed to calloc\n");
return p;
}
void *
erealloc(void *p, size_t s)
{
if (!p)
p = ecalloc(1, s);
else
p = realloc(p, s);
if (!p)
die("realloc()");
return p;
}
size_t
_arealloc(void **p, size_t n, size_t o)
{
if (!(*p)) {
*p = calloc(1, n);
return n;
}
if (o >= n)
return o;
*p = erealloc(*p, n);
return n;
}