updating bsd patch, moving it back to usr.bin
Change-Id: Ibc356c932693729ebf86cc4cc51aeca65163af9b
This commit is contained in:
parent
18e90974b2
commit
757e83288a
|
@ -17,7 +17,7 @@ SUBDIR= add_route arp ash at backup btrace \
|
||||||
lpd lspci mail MAKEDEV \
|
lpd lspci mail MAKEDEV \
|
||||||
mined \
|
mined \
|
||||||
mount mt netconf \
|
mount mt netconf \
|
||||||
nonamed patch \
|
nonamed \
|
||||||
ping postinstall prep printroot \
|
ping postinstall prep printroot \
|
||||||
profile progressbar pr_routes ps pwdauth \
|
profile progressbar pr_routes ps pwdauth \
|
||||||
ramdisk rarpd rawspeed rcp readclock \
|
ramdisk rarpd rawspeed rcp readclock \
|
||||||
|
|
|
@ -19,7 +19,7 @@ SUBDIR= asa \
|
||||||
mkdep mkfifo mkstr mktemp \
|
mkdep mkfifo mkstr mktemp \
|
||||||
msgc \
|
msgc \
|
||||||
nbperf newgrp nice nl nohup \
|
nbperf newgrp nice nl nohup \
|
||||||
passwd paste pathchk pr \
|
passwd paste patch pathchk pr \
|
||||||
printenv printf pwhash \
|
printenv printf pwhash \
|
||||||
renice rev \
|
renice rev \
|
||||||
\
|
\
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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>
|
||||||
|
@ -113,7 +114,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 (strlen(dp->d_name) <= file_name_length)
|
if (dp->d_namlen <= 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);
|
||||||
|
@ -132,14 +133,9 @@ 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(!(backup_name = malloc(len)))
|
if (asprintf(&backup_name, "%s.~%d~", file, version) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (snprintf(backup_name, len, "%s.~%d~", file, version) == -1)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return backup_name;
|
return backup_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,14 +168,9 @@ 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(!(newstr = malloc(strlen(str1) + strlen(str2) + 1)))
|
if (asprintf(&newstr, "%s%s", str1, str2) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (snprintf(newstr, len, "%s%s", str1, str2) == -1)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return newstr;
|
return newstr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* $OpenBSD: inp.c,v 1.34 2006/03/11 19:41:30 otto Exp $
|
* $OpenBSD: inp.c,v 1.34 2006/03/11 19:41:30 otto Exp $
|
||||||
* $DragonFly: src/usr.bin/patch/inp.c,v 1.6 2007/09/29 23:11:10 swildner Exp $
|
* $DragonFly: src/usr.bin/patch/inp.c,v 1.6 2007/09/29 23:11:10 swildner Exp $
|
||||||
* $NetBSD: inp.c,v 1.19 2008/09/19 18:33:34 joerg Exp $
|
* $NetBSD: inp.c,v 1.23 2009/10/21 17:16:11 joerg Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -31,6 +31,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
__RCSID("$NetBSD: inp.c,v 1.23 2009/10/21 17:16:11 joerg Exp $");
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
@ -38,6 +39,7 @@
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
@ -45,7 +47,6 @@
|
||||||
#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"
|
||||||
|
@ -74,24 +75,6 @@ static bool plan_a(const char *);
|
||||||
|
|
||||||
static void plan_b(const char *);
|
static void plan_b(const char *);
|
||||||
|
|
||||||
static int readfile(int fd, char *buf, size_t s)
|
|
||||||
{
|
|
||||||
int ntoread, nread;
|
|
||||||
|
|
||||||
ntoread = s;
|
|
||||||
nread = 0;
|
|
||||||
|
|
||||||
while(ntoread > 0) {
|
|
||||||
if((nread = read(fd, buf, ntoread)) < 0) {
|
|
||||||
return nread;
|
|
||||||
}
|
|
||||||
buf += nread;
|
|
||||||
ntoread -= nread;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* New patch--prepare to edit another file. */
|
/* New patch--prepare to edit another file. */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -102,11 +85,7 @@ re_input(void)
|
||||||
free(i_ptr);
|
free(i_ptr);
|
||||||
i_ptr = NULL;
|
i_ptr = NULL;
|
||||||
if (i_womp != NULL) {
|
if (i_womp != NULL) {
|
||||||
#ifndef __minix
|
|
||||||
munmap(i_womp, i_size);
|
munmap(i_womp, i_size);
|
||||||
#else
|
|
||||||
free(i_womp);
|
|
||||||
#endif
|
|
||||||
i_womp = NULL;
|
i_womp = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -143,11 +122,7 @@ reallocate_lines(size_t *lines_allocated)
|
||||||
new_size = *lines_allocated * 3 / 2;
|
new_size = *lines_allocated * 3 / 2;
|
||||||
p = realloc(i_ptr, (new_size + 2) * sizeof(char *));
|
p = realloc(i_ptr, (new_size + 2) * sizeof(char *));
|
||||||
if (p == NULL) { /* shucks, it was a near thing */
|
if (p == NULL) { /* shucks, it was a near thing */
|
||||||
#ifndef __minix
|
|
||||||
munmap(i_womp, i_size);
|
munmap(i_womp, i_size);
|
||||||
#else
|
|
||||||
free(i_womp);
|
|
||||||
#endif
|
|
||||||
i_womp = NULL;
|
i_womp = NULL;
|
||||||
free(i_ptr);
|
free(i_ptr);
|
||||||
i_ptr = NULL;
|
i_ptr = NULL;
|
||||||
|
@ -279,44 +254,30 @@ plan_a(const char *filename)
|
||||||
out_of_mem = false;
|
out_of_mem = false;
|
||||||
return false; /* force plan b because plan a bombed */
|
return false; /* force plan b because plan a bombed */
|
||||||
}
|
}
|
||||||
#ifndef __minix
|
if ((uintmax_t)i_size > (uintmax_t)SIZE_MAX) {
|
||||||
if (i_size > SIZE_MAX) {
|
|
||||||
say("block too large to mmap\n");
|
say("block too large to mmap\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if ((ifd = open(filename, O_RDONLY)) < 0)
|
if ((ifd = open(filename, O_RDONLY)) < 0)
|
||||||
pfatal("can't open file %s", filename);
|
pfatal("can't open file %s", filename);
|
||||||
|
|
||||||
#ifndef __minix
|
if (i_size) {
|
||||||
i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0);
|
i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0);
|
||||||
if (i_womp == MAP_FAILED) {
|
if (i_womp == MAP_FAILED) {
|
||||||
perror("mmap failed");
|
perror("mmap failed");
|
||||||
|
i_womp = NULL;
|
||||||
|
close(ifd);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
i_womp = NULL;
|
i_womp = NULL;
|
||||||
close(ifd);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
i_womp = malloc(i_size);
|
|
||||||
if(i_size && i_womp == NULL) {
|
|
||||||
fprintf(stderr, "Malloc failed.\n");
|
|
||||||
i_womp = NULL;
|
|
||||||
close(ifd);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(readfile(ifd, i_womp, i_size) < 0) {
|
|
||||||
perror("Readfile failed.");
|
|
||||||
i_womp = NULL;
|
|
||||||
close(ifd);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
close(ifd);
|
close(ifd);
|
||||||
#ifndef __minix
|
#if !defined(__minix)
|
||||||
if (i_size)
|
if (i_size)
|
||||||
madvise(i_womp, i_size, MADV_SEQUENTIAL);
|
madvise(i_womp, i_size, MADV_SEQUENTIAL);
|
||||||
#endif
|
#endif /* !defined(__minix) */
|
||||||
|
|
||||||
/* estimate the number of lines */
|
/* estimate the number of lines */
|
||||||
lines_allocated = i_size / 25;
|
lines_allocated = i_size / 25;
|
||||||
|
@ -349,11 +310,7 @@ plan_a(const char *filename)
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
free(i_ptr);
|
free(i_ptr);
|
||||||
i_ptr = NULL;
|
i_ptr = NULL;
|
||||||
#ifndef __minix
|
|
||||||
munmap(i_womp, i_size);
|
munmap(i_womp, i_size);
|
||||||
#else
|
|
||||||
free(i_womp);
|
|
||||||
#endif
|
|
||||||
i_womp = NULL;
|
i_womp = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
|
@ -34,6 +34,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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>
|
|
@ -1,6 +1,6 @@
|
||||||
.\" $OpenBSD: patch.1,v 1.22 2008/06/06 20:44:00 jmc Exp $
|
.\" $OpenBSD: patch.1,v 1.22 2008/06/06 20:44:00 jmc Exp $
|
||||||
.\" $DragonFly: src/usr.bin/patch/patch.1,v 1.10 2008/08/18 19:15:55 joerg Exp $
|
.\" $DragonFly: src/usr.bin/patch/patch.1,v 1.10 2008/08/18 19:15:55 joerg Exp $
|
||||||
.\" $NetBSD: patch.1,v 1.13 2008/09/19 18:33:34 joerg Exp $
|
.\" $NetBSD: patch.1,v 1.16 2013/01/29 09:30:11 wiz Exp $
|
||||||
.\" Copyright 1986, Larry Wall
|
.\" Copyright 1986, Larry Wall
|
||||||
.\"
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -29,7 +29,6 @@
|
||||||
.Nd apply a diff file to an original
|
.Nd apply a diff file to an original
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Bk -words
|
|
||||||
.Op Fl bCcEeflNnRstuv
|
.Op Fl bCcEeflNnRstuv
|
||||||
.Op Fl B Ar backup-prefix
|
.Op Fl B Ar backup-prefix
|
||||||
.Op Fl D Ar symbol
|
.Op Fl D Ar symbol
|
||||||
|
@ -44,7 +43,6 @@
|
||||||
.Op Fl z Ar backup-ext
|
.Op Fl z Ar backup-ext
|
||||||
.Op Fl Fl posix
|
.Op Fl Fl posix
|
||||||
.Op Ar origfile Op Ar patchfile
|
.Op Ar origfile Op Ar patchfile
|
||||||
.Ek
|
|
||||||
.Nm
|
.Nm
|
||||||
.Pf \*(Lt Ar patchfile
|
.Pf \*(Lt Ar patchfile
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
|
@ -87,10 +85,7 @@ below).
|
||||||
.Pp
|
.Pp
|
||||||
The options are as follows:
|
The options are as follows:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Xo
|
.It Fl B Ar backup-prefix , Fl Fl prefix Ar backup-prefix
|
||||||
.Fl B Ar backup-prefix ,
|
|
||||||
.Fl Fl prefix Ar backup-prefix
|
|
||||||
.Xc
|
|
||||||
Causes the next argument to be interpreted as a prefix to the backup file
|
Causes the next argument to be interpreted as a prefix to the backup file
|
||||||
name.
|
name.
|
||||||
If this argument is specified, any argument to
|
If this argument is specified, any argument to
|
||||||
|
@ -113,10 +108,7 @@ Checks that the patch would apply cleanly, but does not modify anything.
|
||||||
Forces
|
Forces
|
||||||
.Nm
|
.Nm
|
||||||
to interpret the patch file as a context diff.
|
to interpret the patch file as a context diff.
|
||||||
.It Xo
|
.It Fl D Ar symbol , Fl Fl ifdef Ar symbol
|
||||||
.Fl D Ar symbol ,
|
|
||||||
.Fl Fl ifdef Ar symbol
|
|
||||||
.Xc
|
|
||||||
Causes
|
Causes
|
||||||
.Nm
|
.Nm
|
||||||
to use the
|
to use the
|
||||||
|
@ -126,10 +118,7 @@ The argument following will be used as the differentiating symbol.
|
||||||
Note that, unlike the C compiler, there must be a space between the
|
Note that, unlike the C compiler, there must be a space between the
|
||||||
.Fl D
|
.Fl D
|
||||||
and the argument.
|
and the argument.
|
||||||
.It Xo
|
.It Fl d Ar directory , Fl Fl directory Ar directory
|
||||||
.Fl d Ar directory ,
|
|
||||||
.Fl Fl directory Ar directory
|
|
||||||
.Xc
|
|
||||||
Causes
|
Causes
|
||||||
.Nm
|
.Nm
|
||||||
to interpret the next argument as a directory,
|
to interpret the next argument as a directory,
|
||||||
|
@ -145,10 +134,7 @@ Forces
|
||||||
to interpret the patch file as an
|
to interpret the patch file as an
|
||||||
.Xr ed 1
|
.Xr ed 1
|
||||||
script.
|
script.
|
||||||
.It Xo
|
.It Fl F Ar max-fuzz , Fl Fl fuzz Ar max-fuzz
|
||||||
.Fl F Ar max-fuzz ,
|
|
||||||
.Fl Fl fuzz Ar max-fuzz
|
|
||||||
.Xc
|
|
||||||
Sets the maximum fuzz factor.
|
Sets the maximum fuzz factor.
|
||||||
This option only applies to context diffs, and causes
|
This option only applies to context diffs, and causes
|
||||||
.Nm
|
.Nm
|
||||||
|
@ -170,12 +156,9 @@ and assume that patches are not reversed even if they look like they are.
|
||||||
This option does not suppress commentary; use
|
This option does not suppress commentary; use
|
||||||
.Fl s
|
.Fl s
|
||||||
for that.
|
for that.
|
||||||
.It Xo
|
.It Fl i Ar patchfile , Fl Fl input Ar patchfile
|
||||||
.Fl i Ar patchfile ,
|
|
||||||
.Fl Fl input Ar patchfile
|
|
||||||
.Xc
|
|
||||||
Causes the next argument to be interpreted as the input file name
|
Causes the next argument to be interpreted as the input file name
|
||||||
(i.e. a patchfile).
|
(i.e., a patchfile).
|
||||||
This option may be specified multiple times.
|
This option may be specified multiple times.
|
||||||
.It Fl l , Fl Fl ignore-whitespace
|
.It Fl l , Fl Fl ignore-whitespace
|
||||||
Causes the pattern matching to be done loosely, in case the tabs and
|
Causes the pattern matching to be done loosely, in case the tabs and
|
||||||
|
@ -194,15 +177,9 @@ See also
|
||||||
Forces
|
Forces
|
||||||
.Nm
|
.Nm
|
||||||
to interpret the patch file as a normal diff.
|
to interpret the patch file as a normal diff.
|
||||||
.It Xo
|
.It Fl o Ar out-file , Fl Fl output Ar out-file
|
||||||
.Fl o Ar out-file ,
|
|
||||||
.Fl Fl output Ar out-file
|
|
||||||
.Xc
|
|
||||||
Causes the next argument to be interpreted as the output file name.
|
Causes the next argument to be interpreted as the output file name.
|
||||||
.It Xo
|
.It Fl p Ar strip-count , Fl Fl strip Ar strip-count
|
||||||
.Fl p Ar strip-count ,
|
|
||||||
.Fl Fl strip Ar strip-count
|
|
||||||
.Xc
|
|
||||||
Sets the pathname strip count,
|
Sets the pathname strip count,
|
||||||
which controls how pathnames found in the patch file are treated,
|
which controls how pathnames found in the patch file are treated,
|
||||||
in case you keep your files in a different directory than the person who sent
|
in case you keep your files in a different directory than the person who sent
|
||||||
|
@ -263,21 +240,15 @@ If it can, you will be asked if you want to have the
|
||||||
option set.
|
option set.
|
||||||
If it can't, the patch will continue to be applied normally.
|
If it can't, the patch will continue to be applied normally.
|
||||||
(Note: this method cannot detect a reversed patch if it is a normal diff
|
(Note: this method cannot detect a reversed patch if it is a normal diff
|
||||||
and if the first command is an append (i.e. it should have been a delete)
|
and if the first command is an append (i.e., it should have been a delete)
|
||||||
since appends always succeed, due to the fact that a null context will match
|
since appends always succeed, due to the fact that a null context will match
|
||||||
anywhere.
|
anywhere.
|
||||||
Luckily, most patches add or change lines rather than delete them, so most
|
Luckily, most patches add or change lines rather than delete them, so most
|
||||||
reversed normal diffs will begin with a delete, which will fail, triggering
|
reversed normal diffs will begin with a delete, which will fail, triggering
|
||||||
the heuristic.)
|
the heuristic.)
|
||||||
.It Xo
|
.It Fl r Ar rej-name , Fl Fl reject-file Ar rej-name
|
||||||
.Fl r Ar rej-name ,
|
|
||||||
.Fl Fl reject-file Ar rej-name
|
|
||||||
.Xc
|
|
||||||
Causes the next argument to be interpreted as the reject file name.
|
Causes the next argument to be interpreted as the reject file name.
|
||||||
.It Xo
|
.It Fl s , Fl Fl quiet , Fl Fl silent
|
||||||
.Fl s , Fl Fl quiet ,
|
|
||||||
.Fl Fl silent
|
|
||||||
.Xc
|
|
||||||
Makes
|
Makes
|
||||||
.Nm
|
.Nm
|
||||||
do its work silently, unless an error occurs.
|
do its work silently, unless an error occurs.
|
||||||
|
@ -295,10 +266,7 @@ and assume that patches are reversed if they look like they are.
|
||||||
Forces
|
Forces
|
||||||
.Nm
|
.Nm
|
||||||
to interpret the patch file as a unified context diff (a unidiff).
|
to interpret the patch file as a unified context diff (a unidiff).
|
||||||
.It Xo
|
.It Fl V Cm t | nil | never , Fl Fl version-control Cm t | nil | never
|
||||||
.Fl V Cm t | nil | never ,
|
|
||||||
.Fl Fl version-control Cm t | nil | never
|
|
||||||
.Xc
|
|
||||||
Causes the next argument to be interpreted as a method for creating
|
Causes the next argument to be interpreted as a method for creating
|
||||||
backup file names.
|
backup file names.
|
||||||
The type of backups made can also be given in the
|
The type of backups made can also be given in the
|
||||||
|
@ -333,17 +301,11 @@ Always make simple backups.
|
||||||
Causes
|
Causes
|
||||||
.Nm
|
.Nm
|
||||||
to print out its revision header and patch level.
|
to print out its revision header and patch level.
|
||||||
.It Xo
|
.It Fl x Ar number , Fl Fl debug Ar number
|
||||||
.Fl x Ar number ,
|
|
||||||
.Fl Fl debug Ar number
|
|
||||||
.Xc
|
|
||||||
Sets internal debugging flags, and is of interest only to
|
Sets internal debugging flags, and is of interest only to
|
||||||
.Nm
|
.Nm
|
||||||
patchers.
|
patchers.
|
||||||
.It Xo
|
.It Fl z Ar backup-ext , Fl Fl suffix Ar backup-ext
|
||||||
.Fl z Ar backup-ext ,
|
|
||||||
.Fl Fl suffix Ar backup-ext
|
|
||||||
.Xc
|
|
||||||
Causes the next argument to be interpreted as the backup extension, to be
|
Causes the next argument to be interpreted as the backup extension, to be
|
||||||
used in place of
|
used in place of
|
||||||
.Qq .orig .
|
.Qq .orig .
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* $OpenBSD: patch.c,v 1.45 2007/04/18 21:52:24 sobrado Exp $
|
* $OpenBSD: patch.c,v 1.45 2007/04/18 21:52:24 sobrado Exp $
|
||||||
* $DragonFly: src/usr.bin/patch/patch.c,v 1.10 2008/08/10 23:39:56 joerg Exp $
|
* $DragonFly: src/usr.bin/patch/patch.c,v 1.10 2008/08/10 23:39:56 joerg Exp $
|
||||||
* $NetBSD: patch.c,v 1.27 2008/09/19 18:33:34 joerg Exp $
|
* $NetBSD: patch.c,v 1.29 2011/09/06 18:25:14 joerg Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -31,6 +31,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
__RCSID("$NetBSD: patch.c,v 1.29 2011/09/06 18:25:14 joerg Exp $");
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -105,7 +106,7 @@ static bool spew_output(void);
|
||||||
static void dump_line(LINENUM, bool);
|
static void dump_line(LINENUM, bool);
|
||||||
static bool patch_match(LINENUM, LINENUM, LINENUM);
|
static bool patch_match(LINENUM, LINENUM, LINENUM);
|
||||||
static bool similar(const char *, const char *, int);
|
static bool similar(const char *, const char *, int);
|
||||||
static void usage(void);
|
__dead static void usage(void);
|
||||||
|
|
||||||
/* true if -E was specified on command line. */
|
/* true if -E was specified on command line. */
|
||||||
static bool remove_empty_files = false;
|
static bool remove_empty_files = false;
|
||||||
|
@ -155,46 +156,36 @@ 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 (snprintf(TMPINNAME, alloclen, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
|
if (asprintf(&TMPINNAME, "%.*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 (snprintf(TMPREJNAME, alloclen, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
|
if (asprintf(&TMPREJNAME, "%.*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 (snprintf(TMPPATNAME, alloclen, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
|
if (asprintf(&TMPPATNAME, "%.*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);
|
||||||
|
@ -632,7 +623,7 @@ usage(void)
|
||||||
" [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]\n"
|
" [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]\n"
|
||||||
" [--posix] [origfile [patchfile]]\n"
|
" [--posix] [origfile [patchfile]]\n"
|
||||||
" patch <patchfile\n");
|
" patch <patchfile\n");
|
||||||
my_exit(EXIT_SUCCESS);
|
my_exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* $OpenBSD: pch.c,v 1.37 2007/09/02 15:19:33 deraadt Exp $
|
* $OpenBSD: pch.c,v 1.37 2007/09/02 15:19:33 deraadt Exp $
|
||||||
* $DragonFly: src/usr.bin/patch/pch.c,v 1.6 2008/08/10 23:35:40 joerg Exp $
|
* $DragonFly: src/usr.bin/patch/pch.c,v 1.6 2008/08/10 23:35:40 joerg Exp $
|
||||||
* $NetBSD: pch.c,v 1.23 2008/09/19 18:33:34 joerg Exp $
|
* $NetBSD: pch.c,v 1.25 2013/01/29 09:30:11 wiz Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -31,6 +31,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
__RCSID("$NetBSD: pch.c,v 1.25 2013/01/29 09:30:11 wiz Exp $");
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -447,7 +448,7 @@ skip_to(LINENUM file_pos, LINENUM file_line)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make this a function for better debugging. */
|
/* Make this a function for better debugging. */
|
||||||
static void
|
__dead static void
|
||||||
malformed(void)
|
malformed(void)
|
||||||
{
|
{
|
||||||
fatal("malformed patch at line %ld: %s", p_input_line, buf);
|
fatal("malformed patch at line %ld: %s", p_input_line, buf);
|
||||||
|
@ -455,7 +456,7 @@ malformed(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* True if the line has been discarded (i.e. it is a line saying
|
* True if the line has been discarded (i.e., it is a line saying
|
||||||
* "\ No newline at end of file".)
|
* "\ No newline at end of file".)
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* $OpenBSD: util.c,v 1.32 2006/03/11 19:41:30 otto Exp $
|
* $OpenBSD: util.c,v 1.32 2006/03/11 19:41:30 otto Exp $
|
||||||
* $DragonFly: src/usr.bin/patch/util.c,v 1.9 2007/09/29 23:11:10 swildner Exp $
|
* $DragonFly: src/usr.bin/patch/util.c,v 1.9 2007/09/29 23:11:10 swildner Exp $
|
||||||
* $NetBSD: util.c,v 1.24 2008/09/19 18:33:34 joerg Exp $
|
* $NetBSD: util.c,v 1.26 2010/10/02 19:31:14 wiz Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -31,6 +31,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
__RCSID("$NetBSD: util.c,v 1.26 2010/10/02 19:31:14 wiz Exp $");
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -325,8 +326,10 @@ makedirs(const char *filename, bool striplast)
|
||||||
|
|
||||||
if (striplast) {
|
if (striplast) {
|
||||||
char *s = strrchr(tmpbuf, '/');
|
char *s = strrchr(tmpbuf, '/');
|
||||||
if (s == NULL)
|
if (s == NULL) {
|
||||||
|
free(tmpbuf);
|
||||||
return; /* nothing to be done */
|
return; /* nothing to be done */
|
||||||
|
}
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
}
|
}
|
||||||
if (mkpath(tmpbuf) != 0)
|
if (mkpath(tmpbuf) != 0)
|
||||||
|
@ -415,7 +418,7 @@ checked_in(char *file)
|
||||||
void
|
void
|
||||||
version(void)
|
version(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Patch version 2.0-12u8-NetBSD\n");
|
printf("Patch version 2.0-12u8-NetBSD\n");
|
||||||
my_exit(EXIT_SUCCESS);
|
my_exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* $OpenBSD: util.h,v 1.15 2005/06/20 07:14:06 otto Exp $
|
* $OpenBSD: util.h,v 1.15 2005/06/20 07:14:06 otto Exp $
|
||||||
* $DragonFly: src/usr.bin/patch/util.h,v 1.2 2007/09/29 23:11:10 swildner Exp $
|
* $DragonFly: src/usr.bin/patch/util.h,v 1.2 2007/09/29 23:11:10 swildner Exp $
|
||||||
* $NetBSD: util.h,v 1.11 2008/09/19 18:33:34 joerg Exp $
|
* $NetBSD: util.h,v 1.12 2011/09/06 18:25:14 joerg Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -35,20 +35,16 @@ char *checked_in(char *);
|
||||||
int backup_file(const char *);
|
int backup_file(const char *);
|
||||||
int move_file(const char *, const char *);
|
int move_file(const char *, const char *);
|
||||||
int copy_file(const char *, const char *);
|
int copy_file(const char *, const char *);
|
||||||
void say(const char *, ...)
|
void say(const char *, ...) __printflike(1, 2);
|
||||||
__attribute__((__format__(__printf__, 1, 2)));
|
void fatal(const char *, ...) __printflike(1, 2) __dead;
|
||||||
void fatal(const char *, ...)
|
void pfatal(const char *, ...) __printflike(1, 2) __dead;
|
||||||
__attribute__((__format__(__printf__, 1, 2)));
|
void ask(const char *, ...) __printflike(1, 2);
|
||||||
void pfatal(const char *, ...)
|
|
||||||
__attribute__((__format__(__printf__, 1, 2)));
|
|
||||||
void ask(const char *, ...)
|
|
||||||
__attribute__((__format__(__printf__, 1, 2)));
|
|
||||||
char *savestr(const char *);
|
char *savestr(const char *);
|
||||||
void set_signals(int);
|
void set_signals(int);
|
||||||
void ignore_signals(void);
|
void ignore_signals(void);
|
||||||
void makedirs(const char *, bool);
|
void makedirs(const char *, bool);
|
||||||
void version(void);
|
void version(void) __dead;
|
||||||
void my_exit(int) __attribute__((noreturn));
|
void my_exit(int) __dead;
|
||||||
|
|
||||||
/* in mkpath.c */
|
/* in mkpath.c */
|
||||||
extern int mkpath(char *);
|
extern int mkpath(char *);
|
Loading…
Reference in a new issue