minix patch port

This commit is contained in:
Ben Gras
2010-06-22 00:41:23 +00:00
parent f50f1bf7d6
commit 4269db3991
9 changed files with 42 additions and 17 deletions
+14 -5
View File
@@ -31,7 +31,6 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: patch.c,v 1.27 2008/09/19 18:33:34 joerg Exp $");
#include <sys/types.h>
#include <sys/stat.h>
@@ -156,36 +155,46 @@ main(int argc, char *argv[])
LINENUM where = 0, newwhere, fuzz, mymaxfuzz;
const char *tmpdir;
char *v;
int alloclen;
setbuf(stderr, serrbuf);
for (i = 0; i < MAXFILEC; i++)
filearg[i] = NULL;
/* Cons up the names of the temporary files. */
if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
tmpdir = _PATH_TMP;
for (i = strlen(tmpdir) - 1; i > 0 && tmpdir[i] == '/'; i--)
;
i++;
if (asprintf(&TMPOUTNAME, "%.*s/patchoXXXXXXXXXX", i, tmpdir) == -1)
alloclen = i + 100;
#define TMPALLOC(var) if(!(var = malloc(alloclen))) { fatal(#var); exit(1); }
TMPALLOC(TMPOUTNAME);
TMPALLOC(TMPINNAME);
TMPALLOC(TMPREJNAME);
TMPALLOC(TMPPATNAME);
if (snprintf(TMPOUTNAME, alloclen, "%.*s/patchoXXXXXXXXXX", i, tmpdir) == -1)
fatal("cannot allocate memory");
if ((fd = mkstemp(TMPOUTNAME)) < 0)
pfatal("can't create %s", TMPOUTNAME);
close(fd);
if (asprintf(&TMPINNAME, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
if (snprintf(TMPINNAME, alloclen, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
fatal("cannot allocate memory");
if ((fd = mkstemp(TMPINNAME)) < 0)
pfatal("can't create %s", TMPINNAME);
close(fd);
if (asprintf(&TMPREJNAME, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
if (snprintf(TMPREJNAME, alloclen, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
fatal("cannot allocate memory");
if ((fd = mkstemp(TMPREJNAME)) < 0)
pfatal("can't create %s", TMPREJNAME);
close(fd);
if (asprintf(&TMPPATNAME, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
if (snprintf(TMPPATNAME, alloclen, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
fatal("cannot allocate memory");
if ((fd = mkstemp(TMPPATNAME)) < 0)
pfatal("can't create %s", TMPPATNAME);