Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/patch/patch.c
/* $OpenBSD: patch.c,v 1.63 2016/01/04 14:09:46 gsoares 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 | ||||
* modification, are permitted provided that the following condition is met: | * modification, are permitted provided that the following condition is met: | ||||
* 1. Redistributions of source code must retain the above copyright notice, | * 1. Redistributions of source code must retain the above copyright notice, | ||||
* this condition and the following disclaimer. | * this condition and the following disclaimer. | ||||
* | * | ||||
Show All 9 Lines | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
* | * | ||||
* patch - a program to apply diffs to original files | * patch - a program to apply diffs to original files | ||||
* | * | ||||
* -C option added in 1998, original code by Marc Espie, based on FreeBSD | * -C option added in 1998, original code by Marc Espie, based on FreeBSD | ||||
* behaviour | * behaviour | ||||
* | * | ||||
* $OpenBSD: patch.c,v 1.54 2014/12/13 10:31:07 tobias Exp $ | |||||
* $FreeBSD$ | * $FreeBSD$ | ||||
* | * | ||||
*/ | */ | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <getopt.h> | #include <getopt.h> | ||||
#include <limits.h> | #include <limits.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "common.h" | #include "common.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "pch.h" | #include "pch.h" | ||||
#include "inp.h" | #include "inp.h" | ||||
#include "backupfile.h" | #include "backupfile.h" | ||||
#include "pathnames.h" | #include "pathnames.h" | ||||
#include "ed.h" | |||||
mode_t filemode = 0644; | mode_t filemode = 0644; | ||||
char *buf; /* general purpose buffer */ | char *buf; /* general purpose buffer */ | ||||
size_t buf_size; /* size of the general purpose buffer */ | size_t buf_size; /* size of the general purpose buffer */ | ||||
bool using_plan_a = true; /* try to keep everything in memory */ | bool using_plan_a = true; /* try to keep everything in memory */ | ||||
bool out_of_mem = false; /* ran out of memory in plan a */ | bool out_of_mem = false; /* ran out of memory in plan a */ | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | |||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
int error = 0, hunk, failed, i, fd; | int error = 0, hunk, failed, i, fd; | ||||
bool patch_seen, reverse_seen; | bool patch_seen, reverse_seen; | ||||
LINENUM where = 0, newwhere, fuzz, mymaxfuzz; | LINENUM where = 0, newwhere, fuzz, mymaxfuzz; | ||||
const char *tmpdir; | const char *tmpdir; | ||||
char *v; | char *v; | ||||
#ifdef pledge | |||||
pfg: Do we really want to start bringing this crap?
We forked DragonFly's patch(1) and last time I… | |||||
if (pledge("stdio rpath wpath cpath tmppath fattr", NULL) == -1) { | |||||
perror("pledge"); | |||||
my_exit(2); | |||||
} | |||||
#endif | |||||
setvbuf(stdout, NULL, _IOLBF, 0); | setvbuf(stdout, NULL, _IOLBF, 0); | ||||
setvbuf(stderr, NULL, _IOLBF, 0); | setvbuf(stderr, NULL, _IOLBF, 0); | ||||
for (i = 0; i < MAXFILEC; i++) | for (i = 0; i < MAXFILEC; i++) | ||||
filearg[i] = NULL; | filearg[i] = NULL; | ||||
buf_size = INITLINELEN; | buf_size = INITLINELEN; | ||||
buf = malloc((unsigned)(buf_size)); | buf = malloc((unsigned)(buf_size)); | ||||
if (buf == NULL) | if (buf == NULL) | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | for (open_patch_file(filearg[1]); there_is_another_patch(); | ||||
patch_seen = true; | patch_seen = true; | ||||
warn_on_invalid_line = true; | warn_on_invalid_line = true; | ||||
if (outname == NULL) | if (outname == NULL) | ||||
outname = xstrdup(filearg[0]); | outname = xstrdup(filearg[0]); | ||||
/* for ed script just up and do it and exit */ | |||||
if (diff_type == ED_DIFF) { | |||||
do_ed_script(); | |||||
continue; | |||||
} | |||||
/* initialize the patched file */ | /* initialize the patched file */ | ||||
if (!skip_rest_of_patch) | if (!skip_rest_of_patch) | ||||
init_output(TMPOUTNAME); | init_output(TMPOUTNAME); | ||||
/* initialize reject file */ | /* initialize reject file */ | ||||
init_reject(TMPREJNAME); | init_reject(TMPREJNAME); | ||||
/* find out where all the lines are */ | /* find out where all the lines are */ | ||||
if (!skip_rest_of_patch) | if (!skip_rest_of_patch) | ||||
scan_input(filearg[0]); | scan_input(filearg[0]); | ||||
/* for ed script just up and do it and exit */ | |||||
if (diff_type == ED_DIFF) { | |||||
do_ed_script(); | |||||
continue; | |||||
} | |||||
/* | /* | ||||
* from here on, open no standard i/o files, because | * From here on, open no standard I/O files, because | ||||
* malloc might misfire and we can't catch it easily | * malloc might misfire and we can't catch it easily | ||||
*/ | */ | ||||
/* apply each hunk of patch */ | /* apply each hunk of patch */ | ||||
hunk = 0; | hunk = 0; | ||||
failed = 0; | failed = 0; | ||||
reverse_seen = false; | reverse_seen = false; | ||||
out_of_mem = false; | out_of_mem = false; | ||||
▲ Show 20 Lines • Show All 829 Lines • Show Last 20 Lines |
Do we really want to start bringing this crap?
We forked DragonFly's patch(1) and last time I checked, OpenBSD was not interested in our changes.