minix patch port
This commit is contained in:
parent
f50f1bf7d6
commit
4269db3991
|
@ -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 \
|
lpd ls lspci M m4 mail make MAKEDEV makewhatis man \
|
||||||
mdb mesg mined mkdep mkdir mkdist mkfifo mkfs mknod \
|
mdb mesg mined mkdep mkdir mkdist mkfifo mkfs mknod \
|
||||||
mkproto modem mount mt netconf newroot nice nm nohup \
|
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 \
|
ping postinstall poweroff pr prep printf printroot \
|
||||||
profile progressbar proto pr_routes ps pwd pwdauth \
|
profile progressbar proto pr_routes ps pwd pwdauth \
|
||||||
ramdisk rarpd rawspeed rcp rdate readall readclock \
|
ramdisk rarpd rawspeed rcp rdate readall readclock \
|
||||||
|
|
|
@ -5,4 +5,4 @@
|
||||||
PROG= patch
|
PROG= patch
|
||||||
SRCS= patch.c pch.c inp.c util.c backupfile.c mkpath.c
|
SRCS= patch.c pch.c inp.c util.c backupfile.c mkpath.c
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <minix.prog.mk>
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__RCSID("$NetBSD: backupfile.c,v 1.14 2008/09/19 18:33:34 joerg Exp $");
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
@ -114,7 +113,7 @@ max_backup_version(const char *file, const char *dir)
|
||||||
file_name_length = strlen(file);
|
file_name_length = strlen(file);
|
||||||
|
|
||||||
while ((dp = readdir(dirp)) != NULL) {
|
while ((dp = readdir(dirp)) != NULL) {
|
||||||
if (dp->d_namlen <= file_name_length)
|
if (strlen(dp->d_name) <= file_name_length)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
this_version = version_number(file, dp->d_name, file_name_length);
|
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)
|
make_version_name(const char *file, int version)
|
||||||
{
|
{
|
||||||
char *backup_name;
|
char *backup_name;
|
||||||
|
int len = strlen(file)+20;
|
||||||
|
|
||||||
if (asprintf(&backup_name, "%s.~%d~", file, version) == -1)
|
if(!(backup_name = malloc(len)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (snprintf(backup_name, len, "%s.~%d~", file, version) == -1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return backup_name;
|
return backup_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,9 +172,14 @@ static char *
|
||||||
concat(const char *str1, const char *str2)
|
concat(const char *str1, const char *str2)
|
||||||
{
|
{
|
||||||
char *newstr;
|
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;
|
return NULL;
|
||||||
|
|
||||||
|
if (snprintf(newstr, len, "%s%s", str1, str2) == -1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return newstr;
|
return newstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__RCSID("$NetBSD: inp.c,v 1.19 2008/09/19 18:33:34 joerg Exp $");
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
@ -46,6 +45,7 @@ __RCSID("$NetBSD: inp.c,v 1.19 2008/09/19 18:33:34 joerg Exp $");
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "util.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 off_t i_size; /* size of the input file */
|
||||||
static char *i_womp; /* plan a buffer for entire file */
|
static char *i_womp; /* plan a buffer for entire file */
|
||||||
static char **i_ptr; /* pointers to lines in i_womp */
|
static char **i_ptr; /* pointers to lines in i_womp */
|
||||||
|
#if 0
|
||||||
static char empty_line[] = { '\0' };
|
static char empty_line[] = { '\0' };
|
||||||
|
#endif
|
||||||
|
|
||||||
static int tifd = -1; /* plan b virtual string array */
|
static int tifd = -1; /* plan b virtual string array */
|
||||||
static char *tibuf[2]; /* plan b buffers */
|
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 int tireclen; /* length of records in tmp file */
|
||||||
|
|
||||||
static bool rev_in_string(const char *);
|
static bool rev_in_string(const char *);
|
||||||
|
#if 0
|
||||||
static bool reallocate_lines(size_t *);
|
static bool reallocate_lines(size_t *);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* returns false if insufficient memory */
|
/* returns false if insufficient memory */
|
||||||
static bool plan_a(const char *);
|
static bool plan_a(const char *);
|
||||||
|
@ -112,6 +116,7 @@ scan_input(const char *filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static bool
|
static bool
|
||||||
reallocate_lines(size_t *lines_allocated)
|
reallocate_lines(size_t *lines_allocated)
|
||||||
{
|
{
|
||||||
|
@ -132,12 +137,16 @@ reallocate_lines(size_t *lines_allocated)
|
||||||
i_ptr = p;
|
i_ptr = p;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Try keeping everything in memory. */
|
/* Try keeping everything in memory. */
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
plan_a(const char *filename)
|
plan_a(const char *filename)
|
||||||
{
|
{
|
||||||
|
#ifdef __minix
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
int ifd, statfailed;
|
int ifd, statfailed;
|
||||||
char *p, *s, lbuf[MAXLINELEN];
|
char *p, *s, lbuf[MAXLINELEN];
|
||||||
struct stat filestat;
|
struct stat filestat;
|
||||||
|
@ -343,6 +352,7 @@ plan_a(const char *filename)
|
||||||
revision);
|
revision);
|
||||||
}
|
}
|
||||||
return true; /* plan a will work */
|
return true; /* plan a will work */
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep (virtually) nothing in memory. */
|
/* Keep (virtually) nothing in memory. */
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__RCSID("$NetBSD: mkpath.c,v 1.1 2008/09/19 18:33:34 joerg Exp $");
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#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/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -156,36 +155,46 @@ main(int argc, char *argv[])
|
||||||
LINENUM where = 0, newwhere, fuzz, mymaxfuzz;
|
LINENUM where = 0, newwhere, fuzz, mymaxfuzz;
|
||||||
const char *tmpdir;
|
const char *tmpdir;
|
||||||
char *v;
|
char *v;
|
||||||
|
int alloclen;
|
||||||
|
|
||||||
setbuf(stderr, serrbuf);
|
setbuf(stderr, serrbuf);
|
||||||
for (i = 0; i < MAXFILEC; i++)
|
for (i = 0; i < MAXFILEC; i++)
|
||||||
filearg[i] = NULL;
|
filearg[i] = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* Cons up the names of the temporary files. */
|
/* Cons up the names of the temporary files. */
|
||||||
if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
|
if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
|
||||||
tmpdir = _PATH_TMP;
|
tmpdir = _PATH_TMP;
|
||||||
for (i = strlen(tmpdir) - 1; i > 0 && tmpdir[i] == '/'; i--)
|
for (i = strlen(tmpdir) - 1; i > 0 && tmpdir[i] == '/'; 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");
|
fatal("cannot allocate memory");
|
||||||
if ((fd = mkstemp(TMPOUTNAME)) < 0)
|
if ((fd = mkstemp(TMPOUTNAME)) < 0)
|
||||||
pfatal("can't create %s", TMPOUTNAME);
|
pfatal("can't create %s", TMPOUTNAME);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (asprintf(&TMPINNAME, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
|
if (snprintf(TMPINNAME, alloclen, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
|
||||||
fatal("cannot allocate memory");
|
fatal("cannot allocate memory");
|
||||||
if ((fd = mkstemp(TMPINNAME)) < 0)
|
if ((fd = mkstemp(TMPINNAME)) < 0)
|
||||||
pfatal("can't create %s", TMPINNAME);
|
pfatal("can't create %s", TMPINNAME);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (asprintf(&TMPREJNAME, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
|
if (snprintf(TMPREJNAME, alloclen, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
|
||||||
fatal("cannot allocate memory");
|
fatal("cannot allocate memory");
|
||||||
if ((fd = mkstemp(TMPREJNAME)) < 0)
|
if ((fd = mkstemp(TMPREJNAME)) < 0)
|
||||||
pfatal("can't create %s", TMPREJNAME);
|
pfatal("can't create %s", TMPREJNAME);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (asprintf(&TMPPATNAME, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
|
if (snprintf(TMPPATNAME, alloclen, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
|
||||||
fatal("cannot allocate memory");
|
fatal("cannot allocate memory");
|
||||||
if ((fd = mkstemp(TMPPATNAME)) < 0)
|
if ((fd = mkstemp(TMPPATNAME)) < 0)
|
||||||
pfatal("can't create %s", TMPPATNAME);
|
pfatal("can't create %s", TMPPATNAME);
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
* on July 29, 2003.
|
* on July 29, 2003.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <paths.h>
|
#include <minix/paths.h>
|
||||||
|
|
||||||
#define _PATH_ED "/bin/ed"
|
#define _PATH_ED "/bin/ed"
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__RCSID("$NetBSD: pch.c,v 1.23 2008/09/19 18:33:34 joerg Exp $");
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__RCSID("$NetBSD: util.c,v 1.24 2008/09/19 18:33:34 joerg Exp $");
|
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -40,7 +39,7 @@ __RCSID("$NetBSD: util.c,v 1.24 2008/09/19 18:33:34 joerg Exp $");
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <paths.h>
|
#include <minix/paths.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
Loading…
Reference in a new issue