summaryrefslogtreecommitdiffstats
path: root/bin/ls
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/ls
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/ls')
-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
4 files changed, 59 insertions, 61 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>
OpenPOWER on IntegriCloud