version 1.15, 2003/07/21 14:32:21 |
version 1.16, 2003/07/22 17:18:49 |
|
|
/* $OpenBSD$ */ |
/* $OpenBSD$ */ |
|
|
#ifndef lint |
#ifndef lint |
static char rcsid[] = "$OpenBSD$"; |
static const char rcsid[] = "$OpenBSD$"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
|
#include <sys/param.h> |
|
#include <sys/stat.h> |
|
|
|
#include <ctype.h> |
|
#include <errno.h> |
|
#include <fcntl.h> |
|
#include <libgen.h> |
|
#include <paths.h> |
|
#include <stdarg.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include <unistd.h> |
|
|
#include "EXTERN.h" |
#include "EXTERN.h" |
#include "common.h" |
#include "common.h" |
#include "INTERN.h" |
#include "INTERN.h" |
#include "util.h" |
#include "util.h" |
#include "backupfile.h" |
#include "backupfile.h" |
|
|
void my_exit(int) __attribute__((noreturn)); |
|
|
|
/* Rename a file, copying it if necessary. */ |
/* Rename a file, copying it if necessary. */ |
|
|
|
|
if (fromfd < 0) |
if (fromfd < 0) |
pfatal("internal error, can't reopen %s", from); |
pfatal("internal error, can't reopen %s", from); |
while ((i = read(fromfd, buf, sizeof buf)) > 0) |
while ((i = read(fromfd, buf, sizeof buf)) > 0) |
if (write(1, buf, i) != 1) |
if (write(STDOUT_FILENO, buf, i) != i) |
pfatal("write failed"); |
pfatal("write failed"); |
close(fromfd); |
close(fromfd); |
return 0; |
return 0; |
|
|
while (*t++) |
while (*t++) |
; |
; |
rv = malloc((size_t) (t - s)); |
rv = malloc((size_t) (t - s)); |
if (rv == Nullch) { |
if (rv == NULL) { |
if (using_plan_a) |
if (using_plan_a) |
out_of_mem = TRUE; |
out_of_mem = TRUE; |
else |
else |
|
|
void |
void |
set_signals(int reset) |
set_signals(int reset) |
{ |
{ |
#ifndef lint |
|
static sig_t hupval, intval; |
static sig_t hupval, intval; |
|
|
if (!reset) { |
if (!reset) { |
|
|
} |
} |
signal(SIGHUP, hupval); |
signal(SIGHUP, hupval); |
signal(SIGINT, intval); |
signal(SIGINT, intval); |
#endif |
|
} |
} |
|
|
/* |
/* |
|
|
void |
void |
ignore_signals(void) |
ignore_signals(void) |
{ |
{ |
#ifndef lint |
|
signal(SIGHUP, SIG_IGN); |
signal(SIGHUP, SIG_IGN); |
signal(SIGINT, SIG_IGN); |
signal(SIGINT, SIG_IGN); |
#endif |
|
} |
} |
|
|
/* |
/* |
|
|
int sleading = strip_leading; |
int sleading = strip_leading; |
|
|
if (!at || *at == '\0') |
if (!at || *at == '\0') |
return Nullch; |
return NULL; |
while (isspace(*at)) |
while (isspace(*at)) |
at++; |
at++; |
#ifdef DEBUGGING |
#ifdef DEBUGGING |
|
|
say("fetchname %s %d %d\n", at, strip_leading, assume_exists); |
say("fetchname %s %d %d\n", at, strip_leading, assume_exists); |
#endif |
#endif |
if (strnEQ(at, "/dev/null", 9)) /* so files can be created by diffing */ |
if (strnEQ(at, "/dev/null", 9)) /* so files can be created by diffing */ |
return Nullch; /* against /dev/null. */ |
return NULL; /* against /dev/null. */ |
name = fullname = t = savestr(at); |
name = fullname = t = savestr(at); |
|
|
/* Strip off up to `sleading' leading slashes and null terminate. */ |
/* Strip off up to `sleading' leading slashes and null terminate. */ |
|
|
try("%s/%s%s", filedir, SCCSPREFIX, filebase)) |
try("%s/%s%s", filedir, SCCSPREFIX, filebase)) |
return name; |
return name; |
free(name); |
free(name); |
name = Nullch; |
name = NULL; |
} |
} |
return name; |
return name; |
} |
} |
|
|
{ |
{ |
fprintf(stderr, "Patch version 2.0-12u8-OpenBSD\n"); |
fprintf(stderr, "Patch version 2.0-12u8-OpenBSD\n"); |
my_exit(0); |
my_exit(0); |
|
} |
|
|
|
/* |
|
* Exit with cleanup. |
|
*/ |
|
void |
|
my_exit(int status) |
|
{ |
|
unlink(TMPINNAME); |
|
if (!toutkeep) |
|
unlink(TMPOUTNAME); |
|
if (!trejkeep) |
|
unlink(TMPREJNAME); |
|
unlink(TMPPATNAME); |
|
exit(status); |
} |
} |