summaryrefslogtreecommitdiffstats
path: root/bin/pax
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2003-05-03 16:39:34 +0000
committermarkm <markm@FreeBSD.org>2003-05-03 16:39:34 +0000
commit0bdf7b1ca42db0f02d80bb1e42ec62fb25366be8 (patch)
tree49abf2bbd3188e40e370ac4a9c4a84a009a00066 /bin/pax
parent374b694311fb8af6c16cd7a912dd7b381b8b767e (diff)
downloadFreeBSD-src-0bdf7b1ca42db0f02d80bb1e42ec62fb25366be8.zip
FreeBSD-src-0bdf7b1ca42db0f02d80bb1e42ec62fb25366be8.tar.gz
Fix a bazillion warnings. This makes almost the whole of src/bin/*
WARNS=6, std=c99 clean. Tested on: i386, alpha
Diffstat (limited to 'bin/pax')
-rw-r--r--bin/pax/ar_io.c28
-rw-r--r--bin/pax/ar_subs.c9
-rw-r--r--bin/pax/cache.c4
-rw-r--r--bin/pax/cpio.c2
-rw-r--r--bin/pax/extern.h16
-rw-r--r--bin/pax/gen_subs.c6
-rw-r--r--bin/pax/getoldopt.c7
-rw-r--r--bin/pax/options.c30
-rw-r--r--bin/pax/pat_rep.c4
-rw-r--r--bin/pax/pax.c4
-rw-r--r--bin/pax/pax.h53
11 files changed, 88 insertions, 75 deletions
diff --git a/bin/pax/ar_io.c b/bin/pax/ar_io.c
index 5f56837..01c441c 100644
--- a/bin/pax/ar_io.c
+++ b/bin/pax/ar_io.c
@@ -69,8 +69,10 @@ __FBSDID("$FreeBSD$");
#define EXT_MODE O_RDONLY /* open mode for list/extract */
#define AR_MODE (O_WRONLY | O_CREAT | O_TRUNC) /* mode for archive */
#define APP_MODE O_RDWR /* mode for append */
-#define STDO "<STDOUT>" /* pseudo name for stdout */
-#define STDN "<STDIN>" /* pseudo name for stdin */
+
+static char none[] = "<NONE>"; /* pseudo name for no file */
+static char stdo[] = "<STDOUT>"; /* pseudo name for stdout */
+static char stdn[] = "<STDIN>"; /* pseudo name for stdin */
static int arfd = -1; /* archive file descriptor */
static int artyp = ISREG; /* archive type: file/FIFO/tape */
static int arvol = 1; /* archive volume number */
@@ -82,7 +84,7 @@ static struct stat arsb; /* stat of archive device at open */
static int invld_rec; /* tape has out of spec record size */
static int wr_trail = 1; /* trailer was rewritten in append */
static int can_unlnk = 0; /* do we unlink null archives? */
-char *arcname; /* printable name of archive */
+const char *arcname; /* printable name of archive */
const char *gzip_program; /* name of gzip program */
static pid_t zpid = -1; /* pid of child process */
@@ -100,7 +102,7 @@ static void ar_start_gzip(int, const char *, int);
*/
int
-ar_open(char *name)
+ar_open(const char *name)
{
struct mtget mb;
@@ -119,7 +121,7 @@ ar_open(char *name)
case EXTRACT:
if (name == NULL) {
arfd = STDIN_FILENO;
- arcname = STDN;
+ arcname = stdn;
} else if ((arfd = open(name, EXT_MODE, DMOD)) < 0)
syswarn(0, errno, "Failed open to read on %s", name);
if (arfd != -1 && gzip_program != NULL)
@@ -128,7 +130,7 @@ ar_open(char *name)
case ARCHIVE:
if (name == NULL) {
arfd = STDOUT_FILENO;
- arcname = STDO;
+ arcname = stdo;
} else if ((arfd = open(name, AR_MODE, DMOD)) < 0)
syswarn(0, errno, "Failed open to write on %s", name);
else
@@ -139,7 +141,7 @@ ar_open(char *name)
case APPND:
if (name == NULL) {
arfd = STDOUT_FILENO;
- arcname = STDO;
+ arcname = stdo;
} else if ((arfd = open(name, APP_MODE, DMOD)) < 0)
syswarn(0, errno, "Failed open to read/write on %s",
name);
@@ -148,7 +150,7 @@ ar_open(char *name)
/*
* arfd not used in COPY mode
*/
- arcname = "<NONE>";
+ arcname = none;
lstrval = 1;
return(0);
}
@@ -1131,7 +1133,7 @@ ar_next(void)
* if i/o is on stdin or stdout, we cannot reopen it (we do not know
* the name), the user will be forced to type it in.
*/
- if (strcmp(arcname, STDO) && strcmp(arcname, STDN) && (artyp != ISREG)
+ if (strcmp(arcname, stdo) && strcmp(arcname, stdn) && (artyp != ISREG)
&& (artyp != ISPIPE)) {
if (artyp == ISTAPE) {
tty_prnt("%s ready for archive tape volume: %d\n",
@@ -1227,7 +1229,7 @@ ar_next(void)
*/
if (ar_open(buf) >= 0) {
if (freeit) {
- (void)free(arcname);
+ (void)free((char *)(uintptr_t)arcname);
freeit = 0;
}
if ((arcname = strdup(buf)) == NULL) {
@@ -1251,10 +1253,10 @@ ar_next(void)
* to keep the fd the same in the calling function (parent).
*/
void
-ar_start_gzip(int fd, const char *gzip_program, int wr)
+ar_start_gzip(int fd, const char *gzip_prog, int wr)
{
int fds[2];
- char *gzip_flags;
+ const char *gzip_flags;
if (pipe(fds) < 0)
err(1, "could not pipe");
@@ -1282,7 +1284,7 @@ ar_start_gzip(int fd, const char *gzip_program, int wr)
}
close(fds[0]);
close(fds[1]);
- if (execlp(gzip_program, gzip_program, gzip_flags,
+ if (execlp(gzip_prog, gzip_prog, gzip_flags,
(char *)NULL) < 0)
err(1, "could not exec");
/* NOTREACHED */
diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c
index 2a4e189..c345fc0 100644
--- a/bin/pax/ar_subs.c
+++ b/bin/pax/ar_subs.c
@@ -365,7 +365,7 @@ wr_archive(ARCHD *arcn, int is_app)
int hlk;
int wr_one;
off_t cnt;
- int (*wrf)();
+ int (*wrf)(ARCHD *);
int fd = -1;
time_t now;
@@ -1053,7 +1053,7 @@ next_head(ARCHD *arcn)
/*
* this format has trailers outside of valid headers
*/
- if ((ret = (*frmt->trail)(hdbuf,in_resync,&cnt)) == 0){
+ if ((ret = (*frmt->trail_tar)(hdbuf,in_resync,&cnt)) == 0){
/*
* valid trailer found, drain input as required
*/
@@ -1097,10 +1097,9 @@ next_head(ARCHD *arcn)
/*
* ok got a valid header, check for trailer if format encodes it in the
- * the header. NOTE: the parameters are different than trailer routines
- * which encode trailers outside of the header!
+ * the header.
*/
- if (frmt->inhead && ((*frmt->trail)(arcn) == 0)) {
+ if (frmt->inhead && ((*frmt->trail_cpio)(arcn) == 0)) {
/*
* valid trailer found, drain input as required
*/
diff --git a/bin/pax/cache.c b/bin/pax/cache.c
index 840d850..9ae4d89 100644
--- a/bin/pax/cache.c
+++ b/bin/pax/cache.c
@@ -173,7 +173,7 @@ grptb_start(void)
* Pointer to stored name (or an empty string).
*/
-char *
+const char *
name_uid(uid_t uid, int frc)
{
struct passwd *pw;
@@ -244,7 +244,7 @@ name_uid(uid_t uid, int frc)
* Pointer to stored name (or an empty string).
*/
-char *
+const char *
name_gid(gid_t gid, int frc)
{
struct group *gr;
diff --git a/bin/pax/cpio.c b/bin/pax/cpio.c
index a90ca40..efce4bf 100644
--- a/bin/pax/cpio.c
+++ b/bin/pax/cpio.c
@@ -219,7 +219,7 @@ 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))) {
+ ((size_t)arcn->sb.st_size >= sizeof(arcn->ln_name))) {
# ifdef NET2_STAT
paxwarn(1, "Cpio link name length is invalid: %lu",
arcn->sb.st_size);
diff --git a/bin/pax/extern.h b/bin/pax/extern.h
index 1461a36..ba57821 100644
--- a/bin/pax/extern.h
+++ b/bin/pax/extern.h
@@ -47,9 +47,9 @@
/*
* ar_io.c
*/
-extern char *arcname;
+extern const char *arcname;
extern const char *gzip_program;
-int ar_open(char *);
+int ar_open(const char *);
void ar_close(void);
void ar_drain(void);
int ar_set_wr(void);
@@ -105,8 +105,8 @@ int uidtb_start(void);
int gidtb_start(void);
int usrtb_start(void);
int grptb_start(void);
-char * name_uid(uid_t, int);
-char * name_gid(gid_t, int);
+const char * name_uid(uid_t, int);
+const char * name_gid(gid_t, int);
int uid_name(char *, uid_t *);
int gid_name(char *, gid_t *);
@@ -167,7 +167,7 @@ int next_file(ARCHD *);
*/
void ls_list(ARCHD *, time_t, FILE *);
void ls_tty(ARCHD *);
-int l_strncpy(char *, char *, int);
+int l_strncpy(char *, const char *, int);
u_long asc_ul(char *, int, int);
int ul_asc(u_long, char *, int, int);
#ifndef NET2_STAT
@@ -178,7 +178,7 @@ int uqd_asc(u_quad_t, char *, int, int);
/*
* getoldopt.c
*/
-int getoldopt(int, char **, char *);
+int getoldopt(int, char **, const char *);
/*
* options.c
@@ -187,7 +187,7 @@ extern FSUB fsub[];
extern int ford[];
void options(int, char **);
OPLIST * opt_next(void);
-int opt_add(char *);
+int opt_add(const char *);
int bad_opt(void);
char *chdname;
@@ -233,7 +233,7 @@ extern int rmleadslash;
extern int exit_val;
extern int docrc;
extern char *dirptr;
-extern char *argv0;
+extern const char *argv0;
extern FILE *listf;
extern char *tempfile;
extern char *tempbase;
diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c
index 9a91824..bb56434 100644
--- a/bin/pax/gen_subs.c
+++ b/bin/pax/gen_subs.c
@@ -88,7 +88,7 @@ ls_list(ARCHD *arcn, time_t now, FILE *fp)
struct stat *sbp;
char f_mode[MODELEN];
char f_date[DATELEN];
- char *timefrmt;
+ const char *timefrmt;
/*
* if not verbose, just print the file name
@@ -167,7 +167,7 @@ ls_tty(ARCHD *arcn)
{
char f_date[DATELEN];
char f_mode[MODELEN];
- char *timefrmt;
+ const char *timefrmt;
if (d_first < 0)
d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
@@ -198,7 +198,7 @@ ls_tty(ARCHD *arcn)
*/
int
-l_strncpy(char *dest, char *src, int len)
+l_strncpy(char *dest, const char *src, int len)
{
char *stop;
char *start;
diff --git a/bin/pax/getoldopt.c b/bin/pax/getoldopt.c
index ca18d91..94611a6 100644
--- a/bin/pax/getoldopt.c
+++ b/bin/pax/getoldopt.c
@@ -13,12 +13,17 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/types.h>
+#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include "pax.h"
+#include "extern.h"
+
int
-getoldopt(int argc, char **argv, char *optstring)
+getoldopt(int argc, char **argv, const char *optstring)
{
static char *key; /* Points to next keyletter */
static char use_getopt; /* !=0 if argv[1][0] was '-' */
diff --git a/bin/pax/options.c b/bin/pax/options.c
index fb5c546..1475e89 100644
--- a/bin/pax/options.c
+++ b/bin/pax/options.c
@@ -103,31 +103,31 @@ FSUB fsub[] = {
/* 0: OLD BINARY CPIO */
{"bcpio", 5120, sizeof(HD_BCPIO), 1, 0, 0, 1, bcpio_id, cpio_strd,
bcpio_rd, bcpio_endrd, cpio_stwr, bcpio_wr, cpio_endwr, cpio_trail,
- rd_wrfile, wr_rdfile, bad_opt},
+ NULL, rd_wrfile, wr_rdfile, bad_opt},
/* 1: OLD OCTAL CHARACTER CPIO */
{"cpio", 5120, sizeof(HD_CPIO), 1, 0, 0, 1, cpio_id, cpio_strd,
cpio_rd, cpio_endrd, cpio_stwr, cpio_wr, cpio_endwr, cpio_trail,
- rd_wrfile, wr_rdfile, bad_opt},
+ NULL, rd_wrfile, wr_rdfile, bad_opt},
/* 2: SVR4 HEX CPIO */
{"sv4cpio", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, vcpio_id, cpio_strd,
vcpio_rd, vcpio_endrd, cpio_stwr, vcpio_wr, cpio_endwr, cpio_trail,
- rd_wrfile, wr_rdfile, bad_opt},
+ NULL, rd_wrfile, wr_rdfile, bad_opt},
/* 3: SVR4 HEX CPIO WITH CRC */
{"sv4crc", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd,
vcpio_rd, vcpio_endrd, crc_stwr, vcpio_wr, cpio_endwr, cpio_trail,
- rd_wrfile, wr_rdfile, bad_opt},
+ NULL, rd_wrfile, wr_rdfile, bad_opt},
/* 4: OLD TAR */
{"tar", 10240, BLKMULT, 0, 1, BLKMULT, 0, tar_id, no_op,
- tar_rd, tar_endrd, no_op, tar_wr, tar_endwr, tar_trail,
+ tar_rd, tar_endrd, no_op, tar_wr, tar_endwr, NULL, tar_trail,
rd_wrfile, wr_rdfile, tar_opt},
/* 5: POSIX USTAR */
{"ustar", 10240, BLKMULT, 0, 1, BLKMULT, 0, ustar_id, ustar_strd,
- ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, tar_trail,
+ ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, NULL, tar_trail,
rd_wrfile, wr_rdfile, bad_opt},
};
#define F_OCPIO 0 /* format when called as cpio -6 */
@@ -975,9 +975,8 @@ tar_options(int argc, char **argv)
}
}
-int
-mkpath(path)
- char *path;
+static int
+mkpath(char *path)
{
struct stat sb;
char *slash;
@@ -1299,7 +1298,7 @@ printflg(unsigned int flg)
static int
c_frmt(const void *a, const void *b)
{
- return(strcmp(((FSUB *)a)->name, ((FSUB *)b)->name));
+ return(strcmp(((const FSUB *)a)->name, ((const FSUB *)b)->name));
}
/*
@@ -1353,22 +1352,23 @@ bad_opt(void)
*/
int
-opt_add(char *str)
+opt_add(const char *str)
{
OPLIST *opt;
char *frpt;
char *pt;
char *endpt;
+ char *lstr;
if ((str == NULL) || (*str == '\0')) {
paxwarn(0, "Invalid option name");
return(-1);
}
- if ((str = strdup(str)) == NULL) {
+ if ((lstr = strdup(str)) == NULL) {
paxwarn(0, "Unable to allocate space for option list");
return(-1);
}
- frpt = endpt = str;
+ frpt = endpt = lstr;
/*
* break into name and values pieces and stuff each one into a
@@ -1380,12 +1380,12 @@ opt_add(char *str)
*endpt = '\0';
if ((pt = strchr(frpt, '=')) == NULL) {
paxwarn(0, "Invalid options format");
- free(str);
+ free(lstr);
return(-1);
}
if ((opt = (OPLIST *)malloc(sizeof(OPLIST))) == NULL) {
paxwarn(0, "Unable to allocate space for option list");
- free(str);
+ free(lstr);
return(-1);
}
*pt++ = '\0';
diff --git a/bin/pax/pat_rep.c b/bin/pax/pat_rep.c
index 7c98f3f..08e5b9a 100644
--- a/bin/pax/pat_rep.c
+++ b/bin/pax/pat_rep.c
@@ -222,7 +222,7 @@ rep_add(char *str)
*/
int
-pat_add(char *str, char *chdname)
+pat_add(char *str, char *chdnam)
{
PATTERN *pt;
@@ -249,7 +249,7 @@ pat_add(char *str, char *chdname)
pt->plen = strlen(str);
pt->fow = NULL;
pt->flgs = 0;
- pt->chdname = chdname;
+ pt->chdname = chdnam;
if (pathead == NULL) {
pattail = pathead = pt;
diff --git a/bin/pax/pax.c b/bin/pax/pax.c
index 43898bd..9f8c436 100644
--- a/bin/pax/pax.c
+++ b/bin/pax/pax.c
@@ -102,7 +102,7 @@ int rmleadslash = 0; /* remove leading '/' from pathnames */
int exit_val; /* exit value */
int docrc; /* check/create file crc */
char *dirptr; /* destination dir in a copy */
-char *argv0; /* root of argv[0] */
+const char *argv0; /* root of argv[0] */
sigset_t s_mask; /* signal mask for cleanup critical sect */
FILE *listf; /* file pointer to print file list to */
char *tempfile; /* tempfile to use for mkstemp(3) */
@@ -231,7 +231,7 @@ char *tempbase; /* basename of tempfile to use for mkstemp(3) */
int
main(int argc, char *argv[])
{
- char *tmpdir;
+ const char *tmpdir;
size_t tdlen;
(void) setlocale(LC_ALL, "");
diff --git a/bin/pax/pax.h b/bin/pax/pax.h
index a0d8de8..d61bc04 100644
--- a/bin/pax/pax.h
+++ b/bin/pax/pax.h
@@ -72,6 +72,11 @@
#define ISTAPE 3 /* tape drive */
#define ISPIPE 4 /* pipe/socket */
+typedef struct archd ARCHD;
+typedef struct fsub FSUB;
+typedef struct oplist OPLIST;
+typedef struct pattern PATTERN;
+
/*
* Format Specific Routine Table
*
@@ -82,8 +87,8 @@
* independent of the archive format. Data flow in and out of the format
* dependent routines pass pointers to ARCHD structure (described below).
*/
-typedef struct {
- char *name; /* name of format, this is the name the user */
+struct fsub {
+ const char *name; /* name of format, this is the name the user */
/* gives to -x option to select it. */
int bsz; /* default block size. used when the user */
/* does not specify a blocksize for writing */
@@ -108,12 +113,13 @@ typedef struct {
int inhead; /* is the trailer encoded in a valid header? */
/* if not, trailers are assumed to be found */
/* in invalid headers (i.e like tar) */
- int (*id)(); /* checks if a buffer is a valid header */
+ int (*id)(char *, int); /* checks if a buffer is a valid header */
/* returns 1 if it is, o.w. returns a 0 */
- int (*st_rd)(); /* initialize routine for read. so format */
+ int (*st_rd)(void); /* initialize routine for read. so format */
/* can set up tables etc before it starts */
/* reading an archive */
- int (*rd)(); /* read header routine. passed a pointer to */
+ int (*rd)(ARCHD *, char *);
+ /* read header routine. passed a pointer to */
/* ARCHD. It must extract the info from the */
/* format and store it in the ARCHD struct. */
/* This routine is expected to fill all the */
@@ -125,12 +131,12 @@ typedef struct {
/* padding and the number of bytes of data */
/* which follow the header. This info is */
/* used skip to the next file header */
- off_t (*end_rd)(); /* read cleanup. Allows format to clean up */
+ off_t (*end_rd)(void); /* read cleanup. Allows format to clean up */
/* and MUST RETURN THE LENGTH OF THE TRAILER */
/* RECORD (so append knows how many bytes */
/* to move back to rewrite the trailer) */
- int (*st_wr)(); /* initialize routine for write operations */
- int (*wr)(); /* write archive header. Passed an ARCHD */
+ int (*st_wr)(void); /* initialize routine for write operations */
+ int (*wr)(ARCHD *); /* write archive header. Passed an ARCHD */
/* filled with the specs on the next file to */
/* archived. Returns a 1 if no file data is */
/* is to be stored; 0 if file data is to be */
@@ -140,29 +146,30 @@ typedef struct {
/* the proper padding can be added after */
/* file data. This routine must NEVER write */
/* a flawed archive header. */
- int (*end_wr)(); /* end write. write the trailer and do any */
+ int (*end_wr)(void); /* end write. write the trailer and do any */
/* other format specific functions needed */
/* at the end of an archive write */
- int (*trail)(); /* returns 0 if a valid trailer, -1 if not */
+ int (*trail_cpio)(ARCHD *);
+ int (*trail_tar)(char *, int, int *);
+ /* returns 0 if a valid trailer, -1 if not */
/* For formats which encode the trailer */
/* outside of a valid header, a return value */
/* of 1 indicates that the block passed to */
/* it can never contain a valid header (skip */
/* this block, no point in looking at it) */
- /* CAUTION: parameters to this function are */
- /* different for trailers inside or outside */
- /* of headers. See get_head() for details */
- int (*rd_data)(); /* read/process file data from the archive */
- int (*wr_data)(); /* write/process file data to the archive */
- int (*options)(); /* process format specific options (-o) */
-} FSUB;
+ int (*rd_data)(ARCHD *, int, off_t *);
+ /* read/process file data from the archive */
+ int (*wr_data)(ARCHD *, int, off_t *);
+ /* write/process file data to the archive */
+ int (*options)(void); /* process format specific options (-o) */
+};
/*
* Pattern matching structure
*
* Used to store command line patterns
*/
-typedef struct pattern {
+struct pattern {
char *pstr; /* pattern to match, user supplied */
char *pend; /* end of a prefix match */
char *chdname; /* the dir to change to if not NULL. */
@@ -171,7 +178,7 @@ typedef struct pattern {
#define MTCH 0x1 /* pattern has been matched */
#define DIR_MTCH 0x2 /* pattern matched a directory */
struct pattern *fow; /* next pattern */
-} PATTERN;
+};
/*
* General Archive Structure (used internal to pax)
@@ -185,7 +192,7 @@ typedef struct pattern {
* may be required if and when the supporting operating system removes all
* restrictions on the length of pathnames it will resolve.
*/
-typedef struct {
+struct archd {
int nlen; /* file name length */
char name[PAXPATHLEN+1]; /* file name */
int ln_nlen; /* link name length */
@@ -210,18 +217,18 @@ typedef struct {
#define PAX_HLK 8 /* hard link */
#define PAX_HRG 9 /* hard link to a regular file */
#define PAX_CTG 10 /* high performance file */
-} ARCHD;
+};
/*
* Format Specific Options List
*
* Used to pass format options to the format options handler
*/
-typedef struct oplist {
+struct oplist {
char *name; /* option variable name e.g. name= */
char *value; /* value for option variable */
struct oplist *fow; /* next option */
-} OPLIST;
+};
/*
* General Macros
OpenPOWER on IntegriCloud