-
Notifications
You must be signed in to change notification settings - Fork 7
/
utils.c
76 lines (68 loc) · 1.85 KB
/
utils.c
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
69
70
71
72
73
74
75
/*
* wiggle - apply rejected patches
*
* Copyright (C) 2003 Neil Brown <[email protected]>
* Copyright (C) 2010-2013 Neil Brown <[email protected]>
* Copyright (C) 2014-2020 Neil Brown <[email protected]>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.
*
* Author: Neil Brown
* Email: <[email protected]>
*/
#include "wiggle.h"
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
char *wiggle_Cmd = "wiggle";
int wiggle_do_trace = 0;
void *wiggle_xmalloc(int size)
{
void *rv = malloc(size);
if (size && !rv) {
char *msg = "Failed to allocate memory - aborting\n";
write(2, msg, strlen(msg));
exit(3);
}
return rv;
}
void wiggle_printword(FILE *f, struct elmnt e)
{
if (e.start[0])
fprintf(f, "%.*s", e.plen + e.prefix,
e.start - e.prefix);
else {
int a, b, c;
sscanf(e.start+1, "%d %d %d", &a, &b, &c);
fprintf(f, "*** %d,%d **** %d%s", b, c, a, e.start+18);
}
}
void wiggle_die(char *reason)
{
fprintf(stderr, "%s: fatal error: %s failure\n", wiggle_Cmd, reason);
exit(3);
}
void wiggle_check_dir(char *name, int fd)
{
struct stat st;
if (fstat(fd, &st) != 0) {
fprintf(stderr, "%s: fatal: %s is strange\n", wiggle_Cmd, name);
exit(3);
}
if (S_ISDIR(st.st_mode)) {
fprintf(stderr, "%s: %s is a directory\n", wiggle_Cmd, name);
exit(3);
}
}