lpd lspci mail MAKEDEV \
mined \
mount mt netconf \
- nonamed patch \
+ nonamed \
ping postinstall prep printroot \
profile progressbar pr_routes ps pwdauth \
ramdisk rarpd rawspeed rcp readclock \
mkdep mkfifo mkstr mktemp \
msgc \
nbperf newgrp nice nl nohup \
- passwd paste pathchk pr \
+ passwd paste patch pathchk pr \
printenv printf pwhash \
renice rev \
\
*/
#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>
file_name_length = strlen(file);
while ((dp = readdir(dirp)) != NULL) {
- if (strlen(dp->d_name) <= file_name_length)
+ if (dp->d_namlen <= file_name_length)
continue;
this_version = version_number(file, dp->d_name, file_name_length);
make_version_name(const char *file, int version)
{
char *backup_name;
- int len = strlen(file)+20;
- if(!(backup_name = malloc(len)))
+ if (asprintf(&backup_name, "%s.~%d~", file, version) == -1)
return NULL;
-
- if (snprintf(backup_name, len, "%s.~%d~", file, version) == -1)
- return NULL;
-
return backup_name;
}
concat(const char *str1, const char *str2)
{
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;
-
- if (snprintf(newstr, len, "%s%s", str1, str2) == -1)
- return NULL;
-
return newstr;
}
/*
* $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 $
- * $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 $
*/
/*
*/
#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/file.h>
#include <sys/mman.h>
#include <ctype.h>
+#include <fcntl.h>
#include <libgen.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <fcntl.h>
#include "common.h"
#include "util.h"
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. */
void
free(i_ptr);
i_ptr = NULL;
if (i_womp != NULL) {
-#ifndef __minix
munmap(i_womp, i_size);
-#else
- free(i_womp);
-#endif
i_womp = NULL;
}
} else {
new_size = *lines_allocated * 3 / 2;
p = realloc(i_ptr, (new_size + 2) * sizeof(char *));
if (p == NULL) { /* shucks, it was a near thing */
-#ifndef __minix
munmap(i_womp, i_size);
-#else
- free(i_womp);
-#endif
i_womp = NULL;
free(i_ptr);
i_ptr = NULL;
out_of_mem = false;
return false; /* force plan b because plan a bombed */
}
-#ifndef __minix
- if (i_size > SIZE_MAX) {
+ if ((uintmax_t)i_size > (uintmax_t)SIZE_MAX) {
say("block too large to mmap\n");
return false;
}
-#endif
if ((ifd = open(filename, O_RDONLY)) < 0)
pfatal("can't open file %s", filename);
-#ifndef __minix
- i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0);
- if (i_womp == MAP_FAILED) {
- perror("mmap failed");
- 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.");
+ if (i_size) {
+ i_womp = mmap(NULL, i_size, PROT_READ, MAP_PRIVATE, ifd, 0);
+ if (i_womp == MAP_FAILED) {
+ perror("mmap failed");
+ i_womp = NULL;
+ close(ifd);
+ return false;
+ }
+ } else {
i_womp = NULL;
- close(ifd);
- return false;
}
-#endif
close(ifd);
-#ifndef __minix
+#if !defined(__minix)
if (i_size)
madvise(i_womp, i_size, MADV_SEQUENTIAL);
-#endif
+#endif /* !defined(__minix) */
/* estimate the number of lines */
lines_allocated = i_size / 25;
if (p == NULL) {
free(i_ptr);
i_ptr = NULL;
-#ifndef __minix
munmap(i_womp, i_size);
-#else
- free(i_womp);
-#endif
i_womp = NULL;
return false;
}
*/
#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>
.\" $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 $
-.\" $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
.\"
.\" Redistribution and use in source and binary forms, with or without
.Nd apply a diff file to an original
.Sh SYNOPSIS
.Nm
-.Bk -words
.Op Fl bCcEeflNnRstuv
.Op Fl B Ar backup-prefix
.Op Fl D Ar symbol
.Op Fl z Ar backup-ext
.Op Fl Fl posix
.Op Ar origfile Op Ar patchfile
-.Ek
.Nm
.Pf \*(Lt Ar patchfile
.Sh DESCRIPTION
.Pp
The options are as follows:
.Bl -tag -width Ds
-.It Xo
-.Fl B Ar backup-prefix ,
-.Fl Fl prefix Ar backup-prefix
-.Xc
+.It Fl B Ar backup-prefix , Fl Fl prefix Ar backup-prefix
Causes the next argument to be interpreted as a prefix to the backup file
name.
If this argument is specified, any argument to
Forces
.Nm
to interpret the patch file as a context diff.
-.It Xo
-.Fl D Ar symbol ,
-.Fl Fl ifdef Ar symbol
-.Xc
+.It Fl D Ar symbol , Fl Fl ifdef Ar symbol
Causes
.Nm
to use the
Note that, unlike the C compiler, there must be a space between the
.Fl D
and the argument.
-.It Xo
-.Fl d Ar directory ,
-.Fl Fl directory Ar directory
-.Xc
+.It Fl d Ar directory , Fl Fl directory Ar directory
Causes
.Nm
to interpret the next argument as a directory,
to interpret the patch file as an
.Xr ed 1
script.
-.It Xo
-.Fl F Ar max-fuzz ,
-.Fl Fl fuzz Ar max-fuzz
-.Xc
+.It Fl F Ar max-fuzz , Fl Fl fuzz Ar max-fuzz
Sets the maximum fuzz factor.
This option only applies to context diffs, and causes
.Nm
This option does not suppress commentary; use
.Fl s
for that.
-.It Xo
-.Fl i Ar patchfile ,
-.Fl Fl input Ar patchfile
-.Xc
+.It Fl i Ar patchfile , Fl Fl input Ar patchfile
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.
.It Fl l , Fl Fl ignore-whitespace
Causes the pattern matching to be done loosely, in case the tabs and
Forces
.Nm
to interpret the patch file as a normal diff.
-.It Xo
-.Fl o Ar out-file ,
-.Fl Fl output Ar out-file
-.Xc
+.It Fl o Ar out-file , Fl Fl output Ar out-file
Causes the next argument to be interpreted as the output file name.
-.It Xo
-.Fl p Ar strip-count ,
-.Fl Fl strip Ar strip-count
-.Xc
+.It Fl p Ar strip-count , Fl Fl strip Ar strip-count
Sets the pathname strip count,
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
option set.
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
-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
anywhere.
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
the heuristic.)
-.It Xo
-.Fl r Ar rej-name ,
-.Fl Fl reject-file Ar rej-name
-.Xc
+.It Fl r Ar rej-name , Fl Fl reject-file Ar rej-name
Causes the next argument to be interpreted as the reject file name.
-.It Xo
-.Fl s , Fl Fl quiet ,
-.Fl Fl silent
-.Xc
+.It Fl s , Fl Fl quiet , Fl Fl silent
Makes
.Nm
do its work silently, unless an error occurs.
Forces
.Nm
to interpret the patch file as a unified context diff (a unidiff).
-.It Xo
-.Fl V Cm t | nil | never ,
-.Fl Fl version-control Cm t | nil | never
-.Xc
+.It Fl V Cm t | nil | never , Fl Fl version-control Cm t | nil | never
Causes the next argument to be interpreted as a method for creating
backup file names.
The type of backups made can also be given in the
Causes
.Nm
to print out its revision header and patch level.
-.It Xo
-.Fl x Ar number ,
-.Fl Fl debug Ar number
-.Xc
+.It Fl x Ar number , Fl Fl debug Ar number
Sets internal debugging flags, and is of interest only to
.Nm
patchers.
-.It Xo
-.Fl z Ar backup-ext ,
-.Fl Fl suffix Ar backup-ext
-.Xc
+.It Fl z Ar backup-ext , Fl Fl suffix Ar backup-ext
Causes the next argument to be interpreted as the backup extension, to be
used in place of
.Qq .orig .
/*
* $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 $
- * $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 $
*/
/*
*/
#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/stat.h>
static void dump_line(LINENUM, bool);
static bool patch_match(LINENUM, LINENUM, LINENUM);
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. */
static bool remove_empty_files = false;
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++;
-
- 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)
+ if (asprintf(&TMPOUTNAME, "%.*s/patchoXXXXXXXXXX", i, tmpdir) == -1)
fatal("cannot allocate memory");
if ((fd = mkstemp(TMPOUTNAME)) < 0)
pfatal("can't create %s", TMPOUTNAME);
close(fd);
- if (snprintf(TMPINNAME, alloclen, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
+ if (asprintf(&TMPINNAME, "%.*s/patchiXXXXXXXXXX", i, tmpdir) == -1)
fatal("cannot allocate memory");
if ((fd = mkstemp(TMPINNAME)) < 0)
pfatal("can't create %s", TMPINNAME);
close(fd);
- if (snprintf(TMPREJNAME, alloclen, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
+ if (asprintf(&TMPREJNAME, "%.*s/patchrXXXXXXXXXX", i, tmpdir) == -1)
fatal("cannot allocate memory");
if ((fd = mkstemp(TMPREJNAME)) < 0)
pfatal("can't create %s", TMPREJNAME);
close(fd);
- if (snprintf(TMPPATNAME, alloclen, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
+ if (asprintf(&TMPPATNAME, "%.*s/patchpXXXXXXXXXX", i, tmpdir) == -1)
fatal("cannot allocate memory");
if ((fd = mkstemp(TMPPATNAME)) < 0)
pfatal("can't create %s", TMPPATNAME);
" [-r rej-name] [-V t | nil | never] [-x number] [-z backup-ext]\n"
" [--posix] [origfile [patchfile]]\n"
" patch <patchfile\n");
- my_exit(EXIT_SUCCESS);
+ my_exit(EXIT_FAILURE);
}
/*
/*
* $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 $
- * $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 $
*/
/*
*/
#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/stat.h>
}
/* Make this a function for better debugging. */
-static void
+__dead static void
malformed(void)
{
fatal("malformed patch at line %ld: %s", p_input_line, buf);
}
/*
- * 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".)
*/
static bool
/*
* $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 $
- * $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 $
*/
/*
*/
#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/stat.h>
if (striplast) {
char *s = strrchr(tmpbuf, '/');
- if (s == NULL)
+ if (s == NULL) {
+ free(tmpbuf);
return; /* nothing to be done */
+ }
*s = '\0';
}
if (mkpath(tmpbuf) != 0)
void
version(void)
{
- fprintf(stderr, "Patch version 2.0-12u8-NetBSD\n");
+ printf("Patch version 2.0-12u8-NetBSD\n");
my_exit(EXIT_SUCCESS);
}
/*
* $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 $
- * $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 $
*/
/*
int backup_file(const char *);
int move_file(const char *, const char *);
int copy_file(const char *, const char *);
-void say(const char *, ...)
- __attribute__((__format__(__printf__, 1, 2)));
-void fatal(const char *, ...)
- __attribute__((__format__(__printf__, 1, 2)));
-void pfatal(const char *, ...)
- __attribute__((__format__(__printf__, 1, 2)));
-void ask(const char *, ...)
- __attribute__((__format__(__printf__, 1, 2)));
+void say(const char *, ...) __printflike(1, 2);
+void fatal(const char *, ...) __printflike(1, 2) __dead;
+void pfatal(const char *, ...) __printflike(1, 2) __dead;
+void ask(const char *, ...) __printflike(1, 2);
char *savestr(const char *);
void set_signals(int);
void ignore_signals(void);
void makedirs(const char *, bool);
-void version(void);
-void my_exit(int) __attribute__((noreturn));
+void version(void) __dead;
+void my_exit(int) __dead;
/* in mkpath.c */
extern int mkpath(char *);