X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fbuffer.c;h=f402374df6614566ae15963d2b64ad25c0ec3673;hb=740b318ceadbc4bbe4141982ffe8f9f7191959ea;hp=603bdc20dc29fa7137715d6e72187b3a69c8b043;hpb=32841f71caa7337a62ce231ed787609003bce86f;p=chaz%2Ftar diff --git a/src/buffer.c b/src/buffer.c index 603bdc2..f402374 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -21,38 +21,34 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ * Buffer management for tar. * * Written by John Gilmore, ihnp4!hoptoad!gnu, on 25 August 1985. + * + * @(#) buffer.c 1.28 11/6/87 - gnu */ #include #include -#ifndef STDC_HEADERS -extern int errno; -#endif #include /* For non-Berkeley systems */ +#include #include -#include -time_t time(); -#ifndef NO_MTIO +#ifndef MSDOS #include +#if !defined(USG) || defined(HAVE_MTIO) #include #endif - -#ifdef BSD42 -#include -#else -#ifndef V7 -#include -#endif #endif -#ifdef __MSDOS__ +#ifdef MSDOS +# include #include +#else +# ifdef XENIX +# include +# endif +# include #endif -#ifdef XENIX -#include -#endif +extern int errno; #include "tar.h" #include "port.h" @@ -69,24 +65,45 @@ FILE *msg_file = stdout; #define PREAD 0 /* Read file descriptor from pipe() */ #define PWRITE 1 /* Write file descriptor from pipe() */ +#ifdef __STDC__ +extern void *malloc(); +extern void *valloc(); +#else +extern char *malloc(); +extern char *valloc(); +#endif +extern time_t time(); + +extern char *index(), *strcat(); +extern char *strcpy(); + +/* + * V7 doesn't have a #define for this. + */ +#ifndef O_RDONLY +#define O_RDONLY 0 +#endif +#ifndef O_RDWR +#define O_RDWR 2 +#endif +#ifndef O_CREAT +#define O_CREAT 0 +#endif +#ifndef O_BINARY +#define O_BINARY 0 +#endif + #define MAGIC_STAT 105 /* Magic status returned by child, if it can't exec. We hope compress/sh never return this status! */ -char *valloc(); - void writeerror(); void readerror(); void ck_pipe(); void ck_close(); -int backspace_output(); extern void finish_header(); -void flush_archive(); -int isfile(); -int new_volume(); -void verify_volume(); extern void to_oct(); #ifndef __MSDOS__ @@ -241,11 +258,11 @@ dupto(from, to, msg) } } -#ifdef __MSDOS__ +#ifdef MSDOS void child_open() { - fprintf(stderr,"MS-DOS %s can't use compressed or remote archives\n",tar); + fprintf(stderr,"MSDOS %s can't use compressed or remote archives\n",tar); exit(EX_ARGSBAD); } #else @@ -457,7 +474,6 @@ child_open() /* return non-zero if p is the name of a directory */ -int isfile(p) char *p; { @@ -465,7 +481,7 @@ char *p; if(stat(p,&stbuf)<0) return 1; - if(S_ISREG(stbuf.st_mode)) + if((stbuf.st_mode&S_IFMT)==S_IFREG) return 1; return 0; } @@ -477,7 +493,6 @@ char *p; * reading or writing. */ /* JF if the arg is 2, open for reading and writing. */ -void open_archive(reading) int reading; { @@ -542,24 +557,23 @@ open_archive(reading) } else { archive = rmtcreat(ar_file, 0666); } - if (archive < 0) { - msg_perror("can't open %s",ar_file); - exit(EX_BADARCH); - } - #ifndef __MSDOS__ if(!_isrmt(archive)) { struct stat tmp_stat; fstat(archive,&tmp_stat); - if(S_ISREG(tmp_stat.st_mode)) { + if((tmp_stat.st_mode&S_IFMT)==S_IFREG) { ar_dev=tmp_stat.st_dev; ar_ino=tmp_stat.st_ino; } } #endif -#ifdef __MSDOS__ + if (archive < 0) { + msg_perror("can't open %s",ar_file); + exit(EX_BADARCH); + } +#ifdef MSDOS setmode(archive, O_BINARY); #endif @@ -622,7 +636,6 @@ open_archive(reading) * adding (baserec+ar_record), doing a 9-bit shift of baserec, then * subtracting ar_block from that, shifting it back, losing the top 9 bits. */ -void saverec(pointer) union record **pointer; { @@ -644,7 +657,6 @@ saverec(pointer) } */ -void fl_write() { int err; @@ -671,7 +683,7 @@ fl_write() real_s_sizeleft = 0; return; } -#ifdef __MSDOS__ +#ifdef MSDOS if(save_name[1]==':') save_name+=2; #endif @@ -748,7 +760,7 @@ fl_write() else if((real_s_sizeleft+RECORDSIZE-1)/RECORDSIZE<=copy_back) real_s_name[0] = '\0'; else { -#ifdef __MSDOS__ +#ifdef MSDOS if(save_name[1]==':') save_name+=2; #endif @@ -815,7 +827,6 @@ readerror() /* * Perform a read to flush the buffer. */ -void fl_read() { int err; /* Result from system call */ @@ -848,7 +859,7 @@ fl_read() if(f_multivol) { if(save_name) { if(save_name!=real_s_name) { -#ifdef __MSDOS__ +#ifdef MSDOS if(save_name[1]==':') save_name+=2; #endif @@ -999,7 +1010,6 @@ error2loop: /* * Flush the current buffer to/from the archive. */ -void flush_archive() { int c; @@ -1031,7 +1041,6 @@ flush_archive() /* Backspace the archive descriptor by one blocks worth. If its a tape, MTIOCTOP will work. If its something else, we try to seek on it. If we can't seek, we lose! */ -int backspace_output() { long cur; @@ -1069,7 +1078,6 @@ backspace_output() /* * Close the archive file. */ -void close_archive() { int child; @@ -1079,11 +1087,12 @@ close_archive() if (time_to_start_writing || !ar_reading) flush_archive(); if(cmd_mode==CMD_DELETE) { - off_t pos; + long pos; pos = rmtlseek(archive,0L,1); -#ifndef __MSDOS__ - (void) ftruncate(archive,pos); +#ifndef MSDOS + /* FIXME does ftruncate really take an INT?! */ + (void) ftruncate(archive,(int)pos); #else (void)rmtwrite(archive,"",0); #endif @@ -1094,7 +1103,7 @@ close_archive() if((c=rmtclose(archive))<0) msg_perror("Warning: can't close %s(%d,%d)",ar_file,archive,c); -#ifndef __MSDOS__ +#ifndef MSDOS if (childpid) { /* * Loop waiting for the right child to die, or for @@ -1104,32 +1113,32 @@ close_archive() ; if (child != -1) { - switch (WTERMSIG(status)) { + switch (TERM_SIGNAL(status)) { case 0: /* Child voluntarily terminated -- but why? */ - if (WEXITSTATUS(status) == MAGIC_STAT) { + if (TERM_VALUE(status) == MAGIC_STAT) { exit(EX_SYSTEM);/* Child had trouble */ } - if (WEXITSTATUS(status) == (SIGPIPE + 128)) { + if (TERM_VALUE(status) == (SIGPIPE + 128)) { /* * /bin/sh returns this if its child * dies with SIGPIPE. 'Sok. */ break; - } else if (WEXITSTATUS(status)) + } else if (TERM_VALUE(status)) msg("child returned status %d", - WEXITSTATUS(status)); + TERM_VALUE(status)); case SIGPIPE: break; /* This is OK. */ default: msg("child died with signal %d%s", - WTERMSIG(status), - WIFCOREDUMPED(status)? " (core dumped)": ""); + TERM_SIGNAL(status), + TERM_COREDUMP(status)? " (core dumped)": ""); } } } -#endif /* __MSDOS__ */ +#endif /* MSDOS */ } @@ -1190,7 +1199,6 @@ anno(stream, prefix, savedp) /* We've hit the end of the old volume. Close it and open the next one */ /* Values for type: 0: writing 1: reading 2: updating */ -int new_volume(type) int type; { @@ -1268,7 +1276,7 @@ int type; break; case '!': -#ifdef __MSDOS__ +#ifdef MSDOS spawnl(P_WAIT,getenv("COMSPEC"),"-",0); #else /* JF this needs work! */ @@ -1304,7 +1312,7 @@ int type; msg_perror("can't open %s",ar_file); goto tryagain; } -#ifdef __MSDOS__ +#ifdef MSDOS setmode(archive,O_BINARY); #endif return 0;