WARNS=4 fixes. This would be WARNS=9 if we were -std=99 instead of
-ansi, due to 'long long'. Reviewed by: green (slightly earlier version)
This commit is contained in:
parent
28484399ed
commit
7503d74f54
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=111629
@ -3,8 +3,7 @@
|
||||
|
||||
PROG= dd
|
||||
SRCS= args.c conv.c conv_tab.c dd.c misc.c position.c
|
||||
WARNS= 0
|
||||
WFORMAT=0
|
||||
WARNS?= 4
|
||||
|
||||
MAINTAINER= green@FreeBSD.org
|
||||
|
||||
|
@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -67,7 +68,7 @@ static void f_obs(char *);
|
||||
static void f_of(char *);
|
||||
static void f_seek(char *);
|
||||
static void f_skip(char *);
|
||||
static u_quad_t get_num(const char *);
|
||||
static uintmax_t get_num(const char *);
|
||||
static off_t get_off_t(const char *);
|
||||
|
||||
static const struct arg {
|
||||
@ -167,8 +168,10 @@ jcl(char **argv)
|
||||
/*
|
||||
* Bail out if the calculation of a file offset would overflow.
|
||||
*/
|
||||
if (in.offset > QUAD_MAX / in.dbsz || out.offset > QUAD_MAX / out.dbsz)
|
||||
errx(1, "seek offsets cannot be larger than %qd", QUAD_MAX);
|
||||
if (in.offset > OFF_MAX / (ssize_t)in.dbsz ||
|
||||
out.offset > OFF_MAX / (ssize_t)out.dbsz)
|
||||
errx(1, "seek offsets cannot be larger than %jd",
|
||||
(intmax_t)OFF_MAX);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -182,7 +185,7 @@ c_arg(const void *a, const void *b)
|
||||
static void
|
||||
f_bs(char *arg)
|
||||
{
|
||||
u_quad_t res;
|
||||
uintmax_t res;
|
||||
|
||||
res = get_num(arg);
|
||||
if (res < 1 || res > SSIZE_MAX)
|
||||
@ -193,7 +196,7 @@ f_bs(char *arg)
|
||||
static void
|
||||
f_cbs(char *arg)
|
||||
{
|
||||
u_quad_t res;
|
||||
uintmax_t res;
|
||||
|
||||
res = get_num(arg);
|
||||
if (res < 1 || res > SSIZE_MAX)
|
||||
@ -204,15 +207,15 @@ f_cbs(char *arg)
|
||||
static void
|
||||
f_count(char *arg)
|
||||
{
|
||||
u_quad_t res;
|
||||
intmax_t res;
|
||||
|
||||
res = get_num(arg);
|
||||
if ((quad_t)res < 0)
|
||||
res = (intmax_t)get_num(arg);
|
||||
if (res < 0)
|
||||
errx(1, "count cannot be negative");
|
||||
if (res == 0)
|
||||
cpy_cnt = -1;
|
||||
cpy_cnt = (uintmax_t)-1;
|
||||
else
|
||||
cpy_cnt = (quad_t)res;
|
||||
cpy_cnt = (uintmax_t)res;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -221,18 +224,18 @@ f_files(char *arg)
|
||||
|
||||
files_cnt = get_num(arg);
|
||||
if (files_cnt < 1)
|
||||
errx(1, "files must be between 1 and %qd", QUAD_MAX);
|
||||
errx(1, "files must be between 1 and %jd", (uintmax_t)-1);
|
||||
}
|
||||
|
||||
static void
|
||||
f_ibs(char *arg)
|
||||
{
|
||||
u_quad_t res;
|
||||
uintmax_t res;
|
||||
|
||||
if (!(ddflags & C_BS)) {
|
||||
res = get_num(arg);
|
||||
if (res < 1 || res > SSIZE_MAX)
|
||||
errx(1, "ibs must be between 1 and %d", SSIZE_MAX);
|
||||
errx(1, "ibs must be between 1 and %zd", SSIZE_MAX);
|
||||
in.dbsz = (size_t)res;
|
||||
}
|
||||
}
|
||||
@ -247,12 +250,12 @@ f_if(char *arg)
|
||||
static void
|
||||
f_obs(char *arg)
|
||||
{
|
||||
u_quad_t res;
|
||||
uintmax_t res;
|
||||
|
||||
if (!(ddflags & C_BS)) {
|
||||
res = get_num(arg);
|
||||
if (res < 1 || res > SSIZE_MAX)
|
||||
errx(1, "obs must be between 1 and %d", SSIZE_MAX);
|
||||
errx(1, "obs must be between 1 and %zd", SSIZE_MAX);
|
||||
out.dbsz = (size_t)res;
|
||||
}
|
||||
}
|
||||
@ -329,7 +332,7 @@ c_conv(const void *a, const void *b)
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an expression of the following forms to a u_quad_t.
|
||||
* Convert an expression of the following forms to a uintmax_t.
|
||||
* 1) A positive decimal number.
|
||||
* 2) A positive decimal number followed by a b (mult by 512).
|
||||
* 3) A positive decimal number followed by a k (mult by 1 << 10).
|
||||
@ -340,10 +343,10 @@ c_conv(const void *a, const void *b)
|
||||
* separated by x (also * for backwards compatibility), specifying
|
||||
* the product of the indicated values.
|
||||
*/
|
||||
static u_quad_t
|
||||
static uintmax_t
|
||||
get_num(const char *val)
|
||||
{
|
||||
u_quad_t num, mult, prevnum;
|
||||
uintmax_t num, mult, prevnum;
|
||||
char *expr;
|
||||
|
||||
errno = 0;
|
||||
@ -406,14 +409,12 @@ get_num(const char *val)
|
||||
* Convert an expression of the following forms to an off_t. This is the
|
||||
* same as get_num(), but it uses signed numbers.
|
||||
*
|
||||
* The major problem here is that an off_t may not necessarily be a quad_t.
|
||||
* The right thing to do would be to use intmax_t when available and then
|
||||
* cast down to an off_t, if possible.
|
||||
* The major problem here is that an off_t may not necessarily be a intmax_t.
|
||||
*/
|
||||
static off_t
|
||||
get_off_t(const char *val)
|
||||
{
|
||||
quad_t num, mult, prevnum;
|
||||
intmax_t num, mult, prevnum;
|
||||
char *expr;
|
||||
|
||||
errno = 0;
|
||||
@ -457,7 +458,7 @@ get_off_t(const char *val)
|
||||
break;
|
||||
case '*': /* Backward compatible. */
|
||||
case 'x':
|
||||
mult = (quad_t)get_off_t(expr + 1);
|
||||
mult = (intmax_t)get_off_t(expr + 1);
|
||||
prevnum = num;
|
||||
num *= mult;
|
||||
if ((prevnum > 0) == (num > 0) && num / mult == prevnum)
|
||||
|
@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dd.h"
|
||||
@ -171,7 +172,8 @@ block(void)
|
||||
++st.trunc;
|
||||
|
||||
/* Toss characters to a newline. */
|
||||
for (; in.dbcnt && *inp++ != '\n'; --in.dbcnt);
|
||||
for (; in.dbcnt && *inp++ != '\n'; --in.dbcnt)
|
||||
;
|
||||
if (!in.dbcnt)
|
||||
intrunc = 1;
|
||||
else
|
||||
@ -223,8 +225,8 @@ unblock(void)
|
||||
|
||||
/* Translation and case conversion. */
|
||||
if ((t = ctab) != NULL)
|
||||
for (cnt = in.dbrcnt, inp = in.dbp; cnt--;)
|
||||
*--inp = t[*inp];
|
||||
for (inp = in.dbp - (cnt = in.dbrcnt); cnt--; ++inp)
|
||||
*inp = t[*inp];
|
||||
/*
|
||||
* Copy records (max cbsz size chunks) into the output buffer. The
|
||||
* translation has to already be done or we might not recognize the
|
||||
|
@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -77,11 +78,11 @@ static void setup(void);
|
||||
IO in, out; /* input/output state */
|
||||
STAT st; /* statistics */
|
||||
void (*cfunc)(void); /* conversion function */
|
||||
u_quad_t cpy_cnt; /* # of blocks to copy */
|
||||
uintmax_t cpy_cnt; /* # of blocks to copy */
|
||||
static off_t pending = 0; /* pending seek if sparse */
|
||||
u_int ddflags; /* conversion options */
|
||||
u_int ddflags = 0; /* conversion options */
|
||||
size_t cbsz; /* conversion block size */
|
||||
quad_t files_cnt = 1; /* # of files to copy */
|
||||
uintmax_t files_cnt = 1; /* # of files to copy */
|
||||
const u_char *ctab; /* conversion table */
|
||||
|
||||
int
|
||||
@ -247,7 +248,7 @@ dd_in(void)
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
if (st.in_full + st.in_part >= (u_quad_t)cpy_cnt)
|
||||
if (st.in_full + st.in_part >= (uintmax_t)cpy_cnt)
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
14
bin/dd/dd.h
14
bin/dd/dd.h
@ -62,13 +62,13 @@ typedef struct {
|
||||
} IO;
|
||||
|
||||
typedef struct {
|
||||
u_quad_t in_full; /* # of full input blocks */
|
||||
u_quad_t in_part; /* # of partial input blocks */
|
||||
u_quad_t out_full; /* # of full output blocks */
|
||||
u_quad_t out_part; /* # of partial output blocks */
|
||||
u_quad_t trunc; /* # of truncated records */
|
||||
u_quad_t swab; /* # of odd-length swab blocks */
|
||||
u_quad_t bytes; /* # of bytes written */
|
||||
uintmax_t in_full; /* # of full input blocks */
|
||||
uintmax_t in_part; /* # of partial input blocks */
|
||||
uintmax_t out_full; /* # of full output blocks */
|
||||
uintmax_t out_part; /* # of partial output blocks */
|
||||
uintmax_t trunc; /* # of truncated records */
|
||||
uintmax_t swab; /* # of odd-length swab blocks */
|
||||
uintmax_t bytes; /* # of bytes written */
|
||||
double start; /* start time of dd */
|
||||
} STAT;
|
||||
|
||||
|
@ -38,8 +38,6 @@
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
void block(void);
|
||||
void block_close(void);
|
||||
void dd_out(int);
|
||||
@ -57,10 +55,10 @@ void unblock_close(void);
|
||||
extern IO in, out;
|
||||
extern STAT st;
|
||||
extern void (*cfunc)(void);
|
||||
extern u_quad_t cpy_cnt;
|
||||
extern uintmax_t cpy_cnt;
|
||||
extern size_t cbsz;
|
||||
extern u_int ddflags;
|
||||
extern quad_t files_cnt;
|
||||
extern uintmax_t files_cnt;
|
||||
extern const u_char *ctab;
|
||||
extern const u_char a2e_32V[], a2e_POSIX[];
|
||||
extern const u_char e2a_32V[], e2a_POSIX[];
|
||||
|
@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -68,21 +69,21 @@ summary(void)
|
||||
secs = 1e-6;
|
||||
/* Use snprintf(3) so that we don't reenter stdio(3). */
|
||||
(void)snprintf(buf, sizeof(buf),
|
||||
"%qu+%qu records in\n%qu+%qu records out\n",
|
||||
"%ju+%ju records in\n%ju+%ju records out\n",
|
||||
st.in_full, st.in_part, st.out_full, st.out_part);
|
||||
(void)write(STDERR_FILENO, buf, strlen(buf));
|
||||
if (st.swab) {
|
||||
(void)snprintf(buf, sizeof(buf), "%qu odd length swab %s\n",
|
||||
(void)snprintf(buf, sizeof(buf), "%ju odd length swab %s\n",
|
||||
st.swab, (st.swab == 1) ? "block" : "blocks");
|
||||
(void)write(STDERR_FILENO, buf, strlen(buf));
|
||||
}
|
||||
if (st.trunc) {
|
||||
(void)snprintf(buf, sizeof(buf), "%qu truncated %s\n",
|
||||
(void)snprintf(buf, sizeof(buf), "%ju truncated %s\n",
|
||||
st.trunc, (st.trunc == 1) ? "block" : "blocks");
|
||||
(void)write(STDERR_FILENO, buf, strlen(buf));
|
||||
}
|
||||
(void)snprintf(buf, sizeof(buf),
|
||||
"%qu bytes transferred in %.6f secs (%.0f bytes/sec)\n",
|
||||
"%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
|
||||
st.bytes, secs, st.bytes / secs);
|
||||
(void)write(STDERR_FILENO, buf, strlen(buf));
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "dd.h"
|
||||
|
Loading…
Reference in New Issue
Block a user