From: Ben Gras Date: Tue, 22 Jun 2010 00:41:23 +0000 (+0000) Subject: minix patch port X-Git-Tag: v3.1.8~416 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.dnssec-keyfromlabel.html?a=commitdiff_plain;h=4269db3991688bf52078039d01a9b32f551cef81;p=minix.git minix patch port --- diff --git a/commands/Makefile b/commands/Makefile index 25ec9e339..42f26b6b7 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -19,7 +19,7 @@ SUBDIR= aal add_route adduser advent arp ash at autil awk \ lpd ls lspci M m4 mail make MAKEDEV makewhatis man \ mdb mesg mined mkdep mkdir mkdist mkfifo mkfs mknod \ mkproto modem mount mt netconf newroot nice nm nohup \ - nonamed od packit packman passwd paste pax \ + nonamed od packit packman passwd paste patch pax \ ping postinstall poweroff pr prep printf printroot \ profile progressbar proto pr_routes ps pwd pwdauth \ ramdisk rarpd rawspeed rcp rdate readall readclock \ diff --git a/commands/patch/Makefile b/commands/patch/Makefile index 07fa57688..7485f1185 100644 --- a/commands/patch/Makefile +++ b/commands/patch/Makefile @@ -5,4 +5,4 @@ PROG= patch SRCS= patch.c pch.c inp.c util.c backupfile.c mkpath.c -.include +.include diff --git a/commands/patch/backupfile.c b/commands/patch/backupfile.c index 59a2de975..f4574ad45 100644 --- a/commands/patch/backupfile.c +++ b/commands/patch/backupfile.c @@ -22,7 +22,6 @@ */ #include -__RCSID("$NetBSD: backupfile.c,v 1.14 2008/09/19 18:33:34 joerg Exp $"); #include #include @@ -114,7 +113,7 @@ max_backup_version(const char *file, const char *dir) file_name_length = strlen(file); while ((dp = readdir(dirp)) != NULL) { - if (dp->d_namlen <= file_name_length) + if (strlen(dp->d_name) <= file_name_length) continue; this_version = version_number(file, dp->d_name, file_name_length); @@ -133,9 +132,14 @@ static char * make_version_name(const char *file, int version) { char *backup_name; + int len = strlen(file)+20; - if (asprintf(&backup_name, "%s.~%d~", file, version) == -1) + if(!(backup_name = malloc(len))) return NULL; + + if (snprintf(backup_name, len, "%s.~%d~", file, version) == -1) + return NULL; + return backup_name; } @@ -168,9 +172,14 @@ static char * concat(const char *str1, const char *str2) { char *newstr; + int len = strlen(str1) + strlen(str2) + 1; - if (asprintf(&newstr, "%s%s", str1, str2) == -1) + if(!(newstr = malloc(strlen(str1) + strlen(str2) + 1))) return NULL; + + if (snprintf(newstr, len, "%s%s", str1, str2) == -1) + return NULL; + return newstr; } diff --git a/commands/patch/inp.c b/commands/patch/inp.c index 7bb2de110..573a128cf 100644 --- a/commands/patch/inp.c +++ b/commands/patch/inp.c @@ -31,7 +31,6 @@ */ #include -__RCSID("$NetBSD: inp.c,v 1.19 2008/09/19 18:33:34 joerg Exp $"); #include #include @@ -46,6 +45,7 @@ __RCSID("$NetBSD: inp.c,v 1.19 2008/09/19 18:33:34 joerg Exp $"); #include #include #include +#include #include "common.h" #include "util.h" @@ -58,7 +58,9 @@ __RCSID("$NetBSD: inp.c,v 1.19 2008/09/19 18:33:34 joerg Exp $"); static off_t i_size; /* size of the input file */ static char *i_womp; /* plan a buffer for entire file */ static char **i_ptr; /* pointers to lines in i_womp */ +#if 0 static char empty_line[] = { '\0' }; +#endif static int tifd = -1; /* plan b virtual string array */ static char *tibuf[2]; /* plan b buffers */ @@ -67,7 +69,9 @@ static LINENUM lines_per_buf; /* how many lines per buffer */ static int tireclen; /* length of records in tmp file */ static bool rev_in_string(const char *); +#if 0 static bool reallocate_lines(size_t *); +#endif /* returns false if insufficient memory */ static bool plan_a(const char *); @@ -112,6 +116,7 @@ scan_input(const char *filename) } } +#if 0 static bool reallocate_lines(size_t *lines_allocated) { @@ -132,12 +137,16 @@ reallocate_lines(size_t *lines_allocated) i_ptr = p; return true; } +#endif /* Try keeping everything in memory. */ static bool plan_a(const char *filename) { +#ifdef __minix + return false; +#else int ifd, statfailed; char *p, *s, lbuf[MAXLINELEN]; struct stat filestat; @@ -343,6 +352,7 @@ plan_a(const char *filename) revision); } return true; /* plan a will work */ +#endif } /* Keep (virtually) nothing in memory. */ diff --git a/commands/patch/mkpath.c b/commands/patch/mkpath.c index 3d18036f9..3b5c2ca6a 100644 --- a/commands/patch/mkpath.c +++ b/commands/patch/mkpath.c @@ -34,7 +34,6 @@ */ #include -__RCSID("$NetBSD: mkpath.c,v 1.1 2008/09/19 18:33:34 joerg Exp $"); #include #include diff --git a/commands/patch/patch.c b/commands/patch/patch.c index 072a2e888..b5092d16b 100644 --- a/commands/patch/patch.c +++ b/commands/patch/patch.c @@ -31,7 +31,6 @@ */ #include -__RCSID("$NetBSD: patch.c,v 1.27 2008/09/19 18:33:34 joerg Exp $"); #include #include @@ -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); diff --git a/commands/patch/pathnames.h b/commands/patch/pathnames.h index e9d3ccbee..99182f300 100644 --- a/commands/patch/pathnames.h +++ b/commands/patch/pathnames.h @@ -9,6 +9,6 @@ * on July 29, 2003. */ -#include +#include #define _PATH_ED "/bin/ed" diff --git a/commands/patch/pch.c b/commands/patch/pch.c index 6dcf3aeef..d8d354d12 100644 --- a/commands/patch/pch.c +++ b/commands/patch/pch.c @@ -31,7 +31,6 @@ */ #include -__RCSID("$NetBSD: pch.c,v 1.23 2008/09/19 18:33:34 joerg Exp $"); #include #include diff --git a/commands/patch/util.c b/commands/patch/util.c index bc5b2607a..0e2032ab6 100644 --- a/commands/patch/util.c +++ b/commands/patch/util.c @@ -31,7 +31,6 @@ */ #include -__RCSID("$NetBSD: util.c,v 1.24 2008/09/19 18:33:34 joerg Exp $"); #include #include @@ -40,7 +39,7 @@ __RCSID("$NetBSD: util.c,v 1.24 2008/09/19 18:33:34 joerg Exp $"); #include #include #include -#include +#include #include #include #include