projects
/
skeinsum.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
43bc4f8
)
Add WARN macro.
author
Jason Self
<j@jxself.org>
Sat, 19 Sep 2015 03:56:15 +0000
(20:56 -0700)
committer
Jason Self
<j@jxself.org>
Sat, 19 Sep 2015 03:56:15 +0000
(20:56 -0700)
skein_cli.c
patch
|
blob
|
history
diff --git
a/skein_cli.c
b/skein_cli.c
index 67fc0777beeb565001dda90a9bfc8c2e7785ed53..63166f503ce762bc9edee940bca49d6e02399117 100644
(file)
--- a/
skein_cli.c
+++ b/
skein_cli.c
@@
-31,6
+31,8
@@
along with skeinsum. If not, see <http://www.gnu.org/licenses/>.
#include <errno.h>
#include "SHA3api_ref.h"
#include <errno.h>
#include "SHA3api_ref.h"
+#define WARN(msg, ...) fprintf(stderr, "skein%dsum: " msg, hashbitlen, ##__VA_ARGS__)
+
#define TRYHELP_GOODBYE() do { printf("Try 'skein%dsum --help' for more information.\n", hashbitlen); exit(1); } while(0)
typedef long long unsigned LLU;
#define TRYHELP_GOODBYE() do { printf("Try 'skein%dsum --help' for more information.\n", hashbitlen); exit(1); } while(0)
typedef long long unsigned LLU;
@@
-82,21
+84,21
@@
int HashFile(const char file_name[], char MsgDigest[], char mode)
struct stat st;
st.st_size = 0; /* ..needed when reading from stdio */
if (!is_stdin && stat(file_name, &st) < 0) {
struct stat st;
st.st_size = 0; /* ..needed when reading from stdio */
if (!is_stdin && stat(file_name, &st) < 0) {
-
printf("skein%dsum: %s: STAT FAILED: %s\n", hashbitlen
, file_name, strerror(errno));
+
WARN("%s: cannot stat: %s\n"
, file_name, strerror(errno));
return -1;
}
/* Get filesize */
size_t fsize = st.st_size;
if (fsize != st.st_size) {
return -1;
}
/* Get filesize */
size_t fsize = st.st_size;
if (fsize != st.st_size) {
-
printf("skein%dsum:
%s: SIZE WARNING: filesize %llu is too big for reading into memory!\n",
-
hashbitlen,
file_name, (long long unsigned)st.st_size);
+
WARN("
%s: SIZE WARNING: filesize %llu is too big for reading into memory!\n",
+ file_name, (long long unsigned)st.st_size);
}
/* Open file */
FILE *fp_in = is_stdin ? stdin : fopen(file_name, (mode == 't' ? "r" : "rb") );
if (!fp_in) {
}
/* Open file */
FILE *fp_in = is_stdin ? stdin : fopen(file_name, (mode == 't' ? "r" : "rb") );
if (!fp_in) {
-
printf("skein%dsum: %s: OPEN FAILED: %s\n", hashbitlen
, file_name, strerror(errno));
+
WARN("%s: cannot open: %s\n"
, file_name, strerror(errno));
return -1;
}
return -1;
}
@@
-112,7
+114,7
@@
int HashFile(const char file_name[], char MsgDigest[], char mode)
}
if (!readbuf) {
}
if (!readbuf) {
-
printf("skein%dsum: %s: MEM FAILED: %s\n", hashbitlen
, file_name, strerror(errno));
+
WARN("%s: MEM FAILED: error %s\n"
, file_name, strerror(errno));
if (!is_stdin)
fclose(fp_in);
return -1;
if (!is_stdin)
fclose(fp_in);
return -1;
@@
-137,11
+139,11
@@
int HashFile(const char file_name[], char MsgDigest[], char mode)
newbuf = realloc(readbuf, bufsize * 2);
if (!newbuf) {
if (total_readed < st.st_size) {
newbuf = realloc(readbuf, bufsize * 2);
if (!newbuf) {
if (total_readed < st.st_size) {
-
printf("skein%dsum:
%s: MEM WARNING: %llu bytes only readed from %llu\n",
-
hashbitlen,
file_name, (LLU)total_readed, (LLU)st.st_size);
+
WARN("
%s: MEM WARNING: %llu bytes only readed from %llu\n",
+ file_name, (LLU)total_readed, (LLU)st.st_size);
} else {
} else {
-
printf("skein%dsum:
%s: MEM WARNING: %llu bytes only readed.\n",
-
hashbitlen,
file_name, (LLU)total_readed);
+
WARN("
%s: MEM WARNING: %llu bytes only readed.\n",
+ file_name, (LLU)total_readed);
}
break;
}
}
break;
}
@@
-154,8
+156,8
@@
int HashFile(const char file_name[], char MsgDigest[], char mode)
fclose(fp_in);
if (!is_stdin && total_readed < st.st_size && total_readed < bufsize) {
fclose(fp_in);
if (!is_stdin && total_readed < st.st_size && total_readed < bufsize) {
-
printf("skein%dsum:
%s: READ WARNING: filesize=%llu, readed=%llu, error %d, %s\n",
-
hashbitlen,
file_name, (LLU)st.st_size, (LLU)total_readed, errno, strerror(errno));
+
WARN("
%s: READ WARNING: filesize=%llu, readed=%llu, error %d, %s\n",
+ file_name, (LLU)st.st_size, (LLU)total_readed, errno, strerror(errno));
}
if (getenv("SKEIN_DUMP")) {
}
if (getenv("SKEIN_DUMP")) {
@@
-342,7
+344,7
@@
int VerifyHashesFromFile(FILE *fp, int status, int warn, int quiet)
else if (!isProper(MsgDigest_tmp))
{
if(status != 1 && warn == 1)
else if (!isProper(MsgDigest_tmp))
{
if(status != 1 && warn == 1)
-
fprintf(stderr, "skein%dsum: %s: %d: improperly formatted skein%d checksum line\n",hashbitlen
,file_tmp,line,hashbitlen);
+
WARN("%s: %d: improperly formatted skein%d checksum line\n"
,file_tmp,line,hashbitlen);
NotProper ++;
NoMatch ++;
}
NotProper ++;
NoMatch ++;
}
@@
-353,12
+355,12
@@
int VerifyHashesFromFile(FILE *fp, int status, int warn, int quiet)
}
if(NoMatch)
{
}
if(NoMatch)
{
-
fprintf(stderr, "skein%dsum:
WARNING: %d of %d computed checksums did NOT match\n",
-
hashbitlen,NoMatch,
Computed);
+
WARN("
WARNING: %d of %d computed checksums did NOT match\n",
+
NoMatch,
Computed);
}
if(NotProper)
{
}
if(NotProper)
{
-
fprintf(stderr, "skein%dsum: WARNING: %d line is improperly formatted\n",hashbitlen,
NotProper);
+
WARN("WARNING: %d line is improperly formatted\n",
NotProper);
}
return (NotProper || NoMatch) ? -1 : 1;
}
}
return (NotProper || NoMatch) ? -1 : 1;
}
@@
-409,7
+411,7
@@
int is_goodfile(const char filename[])
struct stat s;
if (stat(filename, &s) < 0) {
struct stat s;
if (stat(filename, &s) < 0) {
-
fprintf(stderr, "skein%dsum: %s: no such file or directory\n", hashbitlen
, filename);
+
WARN("%s: no such file or directory\n"
, filename);
return 0;
}
return 0;
}
@@
-420,11
+422,11
@@
int is_goodfile(const char filename[])
if (S_ISFIFO(s.st_mode)) return 1;
if (S_ISDIR (s.st_mode)) {
if (S_ISFIFO(s.st_mode)) return 1;
if (S_ISDIR (s.st_mode)) {
-
fprintf(stderr, "skein%dsum: %s: is a directory\n", hashbitlen
, filename);
+
WARN("%s: is a directory\n"
, filename);
return 0;
}
return 0;
}
-
fprintf(stderr, "skein%dsum: %s: WARNING: wrong filetype 0x%Xu\n", hashbitlen
, filename, s.st_mode);
+
WARN("%s: WARNING: unknown filetype 0x%Xu\n"
, filename, s.st_mode);
return 1; /* try it as good */
}
return 1; /* try it as good */
}
@@
-475,11
+477,11
@@
int main(int argc, char** argv)
if (quiet == 1 || warn == 1 || status == 1)
{
if(quiet == 1)
if (quiet == 1 || warn == 1 || status == 1)
{
if(quiet == 1)
-
fprintf(stderr, "skein%dsum: the --quiet option is meaningful only when verifying checksums\n", hashbitlen
);
+
WARN("the --quiet option is meaningful only when verifying checksums\n"
);
if(status ==1)
if(status ==1)
-
fprintf(stderr, "skein%dsum: the --status option is meaningful only when verifying checksums\n", hashbitlen
);
+
WARN("the --status option is meaningful only when verifying checksums\n"
);
if(warn == 1)
if(warn == 1)
-
fprintf(stderr, "skein%dsum: the --warn option is meaningful only when verifying checksums\n", hashbitlen
);
+
WARN("the --warn option is meaningful only when verifying checksums\n"
);
TRYHELP_GOODBYE();
}
TRYHELP_GOODBYE();
}
@@
-495,7
+497,7
@@
int main(int argc, char** argv)
}
if (binary > 0 && hashString == 1) {
}
if (binary > 0 && hashString == 1) {
-
printf("skein%dsum: %s: No such file or directory\n", hashbitlen
, filename);
+
WARN("%s: No such file or directory\n"
, filename);
continue;
}
continue;
}
@@
-515,9
+517,9
@@
int main(int argc, char** argv)
if (tag == 1 || binary >= 0)
{
if (tag == 1)
if (tag == 1 || binary >= 0)
{
if (tag == 1)
-
fprintf(stderr, "skein%dsum: the --tag option is meaningless when verifying checksums\n", hashbitlen
);
+
WARN("the --tag option is meaningless when verifying checksums\n"
);
if (binary >= 0)
if (binary >= 0)
-
fprintf(stderr, "skein%dsum: the --text and --binary options are meaningless when verifying checksums\n", hashbitlen
);
+
WARN("the --text and --binary options are meaningless when verifying checksums\n"
);
TRYHELP_GOODBYE();
}
TRYHELP_GOODBYE();
}
@@
-533,7
+535,7
@@
int main(int argc, char** argv)
FILE *fp = (strcmp(filename, "-") == 0) ? stdin : fopen(filename, "r");
if (!fp) {
errorFound++;
FILE *fp = (strcmp(filename, "-") == 0) ? stdin : fopen(filename, "r");
if (!fp) {
errorFound++;
-
printf("skein%dsum: %s: error %d, %s\n", hashbitlen, filename, errno
, strerror(errno));
+
WARN("%s: %s\n", filename
, strerror(errno));
continue;
}
if (VerifyHashesFromFile(fp, status, warn, quiet) < 0)
continue;
}
if (VerifyHashesFromFile(fp, status, warn, quiet) < 0)