-/* $OpenBSD: cpio.c,v 1.5 1997/07/25 18:58:28 mickey Exp $ */
+/* $OpenBSD: cpio.c,v 1.18 2008/01/01 16:22:44 tobias Exp $ */
/* $NetBSD: cpio.c,v 1.5 1995/03/21 09:07:13 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[] = "@(#)cpio.c 8.1 (Berkeley) 5/31/93";
+static const char sccsid[] = "@(#)cpio.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: cpio.c,v 1.5 1997/07/25 18:58:28 mickey Exp $";
+static const char rcsid[] = "$OpenBSD: cpio.c,v 1.18 2008/01/01 16:22:44 tobias Exp $";
#endif
#endif /* not lint */
#include "cpio.h"
#include "extern.h"
-static int rd_nm __P((register ARCHD *, int));
-static int rd_ln_nm __P((register ARCHD *));
-static int com_rd __P((register ARCHD *));
+static int rd_nm(ARCHD *, int);
+static int rd_ln_nm(ARCHD *);
+static int com_rd(ARCHD *);
/*
* Routines which support the different cpio versions
* 0 if ok -1 otherwise (the return values of lnk_start())
*/
-#ifdef __STDC__
int
cpio_strd(void)
-#else
-int
-cpio_strd()
-#endif
{
return(lnk_start());
}
* mode; looking for a valid header), and cnt (which starts at zero)
* which is used to count the number of empty blocks we have seen so far.
* Return:
- * 0 if a valid trailer, -1 if not a valid trailer,
+ * 0 if a valid trailer, -1 if not a valid trailer,
*/
-#ifdef __STDC__
-int
-cpio_trail(register ARCHD *arcn)
-#else
int
-cpio_trail(arcn)
- register ARCHD *arcn;
-#endif
+cpio_trail(ARCHD *arcn, char *notused, int notused2, int *notused3)
{
/*
* look for trailer id in file we are about to process
* 0
*/
-#ifdef __STDC__
-static int
-com_rd(register ARCHD *arcn)
-#else
static int
-com_rd(arcn)
- register ARCHD *arcn;
-#endif
+com_rd(ARCHD *arcn)
{
arcn->skip = 0;
arcn->pat = NULL;
arcn->org_name = arcn->name;
- switch(arcn->sb.st_mode & C_IFMT) {
+ switch (arcn->sb.st_mode & C_IFMT) {
case C_ISFIFO:
arcn->type = PAX_FIF;
break;
}
/*
- * cpio_end_wr()
+ * cpio_endwr()
* write the special file with the name trailer in the proper format
* Return:
* result of the write of the trailer from the cpio specific write func
*/
-#ifdef __STDC__
int
cpio_endwr(void)
-#else
-int
-cpio_endwr()
-#endif
{
ARCHD last;
last.nlen = sizeof(TRAILER) - 1;
last.type = PAX_REG;
last.sb.st_nlink = 1;
- (void)strcpy(last.name, TRAILER);
+ (void)strlcpy(last.name, TRAILER, sizeof(last.name));
return((*frmt->wr)(&last));
}
* 0 if ok, -1 otherwise
*/
-#ifdef __STDC__
static int
-rd_nm(register ARCHD *arcn, int nsz)
-#else
-static int
-rd_nm(arcn, nsz)
- register ARCHD *arcn;
- int nsz;
-#endif
+rd_nm(ARCHD *arcn, int nsz)
{
/*
* do not even try bogus values
* 0 if ok, -1 otherwise
*/
-#ifdef __STDC__
-static int
-rd_ln_nm(register ARCHD *arcn)
-#else
static int
-rd_ln_nm(arcn)
- register ARCHD *arcn;
-#endif
+rd_ln_nm(ARCHD *arcn)
{
/*
* check the length specified for bogus values
*/
if ((arcn->sb.st_size == 0) ||
(arcn->sb.st_size >= sizeof(arcn->ln_name))) {
-# ifdef NET2_STAT
+# ifdef LONG_OFF_T
paxwarn(1, "Cpio link name length is invalid: %lu",
arcn->sb.st_size);
# else
* 0 if a valid header, -1 otherwise
*/
-#ifdef __STDC__
int
cpio_id(char *blk, int size)
-#else
-int
-cpio_id(blk, size)
- char *blk;
- int size;
-#endif
{
if ((size < sizeof(HD_CPIO)) ||
(strncmp(blk, AMAGIC, sizeof(AMAGIC) - 1) != 0))
* 0 if a valid header, -1 otherwise.
*/
-#ifdef __STDC__
-int
-cpio_rd(register ARCHD *arcn, register char *buf)
-#else
int
-cpio_rd(arcn, buf)
- register ARCHD *arcn;
- register char *buf;
-#endif
+cpio_rd(ARCHD *arcn, char *buf)
{
- register int nsz;
- register HD_CPIO *hd;
+ int nsz;
+ HD_CPIO *hd;
/*
* check that this is a valid header, if not return -1
arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime, sizeof(hd->c_mtime),
OCT);
arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
-# ifdef NET2_STAT
+# ifdef LONG_OFF_T
arcn->sb.st_size = (off_t)asc_ul(hd->c_filesize,sizeof(hd->c_filesize),
OCT);
# else
if (((arcn->sb.st_mode&C_IFMT) != C_ISLNK)||(arcn->sb.st_size == 0)) {
/*
- * no link name to read for this file
- */
+ * no link name to read for this file
+ */
arcn->ln_nlen = 0;
arcn->ln_name[0] = '\0';
return(com_rd(arcn));
* size of trailer header in this format
*/
-#ifdef __STDC__
off_t
cpio_endrd(void)
-#else
-off_t
-cpio_endrd()
-#endif
{
return((off_t)(sizeof(HD_CPIO) + sizeof(TRAILER)));
}
* 0 if ok, -1 otherwise (what dev_start() returns)
*/
-#ifdef __STDC__
int
cpio_stwr(void)
-#else
-int
-cpio_stwr()
-#endif
{
return(dev_start());
}
* data to write after the header, -1 if archive write failed
*/
-#ifdef __STDC__
int
-cpio_wr(register ARCHD *arcn)
-#else
-int
-cpio_wr(arcn)
- register ARCHD *arcn;
-#endif
+cpio_wr(ARCHD *arcn)
{
- register HD_CPIO *hd;
- register int nsz;
+ HD_CPIO *hd;
+ int nsz;
char hdblk[sizeof(HD_CPIO)];
/*
if ((arcn->type != PAX_BLK) && (arcn->type != PAX_CHR))
arcn->sb.st_rdev = 0;
- switch(arcn->type) {
+ switch (arcn->type) {
case PAX_CTG:
case PAX_REG:
case PAX_HRG:
/*
* set data size for file data
*/
-# ifdef NET2_STAT
+# ifdef LONG_OFF_T
if (ul_asc((u_long)arcn->sb.st_size, hd->c_filesize,
sizeof(hd->c_filesize), OCT)) {
# else
/*
* vcpio_id()
* determine if a block given to us is a valid system VR4 cpio header
- * WITHOUT crc. WATCH it the magic cookies are in OCTAL, the header
+ * WITHOUT crc. WATCH it the magic cookies are in OCTAL, the header
* uses HEX
* Return:
* 0 if a valid header, -1 otherwise
*/
-#ifdef __STDC__
int
vcpio_id(char *blk, int size)
-#else
-int
-vcpio_id(blk, size)
- char *blk;
- int size;
-#endif
{
if ((size < sizeof(HD_VCPIO)) ||
(strncmp(blk, AVMAGIC, sizeof(AVMAGIC) - 1) != 0))
* 0 if a valid header, -1 otherwise
*/
-#ifdef __STDC__
int
crc_id(char *blk, int size)
-#else
-int
-crc_id(blk, size)
- char *blk;
- int size;
-#endif
{
if ((size < sizeof(HD_VCPIO)) ||
(strncmp(blk, AVCMAGIC, sizeof(AVCMAGIC) - 1) != 0))
* 0 if ok -1 otherwise (the return values of lnk_start())
*/
-#ifdef __STDC__
int
crc_strd(void)
-#else
-int
-crc_strd()
-#endif
{
docrc = 1;
return(lnk_start());
* 0 if a valid header, -1 otherwise.
*/
-#ifdef __STDC__
-int
-vcpio_rd(register ARCHD *arcn, register char *buf)
-#else
int
-vcpio_rd(arcn, buf)
- register ARCHD *arcn;
- register char *buf;
-#endif
+vcpio_rd(ARCHD *arcn, char *buf)
{
- register HD_VCPIO *hd;
+ HD_VCPIO *hd;
dev_t devminor;
dev_t devmajor;
- register int nsz;
+ int nsz;
/*
* during the id phase it was determined if we were using CRC, use the
arcn->sb.st_gid = (gid_t)asc_ul(hd->c_gid, sizeof(hd->c_gid), HEX);
arcn->sb.st_mtime = (time_t)asc_ul(hd->c_mtime,sizeof(hd->c_mtime),HEX);
arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime;
-# ifdef NET2_STAT
+# ifdef LONG_OFF_T
arcn->sb.st_size = (off_t)asc_ul(hd->c_filesize,
sizeof(hd->c_filesize), HEX);
# else
return(-1);
/*
- * skip padding. header + filename is aligned to 4 byte boundries
+ * skip padding. header + filename is aligned to 4 byte boundaries
*/
if (rd_skip((off_t)(VCPIO_PAD(sizeof(HD_VCPIO) + nsz))) < 0)
return(-1);
* size of trailer header in this format
*/
-#ifdef __STDC__
off_t
vcpio_endrd(void)
-#else
-off_t
-vcpio_endrd()
-#endif
{
return((off_t)(sizeof(HD_VCPIO) + sizeof(TRAILER) +
(VCPIO_PAD(sizeof(HD_VCPIO) + sizeof(TRAILER)))));
* 0 if ok, -1 otherwise (what dev_start() returns)
*/
-#ifdef __STDC__
int
crc_stwr(void)
-#else
-int
-crc_stwr()
-#endif
{
docrc = 1;
return(dev_start());
* NO data to write after the header, -1 if archive write failed
*/
-#ifdef __STDC__
-int
-vcpio_wr(register ARCHD *arcn)
-#else
int
-vcpio_wr(arcn)
- register ARCHD *arcn;
-#endif
+vcpio_wr(ARCHD *arcn)
{
- register HD_VCPIO *hd;
+ HD_VCPIO *hd;
unsigned int nsz;
char hdblk[sizeof(HD_VCPIO)];
*/
if (docrc) {
if (ul_asc((u_long)VCMAGIC, hd->c_magic, sizeof(hd->c_magic),
- OCT) ||
+ OCT) ||
ul_asc((u_long)arcn->crc,hd->c_chksum,sizeof(hd->c_chksum),
- HEX))
+ HEX))
goto out;
} else {
if (ul_asc((u_long)VMAGIC, hd->c_magic, sizeof(hd->c_magic),
- OCT) ||
+ OCT) ||
ul_asc((u_long)0L, hd->c_chksum, sizeof(hd->c_chksum),HEX))
goto out;
}
- switch(arcn->type) {
+ switch (arcn->type) {
case PAX_CTG:
case PAX_REG:
case PAX_HRG:
* much to pad.
*/
arcn->pad = VCPIO_PAD(arcn->sb.st_size);
-# ifdef NET2_STAT
+# ifdef LONG_OFF_T
if (ul_asc((u_long)arcn->sb.st_size, hd->c_filesize,
sizeof(hd->c_filesize), HEX)) {
# else
ul_asc((u_long)arcn->sb.st_uid, hd->c_uid, sizeof(hd->c_uid),
HEX) ||
ul_asc((u_long)arcn->sb.st_gid, hd->c_gid, sizeof(hd->c_gid),
- HEX) ||
+ HEX) ||
ul_asc((u_long)arcn->sb.st_mtime, hd->c_mtime, sizeof(hd->c_mtime),
- HEX) ||
+ HEX) ||
ul_asc((u_long)arcn->sb.st_nlink, hd->c_nlink, sizeof(hd->c_nlink),
- HEX) ||
+ HEX) ||
ul_asc((u_long)MAJOR(arcn->sb.st_dev),hd->c_maj, sizeof(hd->c_maj),
HEX) ||
ul_asc((u_long)MINOR(arcn->sb.st_dev),hd->c_min, sizeof(hd->c_min),
* 0 if a valid header, -1 otherwise
*/
-#ifdef __STDC__
int
bcpio_id(char *blk, int size)
-#else
-int
-bcpio_id(blk, size)
- char *blk;
- int size;
-#endif
{
if (size < sizeof(HD_BCPIO))
return(-1);
* 0 if a valid header, -1 otherwise.
*/
-#ifdef __STDC__
-int
-bcpio_rd(register ARCHD *arcn, register char *buf)
-#else
int
-bcpio_rd(arcn, buf)
- register ARCHD *arcn;
- register char *buf;
-#endif
+bcpio_rd(ARCHD *arcn, char *buf)
{
- register HD_BCPIO *hd;
- register int nsz;
+ HD_BCPIO *hd;
+ int nsz;
/*
* check the header
hd = (HD_BCPIO *)buf;
if (swp_head) {
/*
- * header has swapped bytes on 16 bit boundries
+ * header has swapped bytes on 16 bit boundaries
*/
arcn->sb.st_dev = (dev_t)(RSHRT_EXT(hd->h_dev));
arcn->sb.st_ino = (ino_t)(RSHRT_EXT(hd->h_ino));
return(-1);
/*
- * header + file name are aligned to 2 byte boundries, skip if needed
+ * header + file name are aligned to 2 byte boundaries, skip if needed
*/
if (rd_skip((off_t)(BCPIO_PAD(sizeof(HD_BCPIO) + nsz))) < 0)
return(-1);
* size of trailer header in this format
*/
-#ifdef __STDC__
off_t
bcpio_endrd(void)
-#else
-off_t
-bcpio_endrd()
-#endif
{
return((off_t)(sizeof(HD_BCPIO) + sizeof(TRAILER) +
(BCPIO_PAD(sizeof(HD_BCPIO) + sizeof(TRAILER)))));
* bcpio_wr()
* copy the data in the ARCHD to buffer in old binary cpio format
* There is a real chance of field overflow with this critter. So we
- * always check the conversion is ok. nobody in his their right mind
- * should write an achive in this format...
+ * always check the conversion is ok. nobody in their right mind
+ * should write an archive in this format...
* Return
* 0 if file has data to be written after the header, 1 if file has NO
* data to write after the header, -1 if archive write failed
*/
-#ifdef __STDC__
int
-bcpio_wr(register ARCHD *arcn)
-#else
-int
-bcpio_wr(arcn)
- register ARCHD *arcn;
-#endif
+bcpio_wr(ARCHD *arcn)
{
- register HD_BCPIO *hd;
- register int nsz;
+ HD_BCPIO *hd;
+ int nsz;
char hdblk[sizeof(HD_BCPIO)];
off_t t_offt;
int t_int;
arcn->sb.st_rdev = 0;
hd = (HD_BCPIO *)hdblk;
- switch(arcn->type) {
+ switch (arcn->type) {
case PAX_CTG:
case PAX_REG:
case PAX_HRG: