Disable *all* backups when --no-backups used
[wiggle/upstream.git] / utils.c
blob6984c150ddee5c93a9c6a6f97723035f70f82bb3
1 /*
2 * wiggle - apply rejected patches
4 * Copyright (C) 2003 Neil Brown <neilb@cse.unsw.edu.au>
5 * Copyright (C) 2010-2013 Neil Brown <neilb@suse.de>
6 * Copyright (C) 2014-2020 Neil Brown <neil@brown.name>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program.
22 * Author: Neil Brown
23 * Email: <neil@brown.name>
26 #include "wiggle.h"
27 #include <unistd.h>
28 #include <stdlib.h>
29 #include <sys/stat.h>
31 char *wiggle_Cmd = "wiggle";
33 int wiggle_do_trace = 0;
35 void *wiggle_xmalloc(int size)
37 void *rv = malloc(size);
38 if (size && !rv) {
39 char *msg = "Failed to allocate memory - aborting\n";
40 write(2, msg, strlen(msg));
41 exit(3);
43 return rv;
46 void wiggle_printword(FILE *f, struct elmnt e)
48 if (e.start[0])
49 fprintf(f, "%.*s", e.plen + e.prefix,
50 e.start - e.prefix);
51 else {
52 int a, b, c;
53 sscanf(e.start+1, "%d %d %d", &a, &b, &c);
54 fprintf(f, "*** %d,%d **** %d%s", b, c, a, e.start+18);
58 void wiggle_die(char *reason)
60 fprintf(stderr, "%s: fatal error: %s failure\n", wiggle_Cmd, reason);
61 exit(3);
64 void wiggle_check_dir(char *name, int fd)
66 struct stat st;
67 if (fstat(fd, &st) != 0) {
68 fprintf(stderr, "%s: fatal: %s is strange\n", wiggle_Cmd, name);
69 exit(3);
71 if (S_ISDIR(st.st_mode)) {
72 fprintf(stderr, "%s: %s is a directory\n", wiggle_Cmd, name);
73 exit(3);