summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bernard <miniupnp@free.fr>2020-03-07 13:32:46 +0100
committerThomas Bernard <miniupnp@free.fr>2020-04-26 22:11:36 +0200
commit5e0eb5bbf43a350899d08dedd78d340a5da63985 (patch)
tree2140f1fe90d30c6995476be5d6e55b74005df67a
parent02875964eba5c4a2ea98c41562835428214adfe7 (diff)
downloadlibtiff-git-5e0eb5bbf43a350899d08dedd78d340a5da63985.tar.gz
tiffcmp: match exit status for posix cmp and diff tools
-rw-r--r--tools/tiffcmp.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/tools/tiffcmp.c b/tools/tiffcmp.c
index 7b764883..041d6a2d 100644
--- a/tools/tiffcmp.c
+++ b/tools/tiffcmp.c
@@ -39,6 +39,13 @@
#include "tiffio.h"
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
#ifndef HAVE_GETOPT
extern int getopt(int argc, char * const argv[], const char *optstring);
#endif
@@ -51,7 +58,7 @@ static uint16 sampleformat = SAMPLEFORMAT_UINT;
static uint32 imagewidth;
static uint32 imagelength;
-static void usage(void);
+static void usage(int code);
static int tiffcmp(TIFF*, TIFF*);
static int cmptags(TIFF*, TIFF*);
static int ContigCompare(int, uint32, unsigned char*, unsigned char*, tsize_t);
@@ -61,6 +68,12 @@ static void PrintFloatDiff(uint32, int, uint32, double, double);
static void leof(const char*, uint32, int);
+/*
+ * exit with status :
+ * 0 No differences were found.
+ * 1 Differences were found.
+ * >1 An error occurred.
+ */
int
main(int argc, char* argv[])
{
@@ -71,7 +84,7 @@ main(int argc, char* argv[])
extern char* optarg;
#endif
- while ((c = getopt(argc, argv, "ltz:")) != -1)
+ while ((c = getopt(argc, argv, "ltz:h")) != -1)
switch (c) {
case 'l':
stopondiff = 0;
@@ -82,18 +95,20 @@ main(int argc, char* argv[])
case 't':
stoponfirsttag = 0;
break;
+ case 'h':
+ usage(EXIT_SUCCESS);
case '?':
- usage();
+ usage(2);
/*NOTREACHED*/
}
if (argc - optind < 2)
- usage();
+ usage(2);
tif1 = TIFFOpen(argv[optind], "r");
if (tif1 == NULL)
- return (-1);
+ return (2);
tif2 = TIFFOpen(argv[optind+1], "r");
if (tif2 == NULL)
- return (-2);
+ return (2);
dirnum = 0;
while (tiffcmp(tif1, tif2)) {
if (!TIFFReadDirectory(tif1)) {
@@ -115,7 +130,7 @@ main(int argc, char* argv[])
return (0);
}
-char* stuff[] = {
+static const char* stuff[] = {
"usage: tiffcmp [options] file1 file2",
"where options are:",
" -l list each byte of image data that differs between the files",
@@ -125,16 +140,15 @@ NULL
};
static void
-usage(void)
+usage(int code)
{
- char buf[BUFSIZ];
int i;
+ FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
- setbuf(stderr, buf);
- fprintf(stderr, "%s\n\n", TIFFGetVersion());
+ fprintf(out, "%s\n\n", TIFFGetVersion());
for (i = 0; stuff[i] != NULL; i++)
- fprintf(stderr, "%s\n", stuff[i]);
- exit(-1);
+ fprintf(out, "%s\n", stuff[i]);
+ exit(code);
}
#define checkEOF(tif, row, sample) { \
@@ -177,7 +191,7 @@ tiffcmp(TIFF* tif1, TIFF* tif2)
buf2 = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(tif2));
if (buf1 == NULL || buf2 == NULL) {
fprintf(stderr, "No space for scanline buffers\n");
- exit(-1);
+ exit(2);
}
if (config1 != config2 && bitspersample != 8 && samplesperpixel > 1) {
fprintf(stderr,