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