summaryrefslogtreecommitdiffstats
path: root/sbin/md5
diff options
context:
space:
mode:
authorru <ru@FreeBSD.org>2001-05-22 10:33:43 +0000
committerru <ru@FreeBSD.org>2001-05-22 10:33:43 +0000
commit510c2815e80f70ff89d94661ce6e15efa6ee7481 (patch)
tree894fa2758dbdffbc3e26397e2aaf4802e76a443e /sbin/md5
parent39c66e3d7ae769a464ee651f049478a7a62a84c3 (diff)
downloadFreeBSD-src-510c2815e80f70ff89d94661ce6e15efa6ee7481.zip
FreeBSD-src-510c2815e80f70ff89d94661ce6e15efa6ee7481.tar.gz
Fix argument processing.
Make this compile with WARNS=2. PR: bin/27524 MFC after: 3 days
Diffstat (limited to 'sbin/md5')
-rw-r--r--sbin/md5/Makefile2
-rw-r--r--sbin/md5/global.h40
-rw-r--r--sbin/md5/md5.c96
3 files changed, 47 insertions, 91 deletions
diff --git a/sbin/md5/Makefile b/sbin/md5/Makefile
index 3522128..c2a1fd4 100644
--- a/sbin/md5/Makefile
+++ b/sbin/md5/Makefile
@@ -6,4 +6,6 @@ PROG= md5
LDADD+= -lmd
DPADD+= ${LIBMD}
+WARNS= 2
+
.include <bsd.prog.mk>
diff --git a/sbin/md5/global.h b/sbin/md5/global.h
deleted file mode 100644
index 3361ecf..0000000
--- a/sbin/md5/global.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* GLOBAL.H - RSAREF types and constants
- */
-
-/* PROTOTYPES should be set to one if and only if the compiler supports
- function argument prototyping.
-The following makes PROTOTYPES default to 0 if it has not already
- been defined with C compiler flags.
- */
-#ifndef PROTOTYPES
-#define PROTOTYPES 0
-#endif
-
-/* POINTER defines a generic pointer type */
-typedef unsigned char *POINTER;
-
-#if 0
-/* UINT2 defines a two byte word */
-typedef unsigned short int UINT2;
-
-/* UINT4 defines a four byte word */
-typedef unsigned long int UINT4;
-#else
-#include <sys/types.h>
-
-/* UINT2 defines a two byte word */
-typedef u_int16_t UINT2;
-
-/* UINT4 defines a four byte word */
-typedef u_int32_t UINT4;
-#endif /* 0 */
-
-/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
-If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
- returns an empty list.
- */
-#if PROTOTYPES
-#define PROTO_LIST(list) list
-#else
-#define PROTO_LIST(list) ()
-#endif
diff --git a/sbin/md5/md5.c b/sbin/md5/md5.c
index 1a803ed..76c2297 100644
--- a/sbin/md5/md5.c
+++ b/sbin/md5/md5.c
@@ -30,8 +30,6 @@ static const char rcsid[] =
#include <unistd.h>
#include <string.h>
-#include "global.h"
-
/*
* Length of test block, number of test blocks.
*/
@@ -41,11 +39,11 @@ static const char rcsid[] =
int qflag;
int rflag;
-static void MDString PROTO_LIST((char *));
-static void MDTimeTrial PROTO_LIST((void));
-static void MDTestSuite PROTO_LIST((void));
-static void MDFilter PROTO_LIST((int));
-static void usage PROTO_LIST((void));
+static void MDString(const char *);
+static void MDTimeTrial(void);
+static void MDTestSuite(void);
+static void MDFilter(int);
+static void usage(void);
/* Main driver.
@@ -57,53 +55,51 @@ Arguments (may be any combination):
(none) - digests standard input
*/
int
-main(argc, argv)
- int argc;
- char *argv[];
+main(int argc, char *argv[])
{
int ch;
char *p;
char buf[33];
- if (argc > 1) {
- while ((ch = getopt(argc, argv, "ps:qrtx")) != -1) {
- switch (ch) {
- case 'p':
- MDFilter(1);
- break;
- case 'q':
- qflag = 1;
- break;
- case 'r':
- rflag = 1;
- break;
- case 's':
- MDString(optarg);
- break;
- case 't':
- MDTimeTrial();
- break;
- case 'x':
- MDTestSuite();
- break;
- default:
- usage();
- }
+ while ((ch = getopt(argc, argv, "ps:qrtx")) != -1)
+ switch (ch) {
+ case 'p':
+ MDFilter(1);
+ break;
+ case 'q':
+ qflag = 1;
+ break;
+ case 'r':
+ rflag = 1;
+ break;
+ case 's':
+ MDString(optarg);
+ break;
+ case 't':
+ MDTimeTrial();
+ break;
+ case 'x':
+ MDTestSuite();
+ break;
+ default:
+ usage();
}
- while (optind < argc) {
- p = MD5File(argv[optind], buf);
+ argc -= optind;
+ argv += optind;
+
+ if (*argv) {
+ do {
+ p = MD5File(*argv, buf);
if (!p)
- warn("%s", argv[optind]);
+ warn("%s", *argv);
else
if (qflag)
printf("%s\n", p);
else if (rflag)
- printf("%s %s\n", p, argv[optind]);
+ printf("%s %s\n", p, *argv);
else
- printf("MD5 (%s) = %s\n", argv[optind],
- p);
- optind++;
- }
+ printf("MD5 (%s) = %s\n", *argv, p);
+ } while (*++argv);
} else
MDFilter(0);
@@ -113,8 +109,7 @@ main(argc, argv)
* Digests a string and prints the result.
*/
static void
-MDString(string)
- char *string;
+MDString(const char *string)
{
size_t len = strlen(string);
char buf[33];
@@ -130,7 +125,7 @@ MDString(string)
* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte blocks.
*/
static void
-MDTimeTrial()
+MDTimeTrial(void)
{
MD5_CTX context;
time_t endTime, startTime;
@@ -172,7 +167,7 @@ MDTimeTrial()
* Digests a reference suite of strings and prints the results.
*/
static void
-MDTestSuite()
+MDTestSuite(void)
{
printf("MD5 test suite:\n");
@@ -193,17 +188,16 @@ MDTestSuite()
* Digests the standard input and prints the result.
*/
static void
-MDFilter(pipe)
- int pipe;
+MDFilter(int tee)
{
MD5_CTX context;
- int len;
+ unsigned int len;
unsigned char buffer[BUFSIZ];
char buf[33];
MD5Init(&context);
while ((len = fread(buffer, 1, BUFSIZ, stdin))) {
- if(pipe && (len != fwrite(buffer, 1, len, stdout)))
+ if (tee && len != fwrite(buffer, 1, len, stdout))
err(1, "stdout");
MD5Update(&context, buffer, len);
}
@@ -211,7 +205,7 @@ MDFilter(pipe)
}
static void
-usage()
+usage(void)
{
fprintf(stderr, "usage: md5 [-pqrtx] [-s string] [files ...]\n");
OpenPOWER on IntegriCloud