summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/ls/extern.h9
-rw-r--r--bin/ls/ls.c66
-rw-r--r--bin/ls/print.c43
-rw-r--r--bin/ls/util.c2
-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
-rw-r--r--bin/ps/fmt.c2
-rw-r--r--bin/rcp/rcp.c24
17 files changed, 161 insertions, 148 deletions
diff --git a/bin/ls/extern.h b/bin/ls/extern.h
index 7f480aa..788138d 100644
--- a/bin/ls/extern.h
+++ b/bin/ls/extern.h
@@ -43,11 +43,11 @@ int revnamecmp(const FTSENT *, const FTSENT *);
int statcmp(const FTSENT *, const FTSENT *);
int revstatcmp(const FTSENT *, const FTSENT *);
-void printcol(DISPLAY *);
-void printlong(DISPLAY *);
+void printcol(const DISPLAY *);
+void printlong(const DISPLAY *);
int printname(const char *);
-void printscol(DISPLAY *);
-void printstream(DISPLAY *);
+void printscol(const DISPLAY *);
+void printstream(const DISPLAY *);
void usage(void);
size_t len_octal(const char *, int);
int prn_octal(const char *);
@@ -62,3 +62,4 @@ extern char *ansi_coloff;
extern char *attrs_off;
extern char *enter_bold;
#endif
+extern int termwidth;
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 9847702..53d6608 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -58,6 +58,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fts.h>
#include <grp.h>
+#include <inttypes.h>
#include <limits.h>
#include <locale.h>
#include <pwd.h>
@@ -80,12 +81,26 @@ __FBSDID("$FreeBSD$");
*/
#define STRBUF_SIZEOF(t) (1 + CHAR_BIT * sizeof(t) / 3 + 1)
-static void display(FTSENT *, FTSENT *, int);
-static u_quad_t makenines(u_long);
+/*
+ * MAKENINES(n) turns n into (10**n)-1. This is useful for converting a width
+ * into a number that wide in decimal.
+ * XXX: Overflows are not considered.
+ */
+#define MAKENINES(n) \
+ do { \
+ intmax_t i; \
+ \
+ /* Use a loop as all values of n are small. */ \
+ for (i = 1; n > 0; i *= 10) \
+ n--; \
+ n = i - 1; \
+ } while(0)
+
+static void display(const FTSENT *, FTSENT *, int);
static int mastercmp(const FTSENT * const *, const FTSENT * const *);
static void traverse(int, char **, int);
-static void (*printfcn)(DISPLAY *);
+static void (*printfcn)(const DISPLAY *);
static int (*sortfcn)(const FTSENT *, const FTSENT *);
long blocksize; /* block size units */
@@ -114,7 +129,7 @@ static int f_singlecol; /* use single column output */
int f_slash; /* similar to f_type, but only for dirs */
int f_sortacross; /* sort across rows, not down columns */
int f_statustime; /* use time of last mode change */
- int f_stream; /* stream the output, separate with commas */
+static int f_stream; /* stream the output, separate with commas */
static int f_timesort; /* sort by time vice name */
int f_type; /* add type character for non-regular files */
static int f_whiteout; /* show whiteout entries */
@@ -473,10 +488,10 @@ traverse(int argc, char *argv[], int options)
*/
if (output) {
putchar('\n');
- printname(p->fts_path);
+ (void)printname(p->fts_path);
puts(":");
} else if (argc > 1) {
- printname(p->fts_path);
+ (void)printname(p->fts_path);
puts(":");
output = 1;
}
@@ -499,14 +514,15 @@ traverse(int argc, char *argv[], int options)
* points to the parent directory of the display list.
*/
static void
-display(FTSENT *p, FTSENT *list, int options)
+display(const FTSENT *p, FTSENT *list, int options)
{
struct stat *sp;
DISPLAY d;
FTSENT *cur;
NAMES *np;
off_t maxsize;
- u_long btotal, labelstrlen, maxblock, maxinode, maxlen, maxnlink;
+ long maxblock;
+ u_long btotal, labelstrlen, maxinode, maxlen, maxnlink;
u_long maxlabelstr;
int bcfile, maxflags;
gid_t maxgroup;
@@ -542,9 +558,10 @@ display(FTSENT *p, FTSENT *list, int options)
int ninitmax;
/* Fill-in "::" as "0:0:0" for the sake of scanf. */
- jinitmax = initmax2 = malloc(strlen(initmax) * 2 + 2);
+ jinitmax = malloc(strlen(initmax) * 2 + 2);
if (jinitmax == NULL)
err(1, "malloc");
+ initmax2 = jinitmax;
if (*initmax == ':')
strcpy(initmax2, "0:"), initmax2 += 2;
else
@@ -563,7 +580,7 @@ display(FTSENT *p, FTSENT *list, int options)
strcpy(initmax2, "0");
ninitmax = sscanf(jinitmax,
- " %lu : %lu : %lu : %i : %i : %i : %llu : %lu : %lu ",
+ " %lu : %ld : %lu : %u : %u : %i : %jd : %lu : %lu ",
&maxinode, &maxblock, &maxnlink, &maxuser,
&maxgroup, &maxflags, &maxsize, &maxlen, &maxlabelstr);
f_notabs = 1;
@@ -603,10 +620,10 @@ display(FTSENT *p, FTSENT *list, int options)
default:
break;
}
- maxinode = makenines(maxinode);
- maxblock = makenines(maxblock);
- maxnlink = makenines(maxnlink);
- maxsize = makenines(maxsize);
+ MAKENINES(maxinode);
+ MAKENINES(maxblock);
+ MAKENINES(maxnlink);
+ MAKENINES(maxsize);
}
bcfile = 0;
flags = NULL;
@@ -787,7 +804,7 @@ label_out:
d.s_inode = strlen(buf);
(void)snprintf(buf, sizeof(buf), "%lu", maxnlink);
d.s_nlink = strlen(buf);
- (void)snprintf(buf, sizeof(buf), "%qu", maxsize);
+ (void)snprintf(buf, sizeof(buf), "%ju", maxsize);
d.s_size = strlen(buf);
d.s_user = maxuser;
}
@@ -829,22 +846,3 @@ mastercmp(const FTSENT * const *a, const FTSENT * const *b)
}
return (sortfcn(*a, *b));
}
-
-/*
- * Makenines() returns (10**n)-1. This is useful for converting a width
- * into a number that wide in decimal.
- */
-static u_quad_t
-makenines(u_long n)
-{
- u_long i;
- u_quad_t reg;
-
- reg = 1;
- /* Use a loop instead of pow(), since all values of n are small. */
- for (i = 0; i < n; i++)
- reg *= 10;
- reg--;
-
- return reg;
-}
diff --git a/bin/ls/print.c b/bin/ls/print.c
index 2fab63a..ae1f9db 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -65,7 +65,7 @@ __FBSDID("$FreeBSD$");
#include "ls.h"
#include "extern.h"
-static int printaname(FTSENT *, u_long, u_long);
+static int printaname(const FTSENT *, u_long, u_long);
static void printlink(const FTSENT *);
static void printtime(time_t);
static int printtype(u_int);
@@ -74,7 +74,7 @@ static void printsize(size_t, off_t);
static void endcolor(int);
static int colortype(mode_t);
#endif
-static void aclmode(char *, FTSENT *, int *);
+static void aclmode(char *, const FTSENT *, int *);
#define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
@@ -128,7 +128,7 @@ static struct {
#endif
void
-printscol(DISPLAY *dp)
+printscol(const DISPLAY *dp)
{
FTSENT *p;
@@ -155,7 +155,7 @@ printname(const char *name)
}
void
-printlong(DISPLAY *dp)
+printlong(const DISPLAY *dp)
{
struct stat *sp;
FTSENT *p;
@@ -179,7 +179,7 @@ printlong(DISPLAY *dp)
if (f_inode)
(void)printf("%*lu ", dp->s_inode, (u_long)sp->st_ino);
if (f_size)
- (void)printf("%*lld ",
+ (void)printf("%*jd ",
dp->s_block, howmany(sp->st_blocks, blocksize));
strmode(sp->st_mode, buf);
/*
@@ -207,7 +207,7 @@ printlong(DISPLAY *dp)
(void)printf("%3d, %3d ",
major(sp->st_rdev), minor(sp->st_rdev));
else if (dp->bcfile)
- (void)printf("%*s%*lld ",
+ (void)printf("%*s%*jd ",
8 - dp->s_size, "", dp->s_size, sp->st_size);
else
printsize(dp->s_size, sp->st_size);
@@ -235,10 +235,9 @@ printlong(DISPLAY *dp)
}
void
-printstream(DISPLAY *dp)
+printstream(const DISPLAY *dp)
{
FTSENT *p;
- extern int termwidth;
int chcnt;
for (p = dp->list, chcnt = 0; p; p = p->fts_link) {
@@ -260,9 +259,8 @@ printstream(DISPLAY *dp)
}
void
-printcol(DISPLAY *dp)
+printcol(const DISPLAY *dp)
{
- extern int termwidth;
static FTSENT **array;
static int lastentries = -1;
FTSENT *p;
@@ -352,7 +350,7 @@ printcol(DISPLAY *dp)
* return # of characters printed, no trailing characters.
*/
static int
-printaname(FTSENT *p, u_long inodefield, u_long sizefield)
+printaname(const FTSENT *p, u_long inodefield, u_long sizefield)
{
struct stat *sp;
int chcnt;
@@ -365,7 +363,7 @@ printaname(FTSENT *p, u_long inodefield, u_long sizefield)
if (f_inode)
chcnt += printf("%*lu ", (int)inodefield, (u_long)sp->st_ino);
if (f_size)
- chcnt += printf("%*lld ",
+ chcnt += printf("%*jd ",
(int)sizefield, howmany(sp->st_blocks, blocksize));
#ifdef COLORLS
if (f_color)
@@ -385,7 +383,7 @@ static void
printtime(time_t ftime)
{
char longstring[80];
- static time_t now;
+ static time_t now = 0;
const char *format;
static int d_first = -1;
@@ -457,7 +455,7 @@ putch(int c)
static int
writech(int c)
{
- char tmp = c;
+ char tmp = (char)c;
(void)write(STDOUT_FILENO, &tmp, 1);
return 0;
@@ -518,6 +516,7 @@ colortype(mode_t mode)
case S_IFCHR:
printcolor(C_CHR);
return (1);
+ default:;
}
if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
if (mode & S_ISUID)
@@ -543,10 +542,10 @@ parsecolors(const char *cs)
if (cs == NULL)
cs = ""; /* LSCOLORS not set */
len = strlen(cs);
- for (i = 0; i < C_NUMCOLORS; i++) {
+ for (i = 0; i < (int)C_NUMCOLORS; i++) {
colors[i].bold = 0;
- if (len <= 2 * i) {
+ if (len <= 2 * (size_t)i) {
c[0] = defcolors[2 * i];
c[1] = defcolors[2 * i + 1];
} else {
@@ -568,7 +567,7 @@ parsecolors(const char *cs)
else if (c[j] >= 'A' && c[j] <= 'H') {
colors[i].num[j] = c[j] - 'A';
colors[i].bold = 1;
- } else if (tolower((unsigned char)c[j] == 'x'))
+ } else if (tolower((unsigned char)c[j]) == 'x')
colors[i].num[j] = -1;
else {
warnx("invalid character '%c' in LSCOLORS"
@@ -622,12 +621,12 @@ printsize(size_t width, off_t bytes)
unit = unit_adjust(&dbytes);
if (dbytes == 0)
- (void)printf("%*s ", width, "0B");
+ (void)printf("%*s ", (u_int)width, "0B");
else
- (void)printf("%*.*f%c ", width - 1, dbytes > 10 ? 0 : 1,
- dbytes, "BKMGTPE"[unit]);
+ (void)printf("%*.*f%c ", (u_int)width - 1,
+ dbytes > 10 ? 0 : 1, dbytes, "BKMGTPE"[unit]);
} else
- (void)printf("%*lld ", width, bytes);
+ (void)printf("%*jd ", (u_int)width, bytes);
}
/*
@@ -658,7 +657,7 @@ unit_adjust(double *val)
}
static void
-aclmode(char *buf, FTSENT *p, int *haveacls)
+aclmode(char *buf, const FTSENT *p, int *haveacls)
{
char name[MAXPATHLEN + 1];
int entries, ret;
diff --git a/bin/ls/util.c b/bin/ls/util.c
index bbfe474..c8ea98b 100644
--- a/bin/ls/util.c
+++ b/bin/ls/util.c
@@ -39,7 +39,7 @@
static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#endif
-#include <sys/types.h>
+#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/types.h>
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
diff --git a/bin/ps/fmt.c b/bin/ps/fmt.c
index fe2101d..aae79e0 100644
--- a/bin/ps/fmt.c
+++ b/bin/ps/fmt.c
@@ -70,7 +70,7 @@ shquote(char **argv)
if (buf == NULL) {
if ((arg_max = sysconf(_SC_ARG_MAX)) == -1)
errx(1, "sysconf _SC_ARG_MAX failed");
- if (arg_max >= LONG_MAX / 4 || 4 * arg_max + 1 > SIZE_MAX)
+ if (arg_max >= LONG_MAX / 4 || 4 * arg_max + 1 > (long)SIZE_MAX)
errx(1, "sysconf _SC_ARG_MAX preposterously large");
buf_size = 4 * arg_max + 1;
if ((buf = malloc(buf_size)) == NULL)
diff --git a/bin/rcp/rcp.c b/bin/rcp/rcp.c
index f9b6789..224e75e 100644
--- a/bin/rcp/rcp.c
+++ b/bin/rcp/rcp.c
@@ -90,14 +90,15 @@ int pflag, iamremote, iamrecursive, targetshouldbedirectory;
int family = PF_UNSPEC;
static int argc_copy;
-static char **argv_copy;
+static const char **argv_copy;
+
+static char period[] = ".";
#define CMDNEEDS 64
char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
int response(void);
void rsource(char *, struct stat *);
-void run_err(const char *, ...) __printflike(1, 2);
void sink(int, char *[]);
void source(int, char *[]);
void tolocal(int, char *[]);
@@ -109,7 +110,7 @@ main(int argc, char *argv[])
{
struct servent *sp;
int ch, fflag, i, tflag;
- char *targ, *shell;
+ char *targ;
/*
* Prepare for execing ourselves.
@@ -163,9 +164,9 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- sp = getservbyname(shell = "shell", "tcp");
+ sp = getservbyname("shell", "tcp");
if (sp == NULL)
- errx(1, "%s/tcp: unknown service", shell);
+ errx(1, "shell/tcp: unknown service");
port = sp->s_port;
if ((pwd = getpwuid(userid = getuid())) == NULL)
@@ -217,7 +218,7 @@ toremote(char *targ, int argc, char *argv[])
*targ++ = 0;
if (*targ == 0)
- targ = ".";
+ targ = period;
if ((thost = strchr(argv[argc - 1], '@'))) {
/* user@host */
@@ -237,7 +238,7 @@ toremote(char *targ, int argc, char *argv[])
if (src) { /* remote to remote */
*src++ = 0;
if (*src == 0)
- src = ".";
+ src = period;
host = strchr(argv[i], '@');
len = strlen(_PATH_RSH) + strlen(argv[i]) +
strlen(src) + (tuser ? strlen(tuser) : 0) +
@@ -317,7 +318,7 @@ tolocal(int argc, char *argv[])
}
*src++ = 0;
if (*src == 0)
- src = ".";
+ src = period;
if ((host = strchr(argv[i], '@')) == NULL) {
host = argv[i];
suser = pwd->pw_name;
@@ -505,7 +506,8 @@ sink(int argc, char *argv[])
int amt, exists, first, mask, mode, ofd, omode;
size_t count;
int setimes, targisdir, wrerrno = 0;
- char ch, *cp, *np, *targ, *why, *vect[1], buf[BUFSIZ], path[PATH_MAX];
+ char ch, *cp, *np, *targ, *vect[1], buf[BUFSIZ], path[PATH_MAX];
+ const char *why;
#define atime tv[0]
#define mtime tv[1]
@@ -673,7 +675,7 @@ bad: run_err("%s: %s", np, strerror(errno));
/* Keep reading so we stay sync'd up. */
if (wrerr == NO) {
j = write(ofd, bp->buf, count);
- if (j != count) {
+ if (j != (off_t)count) {
wrerr = YES;
wrerrno = j >= 0 ? EIO : errno;
}
@@ -683,7 +685,7 @@ bad: run_err("%s: %s", np, strerror(errno));
}
}
if (count != 0 && wrerr == NO &&
- (j = write(ofd, bp->buf, count)) != count) {
+ (j = write(ofd, bp->buf, count)) != (off_t)count) {
wrerr = YES;
wrerrno = j >= 0 ? EIO : errno;
}
OpenPOWER on IntegriCloud