-/* $OpenBSD: buf_subs.c,v 1.7 1997/09/01 18:29:46 deraadt Exp $ */
+/* $OpenBSD: buf_subs.c,v 1.21 2005/11/09 19:59:06 otto Exp $ */
/* $NetBSD: buf_subs.c,v 1.5 1995/03/21 09:07:08 cgd Exp $ */
/*-
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
#ifndef lint
#if 0
-static char sccsid[] = "@(#)buf_subs.c 8.2 (Berkeley) 4/18/94";
+static const char sccsid[] = "@(#)buf_subs.c 8.2 (Berkeley) 4/18/94";
#else
-static char rcsid[] = "$OpenBSD: buf_subs.c,v 1.7 1997/09/01 18:29:46 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: buf_subs.c,v 1.21 2005/11/09 19:59:06 otto Exp $";
#endif
#endif /* not lint */
* 0 if ok, -1 if the user specified write block size violates pax spec
*/
-#ifdef __STDC__
int
wr_start(void)
-#else
-int
-wr_start()
-#endif
{
buf = &(bufmem[BLKMULT]);
/*
}
/*
- * we only allow wrblksz to be used with all archive operations
+ * we only allow wrblksz to be used with all archive operations
*/
blksz = rdblksz = wrblksz;
if ((ar_open(arcname) < 0) && (ar_next() < 0))
* 0 if ok, -1 otherwise
*/
-#ifdef __STDC__
int
rd_start(void)
-#else
-int
-rd_start()
-#endif
{
/*
* leave space for the header pushback (see get_arc()). If we are
}
if (wrblksz % BLKMULT) {
paxwarn(1, "Write block size %d is not a %d byte multiple",
- wrblksz, BLKMULT);
+ wrblksz, BLKMULT);
return(-1);
}
}
* set up buffer system for copying within the file system
*/
-#ifdef __STDC__
void
cp_start(void)
-#else
-void
-cp_start()
-#endif
{
buf = &(bufmem[BLKMULT]);
rdblksz = blksz = MAXBLK;
* the start of the header of the first file added to the archive. The
* format specific end read function tells us how many bytes to move
* backwards in the archive to be positioned BEFORE the trailer. Two
- * different postions have to be adjusted, the O.S. file offset (e.g. the
+ * different position have to be adjusted, the O.S. file offset (e.g. the
* position of the tape head) and the write point within the data we have
* stored in the read (soon to become write) buffer. We may have to move
* back several records (the number depends on the size of the archive
* record and the size of the format trailer) to read up the record where
* the first byte of the trailer is recorded. Trailers may span (and
- * overlap) record boundries.
+ * overlap) record boundaries.
* We first calculate which record has the first byte of the trailer. We
* move the OS file offset back to the start of this record and read it
* up. We set the buffer write pointer to be at this byte (the byte where
* start of this record so a flush of this buffer will replace the record
* in the archive.
* A major problem is rewriting this last record. For archives stored
- * on disk files, this is trival. However, many devices are really picky
+ * on disk files, this is trivial. However, many devices are really picky
* about the conditions under which they will allow a write to occur.
- * Often devices restrict the conditions where writes can be made writes,
- * so it may not be feasable to append archives stored on all types of
- * devices.
+ * Often devices restrict the conditions where writes can be made,
+ * so it may not be feasible to append archives stored on all types of
+ * devices.
* Return:
* 0 for success, -1 for failure
*/
-#ifdef __STDC__
int
appnd_start(off_t skcnt)
-#else
-int
-appnd_start(skcnt)
- off_t skcnt;
-#endif
{
- register int res;
+ int res;
off_t cnt;
if (exit_val != 0) {
paxwarn(1, "Unable to rewrite archive trailer, cannot append.");
return(-1);
}
-
+
/*
* rd_sync()
* A read error occurred on this archive volume. Resync the buffer and
* 0 on success, and -1 on failure
*/
-#ifdef __STDC__
int
rd_sync(void)
-#else
-int
-rd_sync()
-#endif
{
- register int errcnt = 0;
- register int res;
+ int errcnt = 0;
+ int res;
/*
* if the user says bail out on first fault, we are out of here...
* pback()
* push the data used during the archive id phase back into the I/O
* buffer. This is required as we cannot be sure that the header does NOT
- * overlap a block boundry (as in the case we are trying to recover a
+ * overlap a block boundary (as in the case we are trying to recover a
* flawed archived). This was not designed to be used for any other
* purpose. (What software engineering, HA!)
* WARNING: do not even THINK of pback greater than BLKMULT, unless the
* pback space is increased.
*/
-#ifdef __STDC__
void
pback(char *pt, int cnt)
-#else
-void
-pback(pt, cnt)
- char *pt;
- int cnt;
-#endif
{
bufpt -= cnt;
memcpy(bufpt, pt, cnt);
/*
* rd_skip()
- * skip foward in the archive during a archive read. Used to get quickly
+ * skip forward in the archive during a archive read. Used to get quickly
* past file data and padding for files the user did NOT select.
* Return:
* 0 if ok, -1 failure, and 1 when EOF on the archive volume was detected.
*/
-#ifdef __STDC__
int
rd_skip(off_t skcnt)
-#else
-int
-rd_skip(skcnt)
- off_t skcnt;
-#endif
{
off_t res;
off_t cnt;
off_t skipped = 0;
/*
- * consume what data we have in the buffer. If we have to move foward
+ * consume what data we have in the buffer. If we have to move forward
* whole records, we call the low level skip function to see if we can
* move within the archive without doing the expensive reads on data we
* do not want.
return(0);
}
-/*
+/*
* wr_fin()
* flush out any data (and pad if required) the last block. We always pad
* with zero (even though we do not have to). Padding with 0 makes it a
- * lot easier to recover if the archive is damaged. zero paddding SHOULD
+ * lot easier to recover if the archive is damaged. zero padding SHOULD
* BE a requirement....
*/
-#ifdef __STDC__
void
wr_fin(void)
-#else
-void
-wr_fin()
-#endif
{
if (bufpt > buf) {
memset(bufpt, 0, bufend - bufpt);
* by format specific write routines to pass a file header). On failure we
* punt. We do not allow the user to continue to write flawed archives.
* We assume these headers are not very large (the memory copy we use is
- * a bit expensive).
+ * a bit expensive).
* Return:
* 0 if buffer was filled ok, -1 o.w. (buffer flush failure)
*/
-#ifdef __STDC__
int
-wr_rdbuf(register char *out, register int outcnt)
-#else
-int
-wr_rdbuf(out, outcnt)
- register char *out;
- register int outcnt;
-#endif
+wr_rdbuf(char *out, int outcnt)
{
- register int cnt;
+ int cnt;
/*
* while there is data to copy copy into the write buffer. when the
* -1 is a read error
*/
-#ifdef __STDC__
int
-rd_wrbuf(register char *in, register int cpcnt)
-#else
-int
-rd_wrbuf(in, cpcnt)
- register char *in;
- register int cpcnt;
-#endif
+rd_wrbuf(char *in, int cpcnt)
{
- register int res;
- register int cnt;
- register int incnt = cpcnt;
+ int res;
+ int cnt;
+ int incnt = cpcnt;
/*
* loop until we fill the buffer with the requested number of bytes
/*
* read error, return what we got (or the error if
* no data was copied). The caller must know that an
- * error occured and has the best knowledge what to
+ * error occurred and has the best knowledge what to
* do with it
*/
if ((res = cpcnt - incnt) > 0)
/*
* wr_skip()
- * skip foward during a write. In other words add padding to the file.
+ * skip forward during a write. In other words add padding to the file.
* we add zero filled padding as it makes flawed archives much easier to
* recover from. the caller tells us how many bytes of padding to add
* This routine was not designed to add HUGE amount of padding, just small
* 0 if ok, -1 if there was a buf_flush failure
*/
-#ifdef __STDC__
int
wr_skip(off_t skcnt)
-#else
-int
-wr_skip(skcnt)
- off_t skcnt;
-#endif
{
- register int cnt;
+ int cnt;
/*
* loop while there is more padding to add
* 0, but "left" is set to be greater than zero.
*/
-#ifdef __STDC__
int
wr_rdfile(ARCHD *arcn, int ifd, off_t *left)
-#else
-int
-wr_rdfile(arcn, ifd, left)
- ARCHD *arcn;
- int ifd;
- off_t *left;
-#endif
{
- register int cnt;
- register int res = 0;
- register off_t size = arcn->sb.st_size;
+ int cnt;
+ int res = 0;
+ off_t size = arcn->sb.st_size;
struct stat sb;
/*
* we return a 0 but "left" is set to be the amount unwritten
*/
-#ifdef __STDC__
int
rd_wrfile(ARCHD *arcn, int ofd, off_t *left)
-#else
-int
-rd_wrfile(arcn, ofd, left)
- ARCHD *arcn;
- int ofd;
- off_t *left;
-#endif
{
- register int cnt = 0;
- register off_t size = arcn->sb.st_size;
- register int res = 0;
- register char *fnm = arcn->name;
+ int cnt = 0;
+ off_t size = arcn->sb.st_size;
+ int res = 0;
+ char *fnm = arcn->name;
int isem = 1;
int rem;
int sz = MINFBSZ;
- struct stat sb;
- u_long crc = 0L;
+ struct stat sb;
+ u_int32_t crc = 0;
/*
* pass the blocksize of the file being written to the write routine,
* if the size is zero, use the default MINFBSZ
*/
- if (fstat(ofd, &sb) == 0) {
+ if (ofd < 0)
+ sz = PAXPATHLEN + 1; /* GNU tar long link/file */
+ else if (fstat(ofd, &sb) == 0) {
if (sb.st_blksize > 0)
sz = (int)sb.st_blksize;
} else
/*
* if the last block has a file hole (all zero), we must make sure this
* gets updated in the file. We force the last block of zeros to be
- * written. just closing with the file offset moved foward may not put
+ * written. just closing with the file offset moved forward may not put
* a hole at the end of the file.
*/
if (isem && (arcn->sb.st_size > 0L))
* destination file so we can properly copy files with holes.
*/
-#ifdef __STDC__
void
cp_file(ARCHD *arcn, int fd1, int fd2)
-#else
-void
-cp_file(arcn, fd1, fd2)
- ARCHD *arcn;
- int fd1;
- int fd2;
-#endif
{
- register int cnt;
- register off_t cpcnt = 0L;
- register int res = 0;
- register char *fnm = arcn->name;
- register int no_hole = 0;
+ int cnt;
+ off_t cpcnt = 0L;
+ int res = 0;
+ char *fnm = arcn->name;
+ int no_hole = 0;
int isem = 1;
int rem;
int sz = MINFBSZ;
/*
* read the source file and copy to destination file until EOF
*/
- for(;;) {
+ for (;;) {
if ((cnt = read(fd1, buf, blksz)) <= 0)
break;
if (no_hole)
/*
* if the last block has a file hole (all zero), we must make sure this
* gets updated in the file. We force the last block of zeros to be
- * written. just closing with the file offset moved foward may not put
+ * written. just closing with the file offset moved forward may not put
* a hole at the end of the file.
*/
if (!no_hole && isem && (arcn->sb.st_size > 0L))
* 0 when finished (user specified termination in ar_next()).
*/
-#ifdef __STDC__
int
buf_fill(void)
-#else
-int
-buf_fill()
-#endif
{
- register int cnt;
+ int cnt;
static int fini = 0;
if (fini)
return(0);
- for(;;) {
+ for (;;) {
/*
* try to fill the buffer. on error the next archive volume is
* opened and we try again.
* 0 if all is ok, -1 when a write error occurs.
*/
-#ifdef __STDC__
int
-buf_flush(register int bufcnt)
-#else
-int
-buf_flush(bufcnt)
- register int bufcnt;
-#endif
+buf_flush(int bufcnt)
{
- register int cnt;
- register int push = 0;
- register int totcnt = 0;
+ int cnt;
+ int push = 0;
+ int totcnt = 0;
/*
* if we have reached the user specified byte count for each archive
- * volume, prompt for the next volume. (The non-standrad -R flag).
+ * volume, prompt for the next volume. (The non-standard -R flag).
* NOTE: If the wrlimit is smaller than wrcnt, we will always write
* at least one record. We always round limit UP to next blocksize.
*/