c = realloc(list[0].body, len+1);
if (c == NULL)
- die();
+ die("memory allocation");
list[0].body = c;
c += list[0].len;
s.len = stb.st_size;
s.body = xmalloc(s.len+1);
if (read(fd, s.body, s.len) != s.len)
- die();
+ die("file read");
s.body[s.len] = 0;
return s;
list[i].body = xmalloc(8192);
list[i].len = read(fd, list[i].body, 8192);
if (list[i].len < 0)
- die();
+ die("file read");
if (list[i].len == 0)
break;
i++;
s.body = xmalloc(s.len+1);
fseek(f, start, 0);
if (fread(s.body, 1, s.len, f) != (size_t)s.len)
- die();
+ die("file read");
/* ensure string is 'nul' terminated - for sscanf */
s.body[s.len] = 0;
return s;
if (fd < 0)
return s;
}
-
+ check_dir(name, fd);
if (fstat(fd, &stb) == 0) {
if (S_ISREG(stb.st_mode))
fprintf(stderr, "%s: cannot open %s\n", Cmd, argv[0]);
exit(1);
}
+ check_dir(argv[0], fileno(f));
if (patch) {
pl = parse_patch(f, NULL, &num_patches);
if (set_prefix(pl, num_patches, strip) == 0) {
break;
case 2: /* an orig and a diff/.ref */
f = fopen(argv[1], "r");
+ check_dir(argv[1], fileno(f));
if (!f) {
fprintf(stderr, "%s: cannot open %s\n", Cmd, argv[0]);
exit(1);
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
+#include <sys/stat.h>
char *Cmd = "wiggle";
int do_trace = 0;
-void die()
+void die(char *reason)
{
- fprintf(stderr, "%s: fatal error\n", Cmd);
- abort();
+ fprintf(stderr, "%s: fatal error: %s failure\n", Cmd, reason);
exit(3);
}
+void check_dir(char *name, int fd)
+{
+ struct stat st;
+ if (fstat(fd, &st) != 0) {
+ fprintf(stderr, "%s: fatal: %s is strange\n", Cmd, name);
+ exit(3);
+ }
+ if (S_ISDIR(st.st_mode)) {
+ fprintf(stderr, "%s: %s is a directory\n", Cmd, name);
+ exit(3);
+ }
+}
+
void *xmalloc(int size)
{
void *rv = malloc(size);
Cmd, filename);
return 2;
}
+ check_dir(filename, fileno(f));
pl = parse_patch(f, NULL, &num_patches);
fclose(f);
if (set_prefix(pl, num_patches, strip) == 0) {
struct csl *c1, struct csl *c2, int words,
int ignore_already, int show_wiggles);
-extern void die(void);
+extern void die(char *reason);
+extern void check_dir(char *name, int fd);
extern void *xmalloc(int len);
extern int do_trace;