version 1.3, 1996/09/24 04:19:30 |
version 1.4, 1997/09/22 05:45:27 |
|
|
#include "util.h" |
#include "util.h" |
#include "backupfile.h" |
#include "backupfile.h" |
|
|
|
#ifdef __GNUC__ |
|
void my_exit() __attribute__((noreturn)); |
|
#else |
void my_exit(); |
void my_exit(); |
|
#endif |
|
|
/* Rename a file, copying it if necessary. */ |
/* Rename a file, copying it if necessary. */ |
|
|
|
|
move_file(from,to) |
move_file(from,to) |
char *from, *to; |
char *from, *to; |
{ |
{ |
char bakname[512]; |
char bakname[MAXPATHLEN]; |
Reg1 char *s; |
Reg1 char *s; |
Reg2 int i; |
Reg2 int i; |
Reg3 int fromfd; |
Reg3 int fromfd; |
|
|
if (debug & 4) |
if (debug & 4) |
say2("Moving %s to stdout.\n", from); |
say2("Moving %s to stdout.\n", from); |
#endif |
#endif |
fromfd = open(from, 0); |
fromfd = open(from, O_RDONLY); |
if (fromfd < 0) |
if (fromfd < 0) |
pfatal2("internal error, can't reopen %s", from); |
pfatal2("internal error, can't reopen %s", from); |
while ((i=read(fromfd, buf, sizeof buf)) > 0) |
while ((i=read(fromfd, buf, sizeof buf)) > 0) |
|
|
strerror(errno)); |
strerror(errno)); |
return -1; |
return -1; |
} |
} |
tofd = open(to, 0); |
tofd = open(to, O_RDONLY); |
if (tofd < 0) |
if (tofd < 0) |
pfatal2("internal error, can't open %s", to); |
pfatal2("internal error, can't open %s", to); |
while ((i=read(tofd, buf, sizeof buf)) > 0) |
while ((i=read(tofd, buf, sizeof buf)) > 0) |
|
|
to, from, strerror(errno)); |
to, from, strerror(errno)); |
return -1; |
return -1; |
} |
} |
fromfd = open(from, 0); |
fromfd = open(from, O_RDONLY); |
if (fromfd < 0) |
if (fromfd < 0) |
pfatal2("internal error, can't reopen %s", from); |
pfatal2("internal error, can't reopen %s", from); |
while ((i=read(fromfd, buf, sizeof buf)) > 0) |
while ((i=read(fromfd, buf, sizeof buf)) > 0) |
|
|
tofd = creat(to, 0666); |
tofd = creat(to, 0666); |
if (tofd < 0) |
if (tofd < 0) |
pfatal2("can't create %s", to); |
pfatal2("can't create %s", to); |
fromfd = open(from, 0); |
fromfd = open(from, O_RDONLY); |
if (fromfd < 0) |
if (fromfd < 0) |
pfatal2("internal error, can't reopen %s", from); |
pfatal2("internal error, can't reopen %s", from); |
while ((i=read(fromfd, buf, sizeof buf)) > 0) |
while ((i=read(fromfd, buf, sizeof buf)) > 0) |
|
|
} |
} |
else { |
else { |
t = rv; |
t = rv; |
while (*t++ = *s++); |
while ((*t++ = *s++)) |
|
; |
} |
} |
return rv; |
return rv; |
} |
} |
|
|
write(1, buf, strlen(buf)); |
write(1, buf, strlen(buf)); |
r = read(1, buf, sizeof buf); |
r = read(1, buf, sizeof buf); |
} |
} |
else if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) { |
else if ((ttyfd = open(_PATH_TTY, O_RDWR)) >= 0 && isatty(ttyfd)) { |
/* might be deleted or unwriteable */ |
/* might be deleted or unwriteable */ |
write(ttyfd, buf, strlen(buf)); |
write(ttyfd, buf, strlen(buf)); |
r = read(ttyfd, buf, sizeof buf); |
r = read(ttyfd, buf, sizeof buf); |
|
|
int reset; |
int reset; |
{ |
{ |
#ifndef lint |
#ifndef lint |
#ifdef VOIDSIG |
static sig_t hupval, intval; |
static void (*hupval)(),(*intval)(); |
|
#else |
|
static int (*hupval)(),(*intval)(); |
|
#endif |
|
|
|
if (!reset) { |
if (!reset) { |
hupval = signal(SIGHUP, SIG_IGN); |
hupval = signal(SIGHUP, SIG_IGN); |
if (hupval != SIG_IGN) |
if (hupval != SIG_IGN) |
#ifdef VOIDSIG |
hupval = (sig_t)my_exit; |
hupval = my_exit; |
|
#else |
|
hupval = (int(*)())my_exit; |
|
#endif |
|
intval = signal(SIGINT, SIG_IGN); |
intval = signal(SIGINT, SIG_IGN); |
if (intval != SIG_IGN) |
if (intval != SIG_IGN) |
#ifdef VOIDSIG |
intval = (sig_t)my_exit; |
intval = my_exit; |
|
#else |
|
intval = (int(*)())my_exit; |
|
#endif |
|
} |
} |
Signal(SIGHUP, hupval); |
Signal(SIGHUP, hupval); |
Signal(SIGINT, intval); |
Signal(SIGINT, intval); |
|
|
|
|
#define try(f, a1, a2) (Snprintf(tmpbuf + pathlen, sizeof tmpbuf - pathlen, f, a1, a2), stat(tmpbuf, &filestat) == 0) |
#define try(f, a1, a2) (Snprintf(tmpbuf + pathlen, sizeof tmpbuf - pathlen, f, a1, a2), stat(tmpbuf, &filestat) == 0) |
if ( try("RCS/%s%s", filebase, RCSSUFFIX) |
if ( try("RCS/%s%s", filebase, RCSSUFFIX) |
|| try("RCS/%s" , filebase, 0) |
|| try("RCS/%s%s", filebase, "") |
|| try( "%s%s", filebase, RCSSUFFIX) |
|| try( "%s%s", filebase, RCSSUFFIX) |
|| try("SCCS/%s%s", SCCSPREFIX, filebase) |
|| try("SCCS/%s%s", SCCSPREFIX, filebase) |
|| try( "%s%s", SCCSPREFIX, filebase)) |
|| try( "%s%s", SCCSPREFIX, filebase)) |