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

View file

@ -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 \

View file

@ -5,4 +5,4 @@
PROG= patch
SRCS= patch.c pch.c inp.c util.c backupfile.c mkpath.c
.include <bsd.prog.mk>
.include <minix.prog.mk>

View file

@ -22,7 +22,6 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: backupfile.c,v 1.14 2008/09/19 18:33:34 joerg Exp $");
#include <ctype.h>
#include <dirent.h>
@ -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;
}

View file

@ -31,7 +31,6 @@
*/
#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/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 <string.h>
#include <unistd.h>
#include <fcntl.h>
#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. */

View file

@ -34,7 +34,6 @@
*/
#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/stat.h>

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);

View file

@ -9,6 +9,6 @@
* on July 29, 2003.
*/
#include <paths.h>
#include <minix/paths.h>
#define _PATH_ED "/bin/ed"

View file

@ -31,7 +31,6 @@
*/
#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/stat.h>

View file

@ -31,7 +31,6 @@
*/
#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/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 <fcntl.h>
#include <libgen.h>
#include <paths.h>
#include <minix/paths.h>
#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>