-/* $OpenBSD: patch.c,v 1.53 2014/12/08 21:59:36 deraadt Exp $ */
+/* $OpenBSD: patch.c,v 1.54 2014/12/13 10:31:07 tobias Exp $ */
/*
* patch - a program to apply diffs to original files
warn_on_invalid_line = true;
if (outname == NULL)
- outname = savestr(filearg[0]);
+ outname = xstrdup(filearg[0]);
/* for ed script just up and do it and exit */
if (diff_type == ED_DIFF) {
/* FALLTHROUGH */
case 'z':
/* must directly follow 'b' case for backwards compat */
- simple_backup_suffix = savestr(optarg);
+ simple_backup_suffix = xstrdup(optarg);
break;
case 'B':
- origprae = savestr(optarg);
+ origprae = xstrdup(optarg);
break;
case 'c':
diff_type = CONTEXT_DIFF;
case 'i':
if (++filec == MAXFILEC)
fatal("too many file arguments\n");
- filearg[filec] = savestr(optarg);
+ filearg[filec] = xstrdup(optarg);
break;
case 'l':
canonicalize = true;
noreverse = true;
break;
case 'o':
- outname = savestr(optarg);
+ outname = xstrdup(optarg);
break;
case 'p':
strippath = atoi(optarg);
Argv += optind;
if (Argc > 0) {
- filearg[0] = savestr(*Argv++);
+ filearg[0] = xstrdup(*Argv++);
Argc--;
while (Argc > 0) {
if (++filec == MAXFILEC)
fatal("too many file arguments\n");
- filearg[filec] = savestr(*Argv++);
+ filearg[filec] = xstrdup(*Argv++);
Argc--;
}
}
-/* $OpenBSD: pch.c,v 1.48 2014/12/08 21:59:36 deraadt Exp $ */
+/* $OpenBSD: pch.c,v 1.49 2014/12/13 10:31:07 tobias Exp $ */
/*
* patch - a program to apply diffs to original files
while (filearg[0] == NULL) {
if (force || batch) {
say("No file to patch. Skipping...\n");
- filearg[0] = savestr(bestguess);
+ filearg[0] = xstrdup(bestguess);
skip_rest_of_patch = true;
return true;
}
ask("File to patch: ");
if (*buf != '\n') {
free(bestguess);
- bestguess = savestr(buf);
+ bestguess = xstrdup(buf);
filearg[0] = fetchname(buf, &exists, 0);
}
if (!exists) {
else if (strnEQ(s, "Prereq:", 7)) {
for (t = s + 7; isspace((unsigned char)*t); t++)
;
- revision = savestr(t);
+ revision = xstrdup(t);
for (t = revision;
*t && !isspace((unsigned char)*t); t++)
;
free(bestguess);
bestguess = NULL;
if (filearg[0] != NULL)
- bestguess = savestr(filearg[0]);
+ bestguess = xstrdup(filearg[0]);
else if (!ok_to_create_file) {
/*
* We don't want to create a new file but we need a
path = names[NEW_FILE].path;
}
- return path ? savestr(path) : NULL;
+ return path ? xstrdup(path) : NULL;
}
static char *
names[NEW_FILE].path != NULL)
best = names[NEW_FILE].path;
}
- return best ? savestr(best) : NULL;
+ return best ? xstrdup(best) : NULL;
}
static size_t
-/* $OpenBSD: util.c,v 1.37 2014/11/22 15:49:28 tobias Exp $ */
+/* $OpenBSD: util.c,v 1.38 2014/12/13 10:31:07 tobias Exp $ */
/*
* patch - a program to apply diffs to original files
return rv;
}
+/*
+ * Allocate a unique area for a string. Call fatal if out of memory.
+ */
+char *
+xstrdup(const char *s)
+{
+ char *rv;
+
+ if (!s)
+ s = "Oops";
+ rv = strdup(s);
+ if (rv == NULL)
+ fatal("out of memory\n");
+ return rv;
+}
+
/*
* Vanilla terminal output (buffered).
*/
-/* $OpenBSD: util.h,v 1.15 2005/06/20 07:14:06 otto Exp $ */
+/* $OpenBSD: util.h,v 1.16 2014/12/13 10:31:07 tobias Exp $ */
/*
* patch - a program to apply diffs to original files
void ask(const char *, ...)
__attribute__((__format__(__printf__, 1, 2)));
char *savestr(const char *);
+char *xstrdup(const char *);
void set_signals(int);
void ignore_signals(void);
void makedirs(const char *, bool);