Browse code

return codes cleanup (bb#1159)

git-svn: trunk@4749

Tomasz Kojm authored on 2009/02/12 22:53:23
Showing 30 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Feb 12 15:22:17 CET 2009 (tk)
2
+---------------------------------
3
+ * libclamav: return codes cleanup (bb#1159)
4
+
1 5
 Wed Feb 11 11:08:55 CET 2009 (tk)
2 6
 ---------------------------------
3 7
  * libclamav/cvd.c: fix warning when cvd timestamp is in the future (bb#1381)
... ...
@@ -358,13 +358,13 @@ static int ea05(int desc, cli_ctx *ctx, char *tmpd) {
358 358
     if((i = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
359 359
       cli_dbgmsg("autoit: Can't create file %s\n", tempfile);
360 360
       free(UNP.outputbuf);
361
-      return CL_EIO;
361
+      return CL_ECREAT;
362 362
     }
363 363
     if(cli_writen(i, UNP.outputbuf, UNP.usize) != (int32_t)UNP.usize) {
364 364
       cli_dbgmsg("autoit: cannot write %d bytes\n", UNP.usize);
365 365
       close(i);
366 366
       free(UNP.outputbuf);
367
-      return CL_EIO;
367
+      return CL_EWRITE;
368 368
     }
369 369
     free(UNP.outputbuf);
370 370
     if(ctx->engine->keeptmp)
... ...
@@ -375,12 +375,12 @@ static int ea05(int desc, cli_ctx *ctx, char *tmpd) {
375 375
     if(cli_magic_scandesc(i, ctx) == CL_VIRUS) {
376 376
       close(i);
377 377
       if(!ctx->engine->keeptmp)
378
-        if(cli_unlink(tempfile)) return CL_EIO;
378
+        if(cli_unlink(tempfile)) return CL_EUNLINK;
379 379
       return CL_VIRUS;
380 380
     }
381 381
     close(i);
382 382
     if(!ctx->engine->keeptmp) 
383
-      if (cli_unlink(tempfile)) return CL_EIO;
383
+      if (cli_unlink(tempfile)) return CL_EUNLINK;
384 384
   }
385 385
   return ret;
386 386
 }
... ...
@@ -868,13 +868,13 @@ static int ea06(int desc, cli_ctx *ctx, char *tmpd) {
868 868
     if((i = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
869 869
       cli_dbgmsg("autoit: Can't create file %s\n", tempfile);
870 870
       free(buf);
871
-      return CL_EIO;
871
+      return CL_ECREAT;
872 872
     }
873 873
     if(cli_writen(i, buf, UNP.cur_output) != (int32_t)UNP.cur_output) {
874 874
       cli_dbgmsg("autoit: cannot write %d bytes\n", UNP.usize);
875 875
       close(i);
876 876
       free(buf);
877
-      return CL_EIO;
877
+      return CL_EWRITE;
878 878
     }
879 879
     free(buf);
880 880
     if(ctx->engine->keeptmp)
... ...
@@ -885,12 +885,12 @@ static int ea06(int desc, cli_ctx *ctx, char *tmpd) {
885 885
     if(cli_magic_scandesc(i, ctx) == CL_VIRUS) {
886 886
       close(i);
887 887
       if(!ctx->engine->keeptmp) 
888
-        if (cli_unlink(tempfile)) return CL_EIO;
888
+        if (cli_unlink(tempfile)) return CL_EUNLINK;
889 889
       return CL_VIRUS;
890 890
     }
891 891
     close(i);
892 892
     if(!ctx->engine->keeptmp)
893
-      if (cli_unlink(tempfile)) return CL_EIO;
893
+      if (cli_unlink(tempfile)) return CL_EUNLINK;
894 894
   }
895 895
   return ret;
896 896
 }
... ...
@@ -908,7 +908,7 @@ int cli_scanautoit(int desc, cli_ctx *ctx, off_t offset) {
908 908
 
909 909
   lseek(desc, offset, SEEK_SET);
910 910
   if (cli_readn(desc, &version, 1)!=1)
911
-    return CL_EIO;
911
+    return CL_EREAD;
912 912
 
913 913
   cli_dbgmsg("in scanautoit()\n");
914 914
 
... ...
@@ -145,7 +145,7 @@ cli_binhex(const char *dir, int desc)
145 145
 	start = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, 0);
146 146
 	if(buf == MAP_FAILED) {
147 147
 		messageDestroy(m);
148
-		return CL_EMEM;
148
+		return CL_EMAP;
149 149
 	}
150 150
 
151 151
 	cli_dbgmsg("mmap'ed binhex file\n");
... ...
@@ -211,6 +211,7 @@ cli_binhex(const char *dir, int desc)
211 211
 
212 212
 	if(fb)
213 213
 		return CL_CLEAN;	/* a lie - but it gets things going */
214
-	return CL_EIO;	/* probably CL_EMEM, but we can't tell at this layer */
214
+	/* return CL_EIO; */	/* probably CL_EMEM, but we can't tell at this layer */
215
+	return CL_EMEM;
215 216
 #endif
216 217
 }
... ...
@@ -104,7 +104,7 @@ static char *cab_readstr(int fd, int *ret)
104 104
 
105 105
 
106 106
     if((pos = lseek(fd, 0, SEEK_CUR)) == -1) {
107
-	*ret = CL_EIO;
107
+	*ret = CL_ESEEK;
108 108
 	return NULL;
109 109
     }
110 110
 
... ...
@@ -206,7 +206,7 @@ int cab_open(int fd, off_t offset, struct cab_archive *cab)
206 206
 
207 207
     if(lseek(fd, offset, SEEK_SET) == -1) {
208 208
 	cli_errmsg("cab_open: Can't lseek to %u (offset)\n", (unsigned int) offset);
209
-	return CL_EIO;
209
+	return CL_ESEEK;
210 210
     }
211 211
 
212 212
     if(cli_readn(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
... ...
@@ -223,7 +223,7 @@ int cab_open(int fd, off_t offset, struct cab_archive *cab)
223 223
 
224 224
     if(fstat(fd, &sb) == -1) {
225 225
 	cli_errmsg("cab_open: Can't fstat descriptor %d\n", fd);
226
-	return CL_EIO;
226
+	return CL_ESTAT;
227 227
     }
228 228
     rsize = sb.st_size;
229 229
 
... ...
@@ -577,7 +577,7 @@ static int cab_unstore(struct cab_file *file, int bytes)
577 577
 	    return file->error;
578 578
 	} else if(cli_writen(file->ofd, buff, bread) != bread) {
579 579
 	    cli_warnmsg("cab_unstore: Can't write %d bytes to descriptor %d\n", bread, file->ofd);
580
-	    return CL_EIO;
580
+	    return CL_EWRITE;
581 581
 	}
582 582
 
583 583
 	todo -= bread;
... ...
@@ -631,7 +631,7 @@ static int cab_unstore(struct cab_file *file, int bytes)
631 631
 	}								\
632 632
 	if((file->folder->cmethod & 0x000f) && !file->cab->state->stream) { \
633 633
 	    close(file->ofd);						\
634
-	    return CL_EMSCAB;						\
634
+	    return CL_EUNPACK;						\
635 635
 	}								\
636 636
 	file->cab->actfol = file->folder;				\
637 637
     } else {								\
... ...
@@ -669,7 +669,7 @@ int cab_extract(struct cab_file *file, const char *name)
669 669
     file->ofd = open(name, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU);
670 670
     if(file->ofd == -1) {
671 671
 	cli_errmsg("cab_extract: Can't open file %s in write mode\n", name);
672
-	return CL_EIO;
672
+	return CL_ECREAT;
673 673
     }
674 674
 
675 675
     switch(file->folder->cmethod & 0x000f) {
... ...
@@ -824,12 +824,11 @@ int cli_chm_extract_file(int fd, char *dirname, chm_metadata_t *metadata)
824 824
 	snprintf(filename, 1024, "%s/%lu.chm", dirname, (unsigned long int) metadata->file_offset);
825 825
 	metadata->ofd = open(filename, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU);
826 826
 	if (metadata->ofd < 0) {
827
-		return CL_EIO;
827
+		return CL_ECREAT;
828 828
 	}
829 829
 	if (chm_copy_file_data(metadata->ufd, metadata->ofd, metadata->file_length) != metadata->file_length) {
830 830
 		cli_dbgmsg("failed to copy %lu bytes\n", (unsigned long int) metadata->file_length);
831 831
 		close(metadata->ofd);
832
-		/* return CL_EIO; */
833 832
 		return CL_EFORMAT; /* most likely a corrupted file */
834 833
 	}
835 834
 		
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2007-2008 Sourcefire, Inc.
2
+ *  Copyright (C) 2007-2009 Sourcefire, Inc.
3 3
  *
4 4
  *  Authors: Tomasz Kojm
5 5
  *
... ...
@@ -32,38 +32,39 @@ extern "C"
32 32
 #define CL_COUNT_PRECISION 4096
33 33
 
34 34
 /* return codes */
35
-#define CL_CLEAN	0   /* no virus found */
36
-#define CL_VIRUS	1   /* virus(es) found */
37
-#define CL_SUCCESS	CL_CLEAN
38
-#define CL_BREAK	2
39
-
40
-#define CL_EMAXREC	-100 /* (internal) recursion limit exceeded */
41
-#define CL_EMAXSIZE	-101 /* (internal) size limit exceeded */
42
-#define CL_EMAXFILES	-102 /* (internal) files limit exceeded */
43
-#define CL_ERAR		-103 /* rar handler error */
44
-#define CL_EZIP		-104 /* zip handler error */
45
-#define CL_EGZIP	-105 /* gzip handler error */
46
-#define CL_EBZIP	-106 /* bzip2 handler error */
47
-#define CL_EOLE2	-107 /* OLE2 handler error */
48
-#define CL_EMSCOMP	-108 /* MS Expand handler error */
49
-#define CL_EMSCAB	-109 /* MS CAB module error */
50
-#define CL_EACCES	-110 /* access denied */
51
-#define CL_ENULLARG	-111 /* null argument */
52
-#define CL_ETMPFILE	-112 /* tmpfile() failed */
53
-/* #define CL_EFSYNC	-113 *//* fsync() failed */
54
-#define CL_EMEM		-114 /* memory allocation error */
55
-#define CL_EOPEN	-115 /* file open error */
56
-#define CL_EMALFDB	-116 /* malformed database */
57
-#define CL_EPATSHORT	-117 /* pattern too short */
58
-#define CL_ETMPDIR	-118 /* mkdir() failed */
59
-#define CL_ECVD		-119 /* not a CVD file (or broken) */
60
-#define CL_ECVDEXTR	-120 /* CVD extraction failure */
61
-#define CL_EMD5		-121 /* MD5 verification error */
62
-#define CL_EDSIG	-122 /* digital signature verification error */
63
-#define CL_EIO		-123 /* general I/O error */
64
-#define CL_EFORMAT	-124 /* (internal) bad format or broken file */
65
-#define CL_ESUPPORT	-125 /* not supported data format */
66
-#define CL_EARJ         -127 /* ARJ handler error */
35
+typedef enum {
36
+    /* libclamav specific */
37
+    CL_CLEAN = 0,
38
+    CL_SUCCESS = 0,
39
+    CL_VIRUS,
40
+    CL_ENULLARG,
41
+    CL_EMALFDB,
42
+    CL_ECVD,
43
+    CL_EVERIFY,
44
+    CL_EUNPACK,
45
+
46
+    /* I/O and memory errors */
47
+    CL_EOPEN,
48
+    CL_ECREAT,
49
+    CL_EUNLINK,
50
+    CL_ESTAT,
51
+    CL_EREAD,
52
+    CL_ESEEK,
53
+    CL_EWRITE,
54
+    CL_EDUP,
55
+    CL_EACCES,
56
+    CL_ETMPFILE,
57
+    CL_ETMPDIR,
58
+    CL_EMAP,
59
+    CL_EMEM,
60
+
61
+    /* internal (not reported outside libclamav) */
62
+    CL_BREAK,
63
+    CL_EMAXREC,
64
+    CL_EMAXSIZE,
65
+    CL_EMAXFILES,
66
+    CL_EFORMAT
67
+} cl_error_t;
67 68
 
68 69
 /* db options */
69 70
 #define CL_DB_PHISHING	    0x2
... ...
@@ -210,19 +210,19 @@ static int cli_tgzload(int fd, struct cl_engine *engine, unsigned int *signo, un
210 210
 
211 211
     if((fdd = dup(fd)) == -1) {
212 212
 	cli_errmsg("cli_tgzload: Can't duplicate descriptor %d\n", fd);
213
-	return CL_EIO;
213
+	return CL_EDUP;
214 214
     }
215 215
 
216 216
     if(compr) {
217 217
 	if((dbio.gzs = gzdopen(fdd, "rb")) == NULL) {
218 218
 	    cli_errmsg("cli_tgzload: Can't gzdopen() descriptor %d, errno = %d\n", fdd, errno);
219
-	    return CL_EIO;
219
+	    return CL_EOPEN;
220 220
 	}
221 221
 	dbio.fs = NULL;
222 222
     } else {
223 223
 	if((dbio.fs = fdopen(fdd, "rb")) == NULL) {
224 224
 	    cli_errmsg("cli_tgzload: Can't fdopen() descriptor %d, errno = %d\n", fdd, errno);
225
-	    return CL_EIO;
225
+	    return CL_EOPEN;
226 226
 	}
227 227
 	dbio.gzs = NULL;
228 228
     }
... ...
@@ -470,14 +470,14 @@ static int cli_cvdverify(FILE *fs, struct cl_cvd *cvdpt, unsigned int cld)
470 470
 	cli_dbgmsg("cli_cvdverify: MD5 verification error\n");
471 471
 	free(md5);
472 472
 	cl_cvdfree(cvd);
473
-	return CL_EMD5;
473
+	return CL_EVERIFY;
474 474
     }
475 475
 
476 476
     if(cli_versig(md5, cvd->dsig)) {
477 477
 	cli_dbgmsg("cli_cvdverify: Digital signature verification error\n");
478 478
 	free(md5);
479 479
 	cl_cvdfree(cvd);
480
-	return CL_EDSIG;
480
+	return CL_EVERIFY;
481 481
     }
482 482
 
483 483
     free(md5);
... ...
@@ -549,7 +549,7 @@ int cli_cvdload(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigne
549 549
      */ 
550 550
     if(lseek(cfd, 512, SEEK_SET) == -1) {
551 551
 	cli_errmsg("cli_cvdload(): lseek(fs, 512, SEEK_SET) failed\n");
552
-	return CL_EIO;
552
+	return CL_ESEEK;
553 553
     }
554 554
 
555 555
     if(daily) {
... ...
@@ -575,7 +575,7 @@ int cli_cvdload(FILE *fs, struct cl_engine *engine, unsigned int *signo, unsigne
575 575
 	if(cli_untgz(cfd, dir)) {
576 576
 	    cli_errmsg("cli_cvdload(): Can't unpack CVD file.\n");
577 577
 	    free(dir);
578
-	    return CL_ECVDEXTR;
578
+	    return CL_ECVD;
579 579
 	}
580 580
 
581 581
 	/* load extracted directory */
... ...
@@ -111,7 +111,7 @@ int cli_versig(const char *md5, const char *dsig)
111 111
     if(strlen(md5) != 32 || !isalnum(md5[0])) {
112 112
 	/* someone is trying to fool us with empty/malformed MD5 ? */
113 113
 	cli_errmsg("SECURITY WARNING: MD5 basic test failure.\n");
114
-	return CL_EMD5;
114
+	return CL_EVERIFY;
115 115
     }
116 116
 
117 117
     mp_init(&n);
... ...
@@ -122,7 +122,7 @@ int cli_versig(const char *md5, const char *dsig)
122 122
     if(!(pt = (char *) cli_decodesig(dsig, 16, e, n))) {
123 123
 	mp_clear(&n);
124 124
 	mp_clear(&e);
125
-	return CL_EDSIG;
125
+	return CL_EVERIFY;
126 126
     }
127 127
 
128 128
     pt2 = cli_str2hex(pt, 16);
... ...
@@ -135,7 +135,7 @@ int cli_versig(const char *md5, const char *dsig)
135 135
 	free(pt2);
136 136
 	mp_clear(&n);
137 137
 	mp_clear(&e);
138
-	return CL_EDSIG;
138
+	return CL_EVERIFY;
139 139
     }
140 140
 
141 141
     free(pt2);
... ...
@@ -315,7 +315,7 @@ static inline int buf_outc(char c, struct buf *buf)
315 315
 {
316 316
 	if(buf->pos >= sizeof(buf->buf)) {
317 317
 		if(write(buf->outfd, buf->buf, sizeof(buf->buf)) != sizeof(buf->buf))
318
-			return CL_EIO;
318
+			return CL_EWRITE;
319 319
 		buf->pos = 0;
320 320
 	}
321 321
 	buf->buf[buf->pos++] = c;
... ...
@@ -338,7 +338,7 @@ static inline int buf_outs(const char *s, struct buf *buf)
338 338
 		}
339 339
 		if(i == buf_len) {
340 340
 			if(write(buf->outfd, buf->buf, buf_len) < 0)
341
-				return CL_EIO;
341
+				return CL_EWRITE;
342 342
 		       i = 0;
343 343
 		}
344 344
 	}
... ...
@@ -61,8 +61,10 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
61 61
 	}
62 62
     }
63 63
 
64
-    if(len < root->ac_mindepth)
65
-	return CL_EPATSHORT;
64
+    if(len < root->ac_mindepth) {
65
+	/* cli_errmsg("cli_ac_addpatt: Signature for %s is too short\n", pattern->virname); */
66
+	return CL_EMALFDB;
67
+    }
66 68
 
67 69
     pt = root->ac_root;
68 70
 
... ...
@@ -1124,8 +1126,11 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1124 1124
 	return CL_ENULLARG;
1125 1125
     }
1126 1126
 
1127
-    if(strlen(hexsig) / 2 < root->ac_mindepth)
1128
-	return CL_EPATSHORT;
1127
+    if(strlen(hexsig) / 2 < root->ac_mindepth) {
1128
+	cli_errmsg("cli_ac_addsig: Signature for %s is too short\n", virname);
1129
+	return CL_EMALFDB;
1130
+    }
1131
+
1129 1132
     if((new = (struct cli_ac_patt *) mpool_calloc(root->mempool, 1, sizeof(struct cli_ac_patt))) == NULL)
1130 1133
 	return CL_EMEM;
1131 1134
 
... ...
@@ -46,8 +46,8 @@ int cli_bm_addpatt(struct cli_matcher *root, struct cli_bm_patt *pattern)
46 46
 
47 47
 
48 48
     if(pattern->length < BM_MIN_LENGTH) {
49
-	cli_errmsg("Signature for %s is too short\n", pattern->virname);
50
-	return CL_EPATSHORT;
49
+	cli_errmsg("cli_bm_addpatt: Signature for %s is too short\n", pattern->virname);
50
+	return CL_EMALFDB;
51 51
     }
52 52
 
53 53
 #if BM_MIN_LENGTH == BM_BLOCK_SIZE
... ...
@@ -480,7 +480,7 @@ cli_mbox(const char *dir, int desc, cli_ctx *ctx)
480 480
 
481 481
 	start = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, 0);
482 482
 	if(start == MAP_FAILED)
483
-		return CL_EMEM;
483
+		return CL_EMAP;
484 484
 
485 485
 	cli_dbgmsg("mmap'ed mbox\n");
486 486
 
... ...
@@ -1233,7 +1233,7 @@ cli_parse_mbox(const char *dir, int desc, cli_ctx *ctx)
1233 1233
 		/* empty message */
1234 1234
 		fclose(fd);
1235 1235
 #ifdef	SAVE_TMP
1236
-		if (cli_unlink(tmpfilename)) return CL_EIO;
1236
+		if (cli_unlink(tmpfilename)) return CL_EUNLINK;
1237 1237
 #endif
1238 1238
 		return CL_CLEAN;
1239 1239
 	}
... ...
@@ -1251,7 +1251,7 @@ cli_parse_mbox(const char *dir, int desc, cli_ctx *ctx)
1251 1251
 #endif
1252 1252
 			fclose(fd);
1253 1253
 #ifdef	SAVE_TMP
1254
-			if (cli_unlink(tmpfilename)) return CL_EIO;
1254
+			if (cli_unlink(tmpfilename)) return CL_EUNLINK;
1255 1255
 #endif
1256 1256
 			return CL_EMEM;
1257 1257
 		}
... ...
@@ -1312,7 +1312,7 @@ cli_parse_mbox(const char *dir, int desc, cli_ctx *ctx)
1312 1312
 			signal(SIGSEGV, segv);
1313 1313
 #endif
1314 1314
 #ifdef	SAVE_TMP
1315
-			if (cli_unlink(tmpfilename)) return CL_EIO;
1315
+			if (cli_unlink(tmpfilename)) return CL_EUNLINK;
1316 1316
 #endif
1317 1317
 			return CL_EMEM;
1318 1318
 		}
... ...
@@ -1472,7 +1472,7 @@ cli_parse_mbox(const char *dir, int desc, cli_ctx *ctx)
1472 1472
 #endif
1473 1473
 
1474 1474
 #ifdef	SAVE_TMP
1475
-	if (cli_unlink(tmpfilename)) return CL_EIO;
1475
+	if (cli_unlink(tmpfilename)) return CL_EUNLINK;
1476 1476
 #endif
1477 1477
 	return retcode;
1478 1478
 }
... ...
@@ -73,7 +73,7 @@ struct msexp_hdr {
73 73
 #define READBYTES				\
74 74
     ret = cli_readn(fd, rbuff, RWBUFF);		\
75 75
     if(ret == -1)				\
76
-	return CL_EIO;				\
76
+	return CL_EREAD;			\
77 77
     if(!ret)					\
78 78
 	break;					\
79 79
     rbytes = (unsigned int) ret;		\
... ...
@@ -82,7 +82,7 @@ struct msexp_hdr {
82 82
 #define WRITEBYTES				\
83 83
     ret = cli_writen(ofd, wbuff, w);		\
84 84
     if(ret == -1 || (unsigned int) ret != w)	\
85
-	return CL_EIO;				\
85
+	return CL_EWRITE;			\
86 86
     wbytes += w;				\
87 87
     if(wbytes >= EC32(hdr.fsize))		\
88 88
 	return CL_SUCCESS;			\
... ...
@@ -99,7 +99,7 @@ int cli_msexpand(int fd, int ofd, cli_ctx *ctx)
99 99
 
100 100
 
101 101
     if(cli_readn(fd, &hdr, sizeof(hdr)) == -1)
102
-	return CL_EIO;
102
+	return CL_EREAD;
103 103
 
104 104
     if(EC32(hdr.magic1) != MAGIC1 || EC32(hdr.magic2) != MAGIC2 || EC16(hdr.magic3) != MAGIC3) {
105 105
 	cli_dbgmsg("MSEXPAND: Not supported file format\n");
... ...
@@ -624,7 +624,7 @@ int mszip_decompress(struct mszip_stream *zip, off_t out_bytes) {
624 624
   if ((off_t) i > out_bytes) i = (int) out_bytes;
625 625
   if (i) {
626 626
     if (zip->wflag && cli_writen(zip->ofd, zip->o_ptr, i) != i) {
627
-      return zip->error = CL_EIO;
627
+      return zip->error = CL_EWRITE;
628 628
     }
629 629
     zip->o_ptr  += i;
630 630
     out_bytes   -= i;
... ...
@@ -670,7 +670,7 @@ int mszip_decompress(struct mszip_stream *zip, off_t out_bytes) {
670 670
     i = (out_bytes < (off_t)zip->bytes_output) ?
671 671
       (int)out_bytes : zip->bytes_output;
672 672
     if (zip->wflag && cli_writen(zip->ofd, zip->o_ptr, i) != i) {
673
-      return zip->error = CL_EIO;
673
+      return zip->error = CL_EWRITE;
674 674
     }
675 675
 
676 676
     /* mspack errors (i.e. read errors) are fatal and can't be recovered */
... ...
@@ -766,7 +766,7 @@ static int lzx_read_input(struct lzx_stream *lzx) {
766 766
   if (bread == 0) {
767 767
     if (lzx->input_end) {
768 768
       cli_dbgmsg("lzx_read_input: out of input bytes\n");
769
-      return lzx->error = CL_EIO;
769
+      return lzx->error = CL_EREAD;
770 770
     }
771 771
     else {
772 772
       bread = 2;
... ...
@@ -1099,7 +1099,7 @@ int lzx_decompress(struct lzx_stream *lzx, off_t out_bytes) {
1099 1099
   if ((off_t) i > out_bytes) i = (int) out_bytes;
1100 1100
   if (i) {
1101 1101
     if (lzx->wflag && cli_writen(lzx->ofd, lzx->o_ptr, i) != i) {
1102
-      return lzx->error = CL_EIO;
1102
+      return lzx->error = CL_EWRITE;
1103 1103
     }
1104 1104
     lzx->o_ptr  += i;
1105 1105
     lzx->offset += i;
... ...
@@ -1475,7 +1475,7 @@ int lzx_decompress(struct lzx_stream *lzx, off_t out_bytes) {
1475 1475
     /* write a frame */
1476 1476
     i = (out_bytes < (off_t)frame_size) ? (unsigned int)out_bytes : frame_size;
1477 1477
     if (lzx->wflag && cli_writen(lzx->ofd, lzx->o_ptr, i) != i) {
1478
-      return lzx->error = CL_EIO;
1478
+      return lzx->error = CL_EWRITE;
1479 1479
     }
1480 1480
     lzx->o_ptr  += i;
1481 1481
     lzx->offset += i;
... ...
@@ -1810,7 +1810,7 @@ int qtm_decompress(struct qtm_stream *qtm, off_t out_bytes) {
1810 1810
   if ((off_t) i > out_bytes) i = (int) out_bytes;
1811 1811
   if (i) {
1812 1812
     if (qtm->wflag && cli_writen(qtm->ofd, qtm->o_ptr, i) != i) {
1813
-      return qtm->error = CL_EIO;
1813
+      return qtm->error = CL_EWRITE;
1814 1814
     }
1815 1815
     qtm->o_ptr  += i;
1816 1816
     out_bytes   -= i;
... ...
@@ -1929,7 +1929,7 @@ int qtm_decompress(struct qtm_stream *qtm, off_t out_bytes) {
1929 1929
 	/* flush all currently stored data */
1930 1930
 	i = (qtm->o_end - qtm->o_ptr);
1931 1931
 	if (qtm->wflag && cli_writen(qtm->ofd, qtm->o_ptr, i) != i) {
1932
-	  return qtm->error = CL_EIO;
1932
+	  return qtm->error = CL_EWRITE;
1933 1933
 	}
1934 1934
 	out_bytes -= i;
1935 1935
 	qtm->o_ptr = &window[0];
... ...
@@ -1945,7 +1945,7 @@ int qtm_decompress(struct qtm_stream *qtm, off_t out_bytes) {
1945 1945
   if (out_bytes) {
1946 1946
     i = (int) out_bytes;
1947 1947
     if (qtm->wflag && cli_writen(qtm->ofd, qtm->o_ptr, i) != i) {
1948
-      return qtm->error = CL_EIO;
1948
+      return qtm->error = CL_EWRITE;
1949 1949
     }
1950 1950
     qtm->o_ptr += i;
1951 1951
   }
... ...
@@ -93,7 +93,7 @@ static int nsis_init(struct nsis_st *n) {
93 93
   case COMP_BZIP2:
94 94
     memset(&n->bz, 0, sizeof(nsis_bzstream));
95 95
     if (nsis_BZ2_bzDecompressInit(&n->bz, 0, 0)!=BZ_OK)
96
-      return CL_EBZIP;
96
+      return CL_EUNPACK;
97 97
     n->freecomp=1;
98 98
     break;
99 99
   case COMP_LZMA:
... ...
@@ -203,7 +203,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) {
203 203
 
204 204
   if ((n->ofd=open(n->ofn, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0600))==-1) {
205 205
     cli_errmsg("NSIS: unable to create output file %s - aborting.", n->ofn);
206
-    return CL_EIO;
206
+    return CL_ECREAT;
207 207
   }
208 208
 
209 209
   if (!n->solid) {
... ...
@@ -232,7 +232,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) {
232 232
 
233 233
     if ((ret=cli_checklimits("NSIS", ctx, size, 0, 0))!=CL_CLEAN) {
234 234
       close(n->ofd);
235
-      if (lseek(n->ifd, size, SEEK_CUR)==-1) return CL_EIO;
235
+      if (lseek(n->ifd, size, SEEK_CUR)==-1) return CL_ESEEK;
236 236
       return ret;
237 237
     }
238 238
     if (!(ibuf= (unsigned char *) cli_malloc(size))) {
... ...
@@ -244,14 +244,14 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) {
244 244
       cli_dbgmsg("NSIS: cannot read %u bytes"__AT__"\n", size);
245 245
       free(ibuf);
246 246
       close(n->ofd);
247
-      return CL_EIO;
247
+      return CL_EREAD;
248 248
     }
249 249
     if (loops==size) {
250 250
       if (cli_writen(n->ofd, ibuf, size) != (ssize_t) size) {
251 251
 	cli_dbgmsg("NSIS: cannot write output file"__AT__"\n");
252 252
 	free(ibuf);
253 253
 	close(n->ofd);
254
-	return CL_EIO;
254
+	return CL_EWRITE;
255 255
       }
256 256
     } else {
257 257
       if ((ret=nsis_init(n))!=CL_SUCCESS) {
... ...
@@ -275,7 +275,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) {
275 275
 	    free(ibuf);
276 276
 	    close(n->ofd);
277 277
 	    nsis_shutdown(n);
278
-	    return CL_EIO;
278
+	    return CL_EWRITE;
279 279
 	  }
280 280
 	  n->nsis.next_out = obuf;
281 281
 	  n->nsis.avail_out = BUFSIZ;
... ...
@@ -301,7 +301,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) {
301 301
 	  cli_dbgmsg("NSIS: cannot write output file"__AT__"\n");
302 302
 	  free(ibuf);
303 303
 	  close(n->ofd);
304
-	  return CL_EIO;
304
+	  return CL_EWRITE;
305 305
 	}
306 306
       }
307 307
 
... ...
@@ -333,7 +333,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) {
333 333
       if((n->freeme= (unsigned char *)mmap(NULL, n->fullsz, PROT_READ, MAP_PRIVATE, n->ifd, 0))==MAP_FAILED) {
334 334
 	cli_dbgmsg("NSIS: mmap() failed"__AT__"\n");
335 335
 	close(n->ofd);
336
-	return CL_EIO;
336
+	return CL_EMAP;
337 337
       }
338 338
       n->nsis.next_in = n->freeme+n->off+0x1c;
339 339
 #else /* HAVE_MMAP */
... ...
@@ -350,7 +350,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) {
350 350
       if (cli_readn(n->ifd, n->freeme, n->asz) != (ssize_t) n->asz) {
351 351
 	cli_dbgmsg("NSIS: cannot read %u bytes"__AT__"\n", n->asz);
352 352
 	close(n->ofd);
353
-	return CL_EIO;
353
+	return CL_EREAD;
354 354
       }
355 355
       n->nsis.next_in = n->freeme;
356 356
 #endif /* HAVE_MMAP */
... ...
@@ -398,7 +398,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) {
398 398
 	if (cli_writen(n->ofd, obuf, wsz) != (ssize_t) wsz) {
399 399
 	  cli_dbgmsg("NSIS: cannot write output file"__AT__"\n");
400 400
 	  close(n->ofd);
401
-	  return CL_EIO;
401
+	  return CL_EWRITE;
402 402
 	}
403 403
 	size-=wsz;
404 404
 	loops=0;
... ...
@@ -416,7 +416,7 @@ static int nsis_unpack_next(struct nsis_st *n, cli_ctx *ctx) {
416 416
       if (cli_writen(n->ofd, obuf, n->nsis.next_out - obuf) != n->nsis.next_out - obuf) {
417 417
 	cli_dbgmsg("NSIS: cannot write output file"__AT__"\n");
418 418
 	close(n->ofd);
419
-	return CL_EIO;
419
+	return CL_EWRITE;
420 420
       }
421 421
     }
422 422
 
... ...
@@ -456,7 +456,7 @@ static int nsis_headers(struct nsis_st *n, cli_ctx *ctx) {
456 456
   if (fstat(n->ifd, &st)==-1 ||
457 457
       lseek(n->ifd, n->off, SEEK_SET)==-1 ||
458 458
       cli_readn(n->ifd, buf, 28) != 28)
459
-    return CL_EIO;
459
+    return CL_EREAD;
460 460
 
461 461
   n->hsz = (uint32_t)cli_readint32(buf+0x14);
462 462
   n->asz = (uint32_t)cli_readint32(buf+0x18);
... ...
@@ -477,12 +477,12 @@ static int nsis_headers(struct nsis_st *n, cli_ctx *ctx) {
477 477
   /* Guess if solid */
478 478
   for (i=0, pos=0;pos < n->asz-4;i++) {
479 479
     int32_t nextsz;
480
-    if (cli_readn(n->ifd, buf+4, 4)!=4) return CL_EIO;
480
+    if (cli_readn(n->ifd, buf+4, 4)!=4) return CL_EREAD;
481 481
     nextsz=cli_readint32(buf+4);
482 482
     if (!i) n->comp = nsis_detcomp(buf+4);
483 483
     if (nextsz&0x80000000) {
484 484
       nextsz&=~0x80000000;
485
-      if (cli_readn(n->ifd, buf+4, 4)!=4) return CL_EIO;
485
+      if (cli_readn(n->ifd, buf+4, 4)!=4) return CL_EREAD;
486 486
       comps[nsis_detcomp(buf+4)]++;
487 487
       nextsz-=4;
488 488
       pos+=4;
... ...
@@ -492,7 +492,7 @@ static int nsis_headers(struct nsis_st *n, cli_ctx *ctx) {
492 492
       break;
493 493
     }
494 494
 
495
-    if (lseek(n->ifd, nextsz, SEEK_CUR)==-1) return CL_EIO;
495
+    if (lseek(n->ifd, nextsz, SEEK_CUR)==-1) return CL_ESEEK;
496 496
   }
497 497
   
498 498
   if (trunc && i>=2) n->solid=0;
... ...
@@ -505,7 +505,7 @@ static int nsis_headers(struct nsis_st *n, cli_ctx *ctx) {
505 505
     n->comp = (comps[1]<comps[2]) ? (comps[2]<comps[3] ? COMP_ZLIB : COMP_LZMA) : (comps[1]<comps[3] ? COMP_ZLIB : COMP_BZIP2);
506 506
   }
507 507
 
508
-  if (lseek(n->ifd, n->off+0x1c, SEEK_SET)==-1) return CL_EIO;
508
+  if (lseek(n->ifd, n->off+0x1c, SEEK_SET)==-1) return CL_ESEEK;
509 509
 
510 510
   return nsis_unpack_next(n, ctx);
511 511
 }
... ...
@@ -558,7 +558,7 @@ int cli_scannulsft(int desc, cli_ctx *ctx, off_t offset) {
558 558
 	    ret=cli_magic_scandesc(nsist.ofd, ctx);
559 559
 	  close(nsist.ofd);
560 560
 	  if(!ctx->engine->keeptmp)
561
-	    if(cli_unlink(nsist.ofn)) ret = CL_EIO;
561
+	    if(cli_unlink(nsist.ofn)) ret = CL_EUNLINK;
562 562
 	} else if(ret == CL_EMAXSIZE) {
563 563
 	    ret = nsist.solid ? CL_BREAK : CL_SUCCESS;
564 564
 	}
... ...
@@ -721,7 +721,7 @@ static int handler_otf(int fd, ole2_header_t *hdr, property_t *prop, const char
721 721
   if((ofd = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
722 722
     cli_dbgmsg("OLE2: Can't create file %s\n", tempfile);
723 723
     free(tempfile);
724
-    return CL_EIO;
724
+    return CL_ECREAT;
725 725
   }
726 726
 
727 727
   current_block = prop->start_block;
... ...
@@ -743,7 +743,7 @@ static int handler_otf(int fd, ole2_header_t *hdr, property_t *prop, const char
743 743
     close(ofd);
744 744
     if (cli_unlink(tempfile)) {
745 745
         free(tempfile);
746
-	return CL_EIO;
746
+	return CL_EUNLINK;
747 747
     }
748 748
     free(tempfile);
749 749
     return CL_BREAK;
... ...
@@ -777,7 +777,7 @@ static int handler_otf(int fd, ole2_header_t *hdr, property_t *prop, const char
777 777
 	cli_bitset_free(blk_bitset);
778 778
 	if (cli_unlink(tempfile)) {
779 779
 	  free(tempfile);
780
-	  return CL_EIO;
780
+	  return CL_EUNLINK;
781 781
         }
782 782
 	free(tempfile);
783 783
 	return CL_BREAK;
... ...
@@ -797,10 +797,10 @@ static int handler_otf(int fd, ole2_header_t *hdr, property_t *prop, const char
797 797
 	cli_bitset_free(blk_bitset);
798 798
 	if (cli_unlink(tempfile)) {
799 799
 	  free(tempfile);
800
-	  return CL_EIO;
800
+	  return CL_EUNLINK;
801 801
         }
802 802
 	free(tempfile);
803
-	return CL_EIO;
803
+	return CL_EWRITE;
804 804
       }
805 805
 
806 806
       current_block = ole2_get_next_block_number(fd, hdr, current_block);
... ...
@@ -816,7 +816,7 @@ static int handler_otf(int fd, ole2_header_t *hdr, property_t *prop, const char
816 816
   if(ctx && !ctx->engine->keeptmp) {
817 817
     if (cli_unlink(tempfile)) {
818 818
       free(tempfile);
819
-      return CL_EIO;
819
+      return CL_EUNLINK;
820 820
     }
821 821
   }
822 822
   free(tempfile);
... ...
@@ -958,13 +958,13 @@ int cli_ole2_extract(int fd, const char *dirname, cli_ctx *ctx, struct uniq **vb
958 958
 
959 959
 	hdr.bitset = cli_bitset_init();
960 960
 	if (!hdr.bitset) {
961
-		ret=CL_EOLE2;
961
+		ret=CL_EMEM;
962 962
 		goto abort;
963 963
 	}
964 964
 
965 965
 	if (memcmp(hdr.magic, magic_id, 8) != 0) {
966 966
 		cli_dbgmsg("OLE2 magic failed!\n");
967
-		ret=CL_EOLE2;
967
+		ret=CL_EFORMAT;
968 968
 		goto abort;
969 969
 	}
970 970
 
... ...
@@ -139,58 +139,49 @@ unsigned int cl_retflevel(void)
139 139
 const char *cl_strerror(int clerror)
140 140
 {
141 141
     switch(clerror) {
142
+	/* libclamav specific codes */
142 143
 	case CL_CLEAN:
143 144
 	    return "No viruses detected";
144 145
 	case CL_VIRUS:
145 146
 	    return "Virus(es) detected";
146
-	case CL_EMAXREC:
147
-	    return "Recursion limit exceeded";
148
-	case CL_EMAXSIZE:
149
-	    return "File size limit exceeded";
150
-	case CL_EMAXFILES:
151
-	    return "Files number limit exceeded";
152
-	case CL_ERAR:
153
-	    return "RAR module failure";
154
-	case CL_EZIP:
155
-	    return "Zip module failure";
156
-	case CL_EGZIP:
157
-	    return "GZip module failure";
158
-	case CL_EMSCOMP:
159
-	    return "MS Expand module failure";
160
-	case CL_EMSCAB:
161
-	    return "MS CAB module failure";
162
-	case CL_EOLE2:
163
-	    return "OLE2 module failure";
164
-	case CL_ETMPFILE:
165
-	    return "Unable to create temporary file";
166
-	case CL_ETMPDIR:
167
-	    return "Unable to create temporary directory";
168
-	case CL_EMEM:
169
-	    return "Unable to allocate memory";
170
-	case CL_EOPEN:
171
-	    return "Unable to open file or directory";
147
+	case CL_ENULLARG:
148
+	    return "Null argument passed to function";
172 149
 	case CL_EMALFDB:
173 150
 	    return "Malformed database";
174
-	case CL_EPATSHORT:
175
-	    return "Too short pattern detected";
176 151
 	case CL_ECVD:
177 152
 	    return "Broken or not a CVD file";
178
-	case CL_ECVDEXTR:
179
-	    return "CVD extraction failure";
180
-	case CL_EMD5:
181
-	    return "MD5 verification error";
182
-	case CL_EDSIG:
183
-	    return "Digital signature verification error";
184
-	case CL_ENULLARG:
185
-	    return "Null argument passed while initialized is required";
186
-	case CL_EIO:
187
-	    return "Input/Output error";
188
-	case CL_EFORMAT:
189
-	    return "Bad format or broken data";
190
-	case CL_ESUPPORT:
191
-	    return "Not supported data format";
192
-	case CL_EARJ:
193
-	    return "ARJ module failure";
153
+	case CL_EVERIFY:
154
+	    return "Can't verify database integrity";
155
+	case CL_EUNPACK:
156
+	    return "Can't unpack some data";
157
+
158
+	/* I/O and memory errors */
159
+	case CL_EOPEN:
160
+	    return "Can't open file or directory";
161
+	case CL_ECREAT:
162
+	    return "Can't create new file";
163
+	case CL_EUNLINK:
164
+	    return "Can't unlink file";
165
+	case CL_ESTAT:
166
+	    return "Can't get file status";
167
+	case CL_EREAD:
168
+	    return "Can't read file";
169
+	case CL_ESEEK:
170
+	    return "Can't set file offset";
171
+	case CL_EWRITE:
172
+	    return "Can't write to file";
173
+	case CL_EDUP:
174
+	    return "Can't duplicate file descriptor";
175
+	case CL_EACCES:
176
+	    return "Can't access file";
177
+	case CL_ETMPFILE:
178
+	    return "Can't create temporary file";
179
+	case CL_ETMPDIR:
180
+	    return "Can't create temporary directory";
181
+	case CL_EMAP:
182
+	    return "Can't map file into memory";
183
+	case CL_EMEM:
184
+	    return "Can't allocate memory";
194 185
 	default:
195 186
 	    return "Unknown error code";
196 187
     }
... ...
@@ -599,7 +590,7 @@ int cli_gentempfd(const char *dir, char **name, int *fd)
599 599
    if(*fd == -1) {
600 600
 	cli_errmsg("cli_gentempfd: Can't create temporary file %s: %s\n", *name, strerror(errno));
601 601
 	free(*name);
602
-	return CL_EIO;
602
+	return CL_ECREAT;
603 603
     }
604 604
 
605 605
     return CL_SUCCESS;
... ...
@@ -108,7 +108,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
108 108
 	p = buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, desc, offset);
109 109
 	if(buf == MAP_FAILED) {
110 110
 		cli_errmsg("cli_pdf: mmap() failed\n");
111
-		return CL_EMEM;
111
+		return CL_EMAP;
112 112
 	}
113 113
 
114 114
 	cli_dbgmsg("cli_pdf: scanning %lu bytes\n", (unsigned long)size);
... ...
@@ -417,7 +417,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
417 417
 			close(fout);
418 418
 			cli_dbgmsg("cli_pdf: Empty stream\n");
419 419
 			if (cli_unlink(fullname)) {
420
-				rc = CL_EIO;
420
+				rc = CL_EUNLINK;
421 421
 				break;
422 422
 			}
423 423
 			continue;
... ...
@@ -448,7 +448,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
448 448
 			if(ret != CL_CLEAN) {
449 449
 				close(fout);
450 450
 				if (cli_unlink(fullname)) {
451
-					rc = CL_EIO;
451
+					rc = CL_EUNLINK;
452 452
 					break;
453 453
 				}
454 454
 				continue;
... ...
@@ -459,7 +459,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
459 459
 			if(tmpbuf == NULL) {
460 460
 				close(fout);
461 461
 				if (cli_unlink(fullname)) {
462
-					rc = CL_EIO;
462
+					rc = CL_EUNLINK;
463 463
 					break;
464 464
 				}
465 465
 				continue;
... ...
@@ -471,7 +471,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
471 471
 				free(tmpbuf);
472 472
 				close(fout);
473 473
 				if (cli_unlink(fullname)) {
474
-					rc = CL_EIO;
474
+					rc = CL_EUNLINK;
475 475
 					break;
476 476
 				}
477 477
 				continue;
... ...
@@ -486,7 +486,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
486 486
 					free(tmpbuf);
487 487
 					close(fout);
488 488
 					if (cli_unlink(fullname)) {
489
-						rc = CL_EIO;
489
+						rc = CL_EUNLINK;
490 490
 						break;
491 491
 					}
492 492
 					continue;
... ...
@@ -500,7 +500,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
500 500
 				if(is_flatedecode)
501 501
 					rc = try_flatedecode((unsigned char *)tmpbuf, real_streamlen, real_streamlen, fout, ctx);
502 502
 				else
503
-				  rc = (unsigned long)cli_writen(fout, (const char *)streamstart, real_streamlen)==real_streamlen ? CL_CLEAN : CL_EIO;
503
+				  rc = (unsigned long)cli_writen(fout, (const char *)streamstart, real_streamlen)==real_streamlen ? CL_CLEAN : CL_EWRITE;
504 504
 			}
505 505
 			free(tmpbuf);
506 506
 		} else if(is_flatedecode) {
... ...
@@ -510,7 +510,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
510 510
 			cli_dbgmsg("cli_pdf: writing %lu bytes from the stream\n",
511 511
 				(unsigned long)real_streamlen);
512 512
 			if((rc = cli_checklimits("cli_pdf", ctx, real_streamlen, 0, 0))==CL_CLEAN)
513
-				rc = (unsigned long)cli_writen(fout, (const char *)streamstart, real_streamlen) == real_streamlen ? CL_CLEAN : CL_EIO;
513
+				rc = (unsigned long)cli_writen(fout, (const char *)streamstart, real_streamlen) == real_streamlen ? CL_CLEAN : CL_EWRITE;
514 514
 		}
515 515
 
516 516
 		if (rc == CL_CLEAN) {
... ...
@@ -532,7 +532,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
532 532
 					ctx->scannedfiles++;
533 533
 					close(fout);
534 534
 					if (cli_unlink(fullname)) {
535
-						rc = CL_EIO;
535
+						rc = CL_EUNLINK;
536 536
 						break;
537 537
 					}
538 538
 					continue;
... ...
@@ -545,7 +545,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
545 545
 		}
546 546
 		close(fout);
547 547
 		if(!ctx->engine->keeptmp)
548
-			if (cli_unlink(fullname)) rc = CL_EIO;
548
+			if (cli_unlink(fullname)) rc = CL_EUNLINK;
549 549
 		if(rc != CL_CLEAN) break;
550 550
 	}
551 551
 
... ...
@@ -558,7 +558,7 @@ cli_pdf(const char *dir, int desc, cli_ctx *ctx, off_t offset)
558 558
 }
559 559
 
560 560
 /*
561
- * flate inflation - returns clamAV status, e.g CL_SUCCESS, CL_EZIP
561
+ * flate inflation
562 562
  */
563 563
 static int
564 564
 try_flatedecode(unsigned char *buf, off_t real_len, off_t calculated_len, int fout, cli_ctx *ctx)
... ...
@@ -658,7 +658,7 @@ flatedecode(unsigned char *buf, off_t len, int fout, cli_ctx *ctx)
658 658
 					if ((written=cli_writen(fout, output, sizeof(output)))!=sizeof(output)) {
659 659
 						cli_errmsg("cli_pdf: failed to write output file\n");
660 660
 						inflateEnd(&stream);
661
-						return CL_EIO;
661
+						return CL_EWRITE;
662 662
 					}
663 663
 					nbytes += written;
664 664
 
... ...
@@ -690,14 +690,14 @@ flatedecode(unsigned char *buf, off_t len, int fout, cli_ctx *ctx)
690 690
 		if(cli_writen(fout, output, sizeof(output) - stream.avail_out) < 0) {
691 691
 			cli_errmsg("cli_pdf: failed to write output file\n");
692 692
 			inflateEnd(&stream);
693
-			return CL_EIO;
693
+			return CL_EWRITE;
694 694
 		}
695 695
 	}
696 696
 			
697 697
 #ifdef	SAVE_TMP
698 698
 	if (cli_unlink(tmpfilename)) {
699 699
 		inflateEnd(&stream);
700
-		return CL_EIO;
700
+		return CL_EUNLINK;
701 701
 	}
702 702
 #endif
703 703
 	inflateEnd(&stream);
... ...
@@ -100,13 +100,13 @@ if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) { \
100 100
     cli_dbgmsg(NAME": Can't create file %s\n", tempfile); \
101 101
     free(tempfile); \
102 102
     cli_multifree FREEME; \
103
-    return CL_EIO; \
103
+    return CL_ECREAT; \
104 104
 }
105 105
 
106 106
 #define CLI_TMPUNLK() if(!ctx->engine->keeptmp) { \
107 107
     if (cli_unlink(tempfile)) { \
108 108
 	free(tempfile); \
109
-	return CL_EIO; \
109
+	return CL_EUNLINK; \
110 110
     } \
111 111
 }
112 112
 
... ...
@@ -118,7 +118,7 @@ if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) { \
118 118
 	    free(exe_sections); \
119 119
 	    free(tempfile); \
120 120
 	    FREESEC; \
121
-	    return CL_EIO; \
121
+	    return CL_EUNLINK; \
122 122
 	} \
123 123
 	free(tempfile); \
124 124
 	FREESEC; \
... ...
@@ -133,7 +133,7 @@ if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) { \
133 133
 	if (cli_unlink(tempfile)) { \
134 134
 	    free(exe_sections); \
135 135
 	    free(tempfile); \
136
-	    return CL_EIO; \
136
+	    return CL_EUNLINK; \
137 137
 	} \
138 138
 	cli_dbgmsg("PESpin: Size exceeded\n"); \
139 139
 	free(tempfile); \
... ...
@@ -170,7 +170,7 @@ FSGSTUFF; \
170 170
 	    free(exe_sections); \
171 171
 	    free(tempfile); \
172 172
 	    cli_multifree FREEME; \
173
-	    return CL_EIO; \
173
+	    return CL_EUNLINK; \
174 174
 	} \
175 175
 	cli_multifree FREEME; \
176 176
         free(tempfile); \
... ...
@@ -797,7 +797,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
797 797
 
798 798
     if(fstat(desc, &sb) == -1) {
799 799
 	cli_dbgmsg("fstat failed\n");
800
-	return CL_EIO;
800
+	return CL_ESTAT;
801 801
     }
802 802
 
803 803
     fsize = sb.st_size;
... ...
@@ -1168,7 +1168,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1168 1168
 	}
1169 1169
 	if(cli_readn(desc, code, exe_sections[0].rsz)!=exe_sections[0].rsz) {
1170 1170
 	    free(exe_sections);
1171
-	    return CL_EIO;
1171
+	    return CL_EREAD;
1172 1172
 	}
1173 1173
 	for(i=0; i<exe_sections[0].rsz - 5; i++) {
1174 1174
 	    if((uint8_t)(code[i]-0xe8) > 1) continue;
... ...
@@ -1264,7 +1264,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1264 1264
 	    if(lseek(desc, fileoffset, SEEK_SET) == -1) {
1265 1265
 	        cli_dbgmsg("MEW: lseek() failed\n");
1266 1266
 		free(exe_sections);
1267
-		return CL_EIO;
1267
+		return CL_ESEEK;
1268 1268
 	    }
1269 1269
 
1270 1270
 	    if((bytes = read(desc, buff, 0xb0)) != 0xb0) {
... ...
@@ -1283,7 +1283,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1283 1283
 
1284 1284
 	    if(!cli_seeksect(desc, &exe_sections[i + 1])) {
1285 1285
 		free(exe_sections);
1286
-		return CL_EIO;
1286
+		return CL_ESEEK;
1287 1287
 	    }
1288 1288
 	    ssize = exe_sections[i + 1].vsz;
1289 1289
 	    dsize = exe_sections[i].vsz;
... ...
@@ -1309,7 +1309,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1309 1309
 	      cli_dbgmsg("MEW: Can't read %d bytes [read: %lu]\n", exe_sections[i + 1].rsz, (unsigned long)bytes);
1310 1310
 		free(exe_sections);
1311 1311
 		free(src);
1312
-		return CL_EIO;
1312
+		return CL_EREAD;
1313 1313
 	    }
1314 1314
 	    cli_dbgmsg("MEW: %u (%08x) bytes read\n", (unsigned int)bytes, (unsigned int)bytes);
1315 1315
 
... ...
@@ -1473,7 +1473,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1473 1473
 	    cli_dbgmsg("Can't read raw data of section %d\n", i + 1);
1474 1474
 	    free(exe_sections);
1475 1475
 	    free(src);
1476
-	    return CL_EIO;
1476
+	    return CL_ESEEK;
1477 1477
 	}
1478 1478
 
1479 1479
 	dest = src + newedx - exe_sections[i + 1].rva;
... ...
@@ -1574,7 +1574,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1574 1574
 	    cli_dbgmsg("Can't read %d bytes from padding area\n", gp); 
1575 1575
 	    free(exe_sections);
1576 1576
 	    free(support);
1577
-	    return CL_EIO;
1577
+	    return CL_EREAD;
1578 1578
 	}
1579 1579
 
1580 1580
 	/* newebx = cli_readint32(support) - EC32(optional_hdr32.ImageBase);  Unused */
... ...
@@ -1639,7 +1639,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1639 1639
 	    free(exe_sections);
1640 1640
 	    free(sections);
1641 1641
 	    free(src);
1642
-	    return CL_EIO;
1642
+	    return CL_EREAD;
1643 1643
 	}
1644 1644
 
1645 1645
 	if((dest = (char *) cli_calloc(dsize, sizeof(char))) == NULL) {
... ...
@@ -1712,7 +1712,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1712 1712
 	    cli_dbgmsg("Can't read %d bytes from padding area\n", gp); 
1713 1713
 	    free(exe_sections);
1714 1714
 	    free(support);
1715
-	    return CL_EIO;
1715
+	    return CL_EREAD;
1716 1716
 	}
1717 1717
 
1718 1718
 	/* Counting original sections */
... ...
@@ -1760,7 +1760,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1760 1760
 	    free(exe_sections);
1761 1761
 	    free(sections);
1762 1762
 	    free(src);
1763
-	    return CL_EIO;
1763
+	    return CL_EREAD;
1764 1764
 	}
1765 1765
 
1766 1766
 	if((dest = (char *) cli_calloc(dsize, sizeof(char))) == NULL) {
... ...
@@ -1812,7 +1812,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1812 1812
 	    free(exe_sections);
1813 1813
 	    free(src);
1814 1814
 	    free(dest);
1815
-	    return CL_EIO;
1815
+	    return CL_EREAD;
1816 1816
 	}
1817 1817
 
1818 1818
 	/* try to detect UPX code */
... ...
@@ -1904,7 +1904,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1904 1904
 	    free(tempfile);
1905 1905
 	    free(dest);
1906 1906
 	    close(ndesc);
1907
-	    return CL_EIO;
1907
+	    return CL_EWRITE;
1908 1908
 	}
1909 1909
 
1910 1910
 	free(dest);
... ...
@@ -1996,7 +1996,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1996 1996
 	    cli_dbgmsg("PESpin: Can't read %lu bytes\n", (unsigned long)fsize);
1997 1997
 	    free(spinned);
1998 1998
 	    free(exe_sections);
1999
-	    return CL_EIO;
1999
+	    return CL_EREAD;
2000 2000
 	}
2001 2001
 
2002 2002
 	CLI_UNPTEMP("PESpin",(spinned,exe_sections,0));
... ...
@@ -2022,7 +2022,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
2022 2022
 	    cli_dbgmsg("yC: Can't read %lu bytes\n", (unsigned long)fsize);
2023 2023
 	    free(spinned);
2024 2024
 	    free(exe_sections);
2025
-	    return CL_EIO;
2025
+	    return CL_EREAD;
2026 2026
 	}
2027 2027
 
2028 2028
 	CLI_UNPTEMP("yC",(spinned,exe_sections,0));
... ...
@@ -2059,7 +2059,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
2059 2059
 	    cli_dbgmsg("WWPack: Can't read %d bytes from headers\n", head);
2060 2060
 	    free(src);
2061 2061
 	    free(exe_sections);
2062
-	    return CL_EIO;
2062
+	    return CL_EREAD;
2063 2063
 	}
2064 2064
         for(i = 0 ; i < (unsigned int)nsections-1; i++) {
2065 2065
 	    if(!exe_sections[i].rsz) continue;
... ...
@@ -2082,7 +2082,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
2082 2082
 	    free(src);
2083 2083
 	    free(packer);
2084 2084
 	    free(exe_sections);
2085
-	    return CL_EIO;
2085
+	    return CL_EREAD;
2086 2086
 	}
2087 2087
 
2088 2088
 	CLI_UNPTEMP("WWPack",(src,packer,exe_sections,0));
... ...
@@ -1555,7 +1555,7 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
1555 1555
 	} result;
1556 1556
 #endif
1557 1557
 	char *dbfile;
1558
-	int ret = CL_ESUPPORT;
1558
+	int ret = CL_EOPEN;
1559 1559
 
1560 1560
 
1561 1561
     cli_dbgmsg("Loading databases from %s\n", dirname);
... ...
@@ -1632,7 +1632,7 @@ static int cli_loaddbdir(const char *dirname, struct cl_engine *engine, unsigned
1632 1632
     }
1633 1633
 
1634 1634
     closedir(dd);
1635
-    if(ret == CL_ESUPPORT)
1635
+    if(ret == CL_EOPEN)
1636 1636
 	cli_errmsg("cli_loaddb(): No supported database files found in %s\n", dirname);
1637 1637
 
1638 1638
     return ret;
... ...
@@ -1650,7 +1650,7 @@ int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, uns
1650 1650
 
1651 1651
     if(stat(path, &sb) == -1) {
1652 1652
         cli_errmsg("cl_load(): Can't get status of %s\n", path);
1653
-        return CL_EIO;
1653
+        return CL_ESTAT;
1654 1654
     }
1655 1655
 
1656 1656
     if((options & CL_DB_PHISHING_URLS) && !engine->phishcheck && (engine->dconf->phishing & PHISHING_CONF_ENGINE))
... ...
@@ -456,7 +456,7 @@ int load_regex_matcher(struct regex_matcher* matcher,FILE* fd,unsigned int optio
456 456
 		return CL_EMALFDB; /* already failed to load */
457 457
 	if(!fd && !dbio) {
458 458
 		cli_errmsg("Unable to load regex list (null file)\n");
459
-		return CL_EIO;
459
+		return CL_ENULLARG;
460 460
 	}
461 461
 
462 462
 	cli_dbgmsg("Loading regex_list\n");
... ...
@@ -247,7 +247,7 @@ static int decode_and_scan(struct rtf_object_data* data, cli_ctx* ctx)
247 247
 	data->fd = -1;
248 248
 	if(data->name) {
249 249
 		if(!ctx->engine->keeptmp)
250
-			if(cli_unlink(data->name)) ret = CL_EIO;
250
+			if(cli_unlink(data->name)) ret = CL_EUNLINK;
251 251
 		free(data->name);
252 252
 		data->name = NULL;
253 253
 	}
... ...
@@ -409,7 +409,7 @@ static int rtf_object_process(struct rtf_state* state, const unsigned char* inpu
409 409
 							    data->bread = 1;/* flag to indicate this needs to be scanned with cli_decode_ole_object*/
410 410
 							    cli_writeint32(out,data->desc_len);
411 411
 							    if(cli_writen(data->fd,out,4)!=4)
412
-								    return CL_EIO; 
412
+								    return CL_EWRITE; 
413 413
 							}
414 414
 							else
415 415
 								data->bread = 2;
... ...
@@ -417,7 +417,7 @@ static int rtf_object_process(struct rtf_state* state, const unsigned char* inpu
417 417
 
418 418
 						data->desc_len -= out_want;
419 419
 						if(cli_writen(data->fd,out_data,out_want) != out_want) {
420
-							return CL_EIO;
420
+							return CL_EWRITE;
421 421
 						}
422 422
 						out_data += out_want;
423 423
 						out_cnt  -= out_want;
... ...
@@ -271,7 +271,7 @@ static int cli_scanrar(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
271 271
 
272 272
     if(sfx_offset)
273 273
 	if(lseek(desc, sfx_offset, SEEK_SET) == -1)
274
-	    return CL_EIO;
274
+	    return CL_ESEEK;
275 275
 
276 276
     /* generate the temporary directory */
277 277
     if(!(dir = cli_gentemp(ctx->engine->tmpdir)))
... ...
@@ -300,7 +300,7 @@ static int cli_scanrar(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
300 300
 	} if(ret == UNRAR_EMEM) {
301 301
 	    return CL_EMEM;
302 302
 	} else {
303
-	    return CL_ERAR;
303
+	    return CL_EUNPACK;
304 304
 	}
305 305
     }
306 306
 
... ...
@@ -314,7 +314,7 @@ static int cli_scanrar(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
314 314
 	    else if(ret == UNRAR_EMEM)
315 315
 		ret = CL_EMEM;
316 316
 	    else
317
-		ret = CL_ERAR;
317
+		ret = CL_EUNPACK;
318 318
 	    break;
319 319
 	}
320 320
 	if((ret=cli_checklimits("RAR", ctx, rar_state.metadata_tail->unpack_size, rar_state.metadata_tail->pack_size, 0)!=CL_CLEAN)) {
... ...
@@ -329,14 +329,14 @@ static int cli_scanrar(int desc, cli_ctx *ctx, off_t sfx_offset, uint32_t *sfx_c
329 329
 	else if(ret == UNRAR_EMEM)
330 330
 	    ret = CL_EMEM;
331 331
 	else
332
-	    ret = CL_ERAR;
332
+	    ret = CL_EFORMAT;
333 333
 
334 334
 	if(rar_state.ofd > 0) {
335 335
 	    lseek(rar_state.ofd,0,SEEK_SET);
336 336
 	    rc = cli_magic_scandesc(rar_state.ofd,ctx);
337 337
 	    close(rar_state.ofd);
338 338
 	    if(!ctx->engine->keeptmp) 
339
-		if (cli_unlink(rar_state.filename)) ret = CL_EIO;
339
+		if (cli_unlink(rar_state.filename)) ret = CL_EUNLINK;
340 340
 	    if(rc == CL_VIRUS ) {
341 341
 		cli_dbgmsg("RAR: infected with %s\n",*ctx->virname);
342 342
 		ret = CL_VIRUS;
... ...
@@ -463,7 +463,7 @@ static int cli_scangzip(int desc, cli_ctx *ctx)
463 463
 
464 464
     if((gd = gzdopen(dup(desc), "rb")) == NULL) {
465 465
 	cli_dbgmsg("GZip: Can't open descriptor %d\n", desc);
466
-	return CL_EGZIP;
466
+	return CL_EOPEN;
467 467
     }
468 468
 
469 469
     if((ret = cli_gentempfd(ctx->engine->tmpdir, &tmpname, &fd))) {
... ...
@@ -479,7 +479,7 @@ static int cli_scangzip(int desc, cli_ctx *ctx)
479 479
 	if(!ctx->engine->keeptmp) {
480 480
 	    if(cli_unlink(tmpname)) {
481 481
 	    	free(tmpname);
482
-		return CL_EIO;
482
+		return CL_EUNLINK;
483 483
 	    }
484 484
 	}
485 485
 	return CL_EMEM;
... ...
@@ -499,13 +499,13 @@ static int cli_scangzip(int desc, cli_ctx *ctx)
499 499
 		    free(tmpname);
500 500
 		    gzclose(gd);
501 501
 		    free(buff);
502
-		    return CL_EIO;
502
+		    return CL_EUNLINK;
503 503
 		}
504 504
 	    }
505 505
 	    free(tmpname);	
506 506
 	    gzclose(gd);
507 507
 	    free(buff);
508
-	    return CL_EGZIP;
508
+	    return CL_EWRITE;
509 509
 	}
510 510
     }
511 511
 
... ...
@@ -515,7 +515,7 @@ static int cli_scangzip(int desc, cli_ctx *ctx)
515 515
     if(ret == CL_VIRUS) {
516 516
 	close(fd);
517 517
 	if(!ctx->engine->keeptmp)
518
-	    if (cli_unlink(tmpname)) ret = CL_EIO;
518
+	    if (cli_unlink(tmpname)) ret = CL_EUNLINK;
519 519
 	free(tmpname);	
520 520
 	return ret;
521 521
     }
... ...
@@ -527,7 +527,7 @@ static int cli_scangzip(int desc, cli_ctx *ctx)
527 527
 	if(!ctx->engine->keeptmp) {
528 528
 	    if (cli_unlink(tmpname)) {
529 529
 	    	free(tmpname);
530
-		return CL_EIO;
530
+		return CL_EUNLINK;
531 531
 	    }
532 532
 	}
533 533
 	free(tmpname);	
... ...
@@ -535,7 +535,7 @@ static int cli_scangzip(int desc, cli_ctx *ctx)
535 535
     }
536 536
     close(fd);
537 537
     if(!ctx->engine->keeptmp)
538
-	if (cli_unlink(tmpname)) ret = CL_EIO;
538
+	if (cli_unlink(tmpname)) ret = CL_EUNLINK;
539 539
     free(tmpname);	
540 540
 
541 541
     return ret;
... ...
@@ -568,13 +568,13 @@ static int cli_scanbzip(int desc, cli_ctx *ctx)
568 568
 
569 569
     if((fs = fdopen(dup(desc), "rb")) == NULL) {
570 570
 	cli_dbgmsg("Bzip: Can't open descriptor %d.\n", desc);
571
-	return CL_EBZIP;
571
+	return CL_EOPEN;
572 572
     }
573 573
 
574 574
     if((bfd = BZ2_bzReadOpen(&bzerror, fs, 0, 0, NULL, 0)) == NULL) {
575 575
 	cli_dbgmsg("Bzip: Can't initialize bzip2 library (descriptor: %d).\n", desc);
576 576
 	fclose(fs);
577
-	return CL_EBZIP;
577
+	return CL_EOPEN;
578 578
     }
579 579
 
580 580
     if((ret = cli_gentempfd(ctx->engine->tmpdir, &tmpname, &fd))) {
... ...
@@ -592,7 +592,7 @@ static int cli_scanbzip(int desc, cli_ctx *ctx)
592 592
 	    	free(tmpname);
593 593
 		fclose(fs);
594 594
 		BZ2_bzReadClose(&bzerror, bfd);
595
-		return CL_EIO;
595
+		return CL_EUNLINK;
596 596
 	    }
597 597
 	}
598 598
 	free(tmpname);	
... ...
@@ -616,13 +616,13 @@ static int cli_scanbzip(int desc, cli_ctx *ctx)
616 616
 		    free(tmpname);
617 617
 		    free(buff);
618 618
 		    fclose(fs);
619
-		    return CL_EIO;
619
+		    return CL_EUNLINK;
620 620
 		}
621 621
 	    }
622 622
 	    free(tmpname);	
623 623
 	    free(buff);
624 624
 	    fclose(fs);
625
-	    return CL_EGZIP;
625
+	    return CL_EWRITE;
626 626
 	}
627 627
     }
628 628
 
... ...
@@ -632,7 +632,7 @@ static int cli_scanbzip(int desc, cli_ctx *ctx)
632 632
     if(ret == CL_VIRUS) {
633 633
 	close(fd);
634 634
 	if(!ctx->engine->keeptmp)
635
-	    if (cli_unlink(tmpname)) ret = CL_EIO;
635
+	    if (cli_unlink(tmpname)) ret = CL_EUNLINK;
636 636
 	free(tmpname);	
637 637
 	fclose(fs);
638 638
 	return ret;
... ...
@@ -644,7 +644,7 @@ static int cli_scanbzip(int desc, cli_ctx *ctx)
644 644
     }
645 645
     close(fd);
646 646
     if(!ctx->engine->keeptmp)
647
-	if (cli_unlink(tmpname)) ret = CL_EIO;
647
+	if (cli_unlink(tmpname)) ret = CL_EUNLINK;
648 648
     free(tmpname);	
649 649
     fclose(fs);
650 650
 
... ...
@@ -671,7 +671,7 @@ static int cli_scanszdd(int desc, cli_ctx *ctx)
671 671
     if(ret != CL_SUCCESS) { /* CL_VIRUS or some error */
672 672
 	close(ofd);
673 673
 	if(!ctx->engine->keeptmp)
674
-	    if (cli_unlink(tmpname)) ret = CL_EIO;
674
+	    if (cli_unlink(tmpname)) ret = CL_EUNLINK;
675 675
 	free(tmpname);	
676 676
 	return ret;
677 677
     }
... ...
@@ -681,7 +681,7 @@ static int cli_scanszdd(int desc, cli_ctx *ctx)
681 681
     ret = cli_magic_scandesc(ofd, ctx);
682 682
     close(ofd);
683 683
     if(!ctx->engine->keeptmp)
684
-	if (cli_unlink(tmpname)) ret = CL_EIO;
684
+	if (cli_unlink(tmpname)) ret = CL_EUNLINK;
685 685
     free(tmpname);	
686 686
 
687 687
     return ret;
... ...
@@ -720,7 +720,7 @@ static int cli_scanmscab(int desc, cli_ctx *ctx, off_t sfx_offset)
720 720
 	if(!ctx->engine->keeptmp) {
721 721
 	    if (cli_unlink(tempname)) {
722 722
 	    	free(tempname);
723
-		ret = CL_EIO;
723
+		ret = CL_EUNLINK;
724 724
 		break;
725 725
 	    }
726 726
 	}
... ...
@@ -928,7 +928,7 @@ static int cli_scanhtml(int desc, cli_ctx *ctx)
928 928
 
929 929
     if(fstat(desc, &sb) == -1) {
930 930
         cli_errmsg("cli_scanhtml: fstat() failed for descriptor %d\n", desc);
931
-	return CL_EIO;
931
+	return CL_ESTAT;
932 932
     }
933 933
 
934 934
     /* Because HTML detection is FP-prone and html_normalise_fd() needs to
... ...
@@ -1011,7 +1011,7 @@ static int cli_scanscript(int desc, cli_ctx *ctx)
1011 1011
 
1012 1012
 	if(fstat(desc, &sb) == -1) {
1013 1013
 		cli_errmsg("cli_scanscript: fstat() failed for descriptor %d\n", desc);
1014
-		return CL_EIO;
1014
+		return CL_ESTAT;
1015 1015
 	}
1016 1016
 
1017 1017
 	/* don't normalize files that are too large */
... ...
@@ -1088,7 +1088,7 @@ static int cli_scanhtml_utf16(int desc, cli_ctx *ctx)
1088 1088
     if((fd = open(tempname, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
1089 1089
 	cli_errmsg("cli_scanhtml_utf16: Can't create file %s\n", tempname);
1090 1090
 	free(tempname);
1091
-	return CL_EIO;
1091
+	return CL_EOPEN;
1092 1092
     }
1093 1093
 
1094 1094
     cli_dbgmsg("cli_scanhtml_utf16: using tempfile %s\n", tempname);
... ...
@@ -1102,7 +1102,7 @@ static int cli_scanhtml_utf16(int desc, cli_ctx *ctx)
1102 1102
 		cli_unlink(tempname);
1103 1103
 		free(tempname);
1104 1104
 		close(fd);
1105
-		return CL_EIO;
1105
+		return CL_EWRITE;
1106 1106
 	    }
1107 1107
 	    free(decoded);
1108 1108
 	}
... ...
@@ -1113,7 +1113,7 @@ static int cli_scanhtml_utf16(int desc, cli_ctx *ctx)
1113 1113
     close(fd);
1114 1114
 
1115 1115
     if(!ctx->engine->keeptmp) {
1116
-	if (cli_unlink(tempname)) ret = CL_EIO;
1116
+	if (cli_unlink(tempname)) ret = CL_EUNLINK;
1117 1117
     } else
1118 1118
 	cli_dbgmsg("cli_scanhtml_utf16: Decoded HTML data saved in %s\n", tempname);
1119 1119
     free(tempname);
... ...
@@ -1346,7 +1346,7 @@ static int cli_scancryptff(int desc, cli_ctx *ctx)
1346 1346
 
1347 1347
     if(fstat(desc, &sb) == -1) {
1348 1348
 	cli_errmsg("CryptFF: Can't fstat descriptor %d\n", desc);
1349
-	return CL_EIO;
1349
+	return CL_ESTAT;
1350 1350
     }
1351 1351
 
1352 1352
     /* Skip the CryptFF file header */
... ...
@@ -1372,7 +1372,7 @@ static int cli_scancryptff(int desc, cli_ctx *ctx)
1372 1372
 	cli_dbgmsg("CryptFF: Can't read from descriptor %d\n", desc);
1373 1373
 	free(dest);
1374 1374
 	free(src);
1375
-	return CL_EIO;
1375
+	return CL_EREAD;
1376 1376
     }
1377 1377
 
1378 1378
     for(i = 0; i < length; i++)
... ...
@@ -1389,7 +1389,7 @@ static int cli_scancryptff(int desc, cli_ctx *ctx)
1389 1389
 	cli_errmsg("CryptFF: Can't create file %s\n", tempfile);
1390 1390
 	free(dest);
1391 1391
 	free(tempfile);
1392
-	return CL_EIO;
1392
+	return CL_ECREAT;
1393 1393
     }
1394 1394
 
1395 1395
     if(write(ndesc, dest, length) == -1) {
... ...
@@ -1397,7 +1397,7 @@ static int cli_scancryptff(int desc, cli_ctx *ctx)
1397 1397
 	free(dest);
1398 1398
 	close(ndesc);
1399 1399
 	free(tempfile);
1400
-	return CL_EIO;
1400
+	return CL_EWRITE;
1401 1401
     }
1402 1402
 
1403 1403
     free(dest);
... ...
@@ -1414,7 +1414,7 @@ static int cli_scancryptff(int desc, cli_ctx *ctx)
1414 1414
     if(ctx->engine->keeptmp)
1415 1415
 	cli_dbgmsg("CryptFF: Decompressed data saved in %s\n", tempfile);
1416 1416
     else
1417
-	if (cli_unlink(tempfile)) ret = CL_EIO;
1417
+	if (cli_unlink(tempfile)) ret = CL_EUNLINK;
1418 1418
 
1419 1419
     free(tempfile);
1420 1420
     return ret;
... ...
@@ -1616,7 +1616,7 @@ static int cli_scanembpe(int desc, cli_ctx *ctx)
1616 1616
     if((fd = open(tmpname, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
1617 1617
 	cli_errmsg("cli_scanembpe: Can't create file %s\n", tmpname);
1618 1618
 	free(tmpname);
1619
-	return CL_EIO;
1619
+	return CL_ECREAT;
1620 1620
     }
1621 1621
 
1622 1622
     while((bytes = read(desc, buff, sizeof(buff))) > 0) {
... ...
@@ -1631,11 +1631,11 @@ static int cli_scanembpe(int desc, cli_ctx *ctx)
1631 1631
 	    if(!ctx->engine->keeptmp) {
1632 1632
 		if (cli_unlink(tmpname)) {
1633 1633
 		    free(tmpname);
1634
-		    return CL_EIO;
1634
+		    return CL_EUNLINK;
1635 1635
 		}
1636 1636
 	    }
1637 1637
 	    free(tmpname);	
1638
-	    return CL_EIO;
1638
+	    return CL_EWRITE;
1639 1639
 	}
1640 1640
     }
1641 1641
 
... ...
@@ -1647,7 +1647,7 @@ static int cli_scanembpe(int desc, cli_ctx *ctx)
1647 1647
 	if(!ctx->engine->keeptmp) {
1648 1648
 	    if (cli_unlink(tmpname)) {
1649 1649
 	    	free(tmpname);
1650
-		return CL_EIO;
1650
+		return CL_EUNLINK;
1651 1651
 	    }
1652 1652
 	}
1653 1653
 	free(tmpname);	
... ...
@@ -1659,7 +1659,7 @@ static int cli_scanembpe(int desc, cli_ctx *ctx)
1659 1659
     if(!ctx->engine->keeptmp) {
1660 1660
 	if (cli_unlink(tmpname)) {
1661 1661
 	    free(tmpname);
1662
-	    return CL_EIO;
1662
+	    return CL_EUNLINK;
1663 1663
 	}
1664 1664
     }
1665 1665
     free(tmpname);
... ...
@@ -1689,7 +1689,7 @@ static int cli_scanraw(int desc, cli_ctx *ctx, cli_file_t type, uint8_t typercg,
1689 1689
 
1690 1690
     if(lseek(desc, 0, SEEK_SET) < 0) {
1691 1691
 	cli_errmsg("cli_scanraw: lseek() failed\n");
1692
-	return CL_EIO;
1692
+	return CL_ESEEK;
1693 1693
     }
1694 1694
 
1695 1695
     ret = cli_scandesc(desc, ctx, type == CL_TYPE_TEXT_ASCII ? 0 : type, 0, &ftoffset, acmode);
... ...
@@ -1836,7 +1836,7 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
1836 1836
 
1837 1837
     if(fstat(desc, &sb) == -1) {
1838 1838
 	cli_errmsg("magic_scandesc: Can't fstat descriptor %d\n", desc);
1839
-	return CL_EIO;
1839
+	return CL_ESTAT;
1840 1840
     }
1841 1841
 
1842 1842
     if(sb.st_size <= 5) {
... ...
@@ -1868,7 +1868,7 @@ int cli_magic_scandesc(int desc, cli_ctx *ctx)
1868 1868
     type = cli_filetype2(desc, ctx->engine);
1869 1869
     if(type == CL_TYPE_ERROR) {
1870 1870
 	cli_dbgmsg("cli_magic_scandesc: cli_filetype2 returned CL_TYPE_ERROR\n");
1871
-	return CL_EIO;
1871
+	return CL_EREAD;
1872 1872
     }
1873 1873
     lseek(desc, 0, SEEK_SET);
1874 1874
 
... ...
@@ -81,14 +81,14 @@ int cli_scansis(int desc, cli_ctx *ctx) {
81 81
     cli_dbgmsg("SIS: dup() failed\n");
82 82
     cli_rmdirs(tmpd);
83 83
     free(tmpd);
84
-    return CL_EIO;
84
+    return CL_EDUP;
85 85
   }
86 86
   if (!(f=fdopen(i, "rb"))) {
87 87
     cli_dbgmsg("SIS: fdopen() failed\n");
88 88
     close(i);
89 89
     cli_rmdirs(tmpd);
90 90
     free(tmpd);
91
-    return CL_EIO;
91
+    return CL_EOPEN;
92 92
   }
93 93
   rewind(f);
94 94
   if (fread(uid, 16, 1, f)!=1) {
... ...
@@ -96,7 +96,7 @@ int cli_scansis(int desc, cli_ctx *ctx) {
96 96
     cli_rmdirs(tmpd);
97 97
     free(tmpd);
98 98
     fclose(f);
99
-    return CL_EIO;
99
+    return CL_EREAD;
100 100
   }
101 101
 
102 102
   cli_dbgmsg("SIS: UIDS %x %x %x - %x\n", EC32(uid[0]), EC32(uid[1]), EC32(uid[2]), EC32(uid[3]));
... ...
@@ -504,7 +504,7 @@ static int real_scansis(FILE *f, cli_ctx *ctx, const char *tmpd) {
504 504
 	    free(decomp);
505 505
 	    free(ptrs);
506 506
 	    free(alangs);
507
-	    return CL_EIO;
507
+	    return CL_ECREAT;
508 508
 	  }
509 509
 	  if (cli_writen(fd, decomp, olen)!=(int)olen) {
510 510
 	    close(fd);
... ...
@@ -512,7 +512,7 @@ static int real_scansis(FILE *f, cli_ctx *ctx, const char *tmpd) {
512 512
 	    free(ptrs);
513 513
 	    free(alangs);
514 514
 	    close(fd);
515
-	    return CL_EIO;
515
+	    return CL_EWRITE;
516 516
 	  }
517 517
 	  free(decomp);
518 518
 	  if (cli_magic_scandesc(fd, ctx) == CL_VIRUS) {
... ...
@@ -75,7 +75,7 @@ cli_tnef(const char *dir, int desc, cli_ctx *ctx)
75 75
 
76 76
 	if(fstat(desc, &statb) < 0) {
77 77
 		cli_errmsg("Can't fstat descriptor %d\n", desc);
78
-		return CL_EIO;
78
+		return CL_ESTAT;
79 79
 	}
80 80
 	fsize = statb.st_size;
81 81
 
... ...
@@ -94,7 +94,7 @@ cli_tnef(const char *dir, int desc, cli_ctx *ctx)
94 94
 	if(fread(&i32, sizeof(uint32_t), 1, fp) != 1) {
95 95
 		fclose(fp);
96 96
 		/* The file is at least MIN_SIZE bytes, so it "can't" fail */
97
-		return CL_EIO;
97
+		return CL_EREAD;
98 98
 	}
99 99
 	if(host32(i32) != TNEF_SIGNATURE) {
100 100
 		fclose(fp);
... ...
@@ -104,7 +104,7 @@ cli_tnef(const char *dir, int desc, cli_ctx *ctx)
104 104
 	if(fread(&i16, sizeof(uint16_t), 1, fp) != 1) {
105 105
 		fclose(fp);
106 106
 		/* The file is at least MIN_SIZE bytes, so it "can't" fail */
107
-		return CL_EIO;
107
+		return CL_EREAD;
108 108
 	}
109 109
 
110 110
 	fb = NULL;
... ...
@@ -120,7 +120,7 @@ cli_tnef(const char *dir, int desc, cli_ctx *ctx)
120 120
 			case 0:
121 121
 				if(ferror(fp)) {
122 122
 					perror("read");
123
-					ret = CL_EIO;
123
+					ret = CL_EREAD;
124 124
 				}
125 125
 				alldone = 1;
126 126
 				break;
... ...
@@ -130,7 +130,6 @@ cli_tnef(const char *dir, int desc, cli_ctx *ctx)
130 130
 				/*
131 131
 				 * Assume truncation, not file I/O error
132 132
 				 */
133
-				/*ret = CL_EIO;*/
134 133
 				cli_warnmsg("cli_tnef: file truncated, returning CLEAN\n");
135 134
 				ret = CL_CLEAN;
136 135
 				alldone = 1;
... ...
@@ -173,8 +173,8 @@ static int fill_buf(arj_decode_t *decode_data, int n)
173 173
 		if (decode_data->comp_size != 0) {
174 174
 			decode_data->comp_size--;
175 175
 			if (cli_readn(decode_data->fd, &decode_data->sub_bit_buf, 1) != 1) {
176
-				decode_data->status = CL_EIO;
177
-				return CL_EIO;
176
+				decode_data->status = CL_EREAD;
177
+				return CL_EREAD;
178 178
 			}
179 179
 		} else {
180 180
 			decode_data->sub_bit_buf = 0;
... ...
@@ -214,7 +214,7 @@ static int write_text(int ofd, unsigned char *data, int length)
214 214
 	
215 215
 	count = cli_writen(ofd, data, length);
216 216
 	if (count != length) {
217
-		return CL_EIO;
217
+		return CL_EWRITE;
218 218
 	} else {
219 219
 		return CL_SUCCESS;
220 220
 	}
... ...
@@ -232,8 +232,8 @@ static int make_table(arj_decode_t *decode_data, int nchar, unsigned char *bitle
232 232
 	for (i = 0; (int)i < nchar; i++) {
233 233
 		if (bitlen[i] >= 17) {
234 234
 			cli_dbgmsg("UNARJ: bounds exceeded\n");
235
-			decode_data->status = CL_EARJ;
236
-			return CL_EARJ;
235
+			decode_data->status = CL_EUNPACK;
236
+			return CL_EUNPACK;
237 237
 		}
238 238
 		count[bitlen[i]]++;
239 239
 	}
... ...
@@ -243,15 +243,15 @@ static int make_table(arj_decode_t *decode_data, int nchar, unsigned char *bitle
243 243
 		start[i+1] = start[i] + (count[i] << (16 - i));
244 244
 	}
245 245
 	if (start[17] != (unsigned short) (1 << 16)) {
246
-		decode_data->status = CL_EARJ;
247
-		return CL_EARJ;
246
+		decode_data->status = CL_EUNPACK;
247
+		return CL_EUNPACK;
248 248
 	}
249 249
 	
250 250
 	jutbits = 16 - tablebits;
251 251
 	if (tablebits >= 17) {
252 252
 		cli_dbgmsg("UNARJ: bounds exceeded\n");
253
-		decode_data->status = CL_EARJ;
254
-		return CL_EARJ;
253
+		decode_data->status = CL_EUNPACK;
254
+		return CL_EUNPACK;
255 255
 	}
256 256
 	for (i = 1; (int)i <= tablebits; i++) {
257 257
 		start[i] >>= jutbits;
... ...
@@ -268,8 +268,8 @@ static int make_table(arj_decode_t *decode_data, int nchar, unsigned char *bitle
268 268
 		while (i != k) {
269 269
 			if (i >= tablesize) {
270 270
 				cli_dbgmsg("UNARJ: bounds exceeded\n");
271
-				decode_data->status = CL_EARJ;
272
-				return CL_EARJ;
271
+				decode_data->status = CL_EUNPACK;
272
+				return CL_EUNPACK;
273 273
 			}
274 274
 			table[i++] = 0;
275 275
 		}
... ...
@@ -283,15 +283,15 @@ static int make_table(arj_decode_t *decode_data, int nchar, unsigned char *bitle
283 283
 		}
284 284
 		if (len >= 17) {
285 285
 			cli_dbgmsg("UNARJ: bounds exceeded\n");
286
-			decode_data->status = CL_EARJ;
287
-			return CL_EARJ;
286
+			decode_data->status = CL_EUNPACK;
287
+			return CL_EUNPACK;
288 288
 		}
289 289
 		k = start[len];
290 290
 		nextcode = k + weight[len];
291 291
 		if ((int)len <= tablebits) {
292 292
 			if (nextcode > (unsigned int) tablesize) {
293
-				decode_data->status = CL_EARJ;
294
-				return CL_EARJ;
293
+				decode_data->status = CL_EUNPACK;
294
+				return CL_EUNPACK;
295 295
 			}
296 296
 			for (i = start[len]; i < nextcode; i++) {
297 297
 				table[i] = ch;
... ...
@@ -303,16 +303,16 @@ static int make_table(arj_decode_t *decode_data, int nchar, unsigned char *bitle
303 303
 				if (*p == 0) {
304 304
 					if (avail >= (2 * NC - 1)) {
305 305
 						cli_dbgmsg("UNARJ: bounds exceeded\n");
306
-						decode_data->status = CL_EARJ;
307
-						return CL_EARJ;
306
+						decode_data->status = CL_EUNPACK;
307
+						return CL_EUNPACK;
308 308
 					}
309 309
 					decode_data->right[avail] = decode_data->left[avail] = 0;
310 310
 					*p = avail++;
311 311
 				}
312 312
 				if (*p >= (2 * NC - 1)) {
313 313
 					cli_dbgmsg("UNARJ: bounds exceeded\n");
314
-					decode_data->status = CL_EARJ;
315
-					return CL_EARJ;
314
+					decode_data->status = CL_EUNPACK;
315
+					return CL_EUNPACK;
316 316
 				}
317 317
 				if (k & mask) {
318 318
 					p = &decode_data->right[*p];
... ...
@@ -339,8 +339,8 @@ static int read_pt_len(arj_decode_t *decode_data, int nn, int nbit, int i_specia
339 339
 	if (n == 0) {
340 340
 		if (nn > NPT) {
341 341
 			cli_dbgmsg("UNARJ: bounds exceeded\n");
342
-			decode_data->status = CL_EARJ;
343
-			return CL_EARJ;
342
+			decode_data->status = CL_EUNPACK;
343
+			return CL_EUNPACK;
344 344
 		}
345 345
 		c = arj_getbits(decode_data, nbit);
346 346
 		for (i = 0; i < nn; i++) {
... ...
@@ -379,7 +379,7 @@ static int read_pt_len(arj_decode_t *decode_data, int nn, int nbit, int i_specia
379 379
 			decode_data->pt_len[i++] = 0;
380 380
 		}
381 381
 		if (make_table(decode_data, nn, decode_data->pt_len, 8, decode_data->pt_table, PTABLESIZE) != CL_SUCCESS) {
382
-			return CL_EARJ;
382
+			return CL_EUNPACK;
383 383
 		}
384 384
 	}
385 385
 	return CL_SUCCESS;
... ...
@@ -427,8 +427,8 @@ static int read_c_len(arj_decode_t *decode_data)
427 427
 			}
428 428
 			if (c >= 19) {
429 429
 				cli_dbgmsg("UNARJ: bounds exceeded\n");
430
-				decode_data->status = CL_EARJ;
431
-				return CL_EARJ;
430
+				decode_data->status = CL_EUNPACK;
431
+				return CL_EUNPACK;
432 432
 			}
433 433
 			fill_buf(decode_data, (int)(decode_data->pt_len[c]));
434 434
 			if (decode_data->status != CL_SUCCESS) {
... ...
@@ -466,7 +466,7 @@ static int read_c_len(arj_decode_t *decode_data)
466 466
 			decode_data->c_len[i++] = 0;
467 467
 		}
468 468
 		if (make_table(decode_data, NC, decode_data->c_len, 12, decode_data->c_table, CTABLESIZE) != CL_SUCCESS) {
469
-			return CL_EARJ;
469
+			return CL_EUNPACK;
470 470
 		}
471 471
 	}
472 472
 	return CL_SUCCESS;
... ...
@@ -490,7 +490,7 @@ static uint16_t decode_c(arj_decode_t *decode_data)
490 490
 		do {
491 491
 			if (j >= (2 * NC - 1)) {
492 492
 				cli_warnmsg("ERROR: bounds exceeded\n");
493
-				decode_data->status = CL_EARJ;
493
+				decode_data->status = CL_EUNPACK;
494 494
 				return 0;
495 495
 			}
496 496
 			if (decode_data->bit_buf & mask) {
... ...
@@ -515,7 +515,7 @@ static uint16_t decode_p(arj_decode_t *decode_data)
515 515
 		do {
516 516
 			if (j >= (2 * NC - 1)) {
517 517
 				cli_warnmsg("ERROR: bounds exceeded\n");
518
-				decode_data->status = CL_EARJ;
518
+				decode_data->status = CL_EUNPACK;
519 519
 				return 0;
520 520
 			}
521 521
 			if (decode_data->bit_buf & mask) {
... ...
@@ -563,7 +563,7 @@ static int decode(int fd, arj_metadata_t *metadata)
563 563
 				out_ptr = 0;
564 564
 				if (write_text(metadata->ofd, decode_data.text, DDICSIZ) != CL_SUCCESS) {
565 565
 					free(decode_data.text);
566
-					return CL_EIO;
566
+					return CL_EWRITE;
567 567
 				}
568 568
 			}
569 569
 		} else {
... ...
@@ -588,7 +588,7 @@ static int decode(int fd, arj_metadata_t *metadata)
588 588
 						out_ptr = 0;
589 589
 						if (write_text(metadata->ofd, decode_data.text, DDICSIZ) != CL_SUCCESS) {
590 590
 							free(decode_data.text);
591
-							return CL_EIO;
591
+							return CL_EWRITE;
592 592
 						}
593 593
 					}
594 594
 					if (++i >= DDICSIZ) {
... ...
@@ -697,7 +697,7 @@ static int decode_f(int fd, arj_metadata_t *metadata)
697 697
 				out_ptr = 0;
698 698
 				if (write_text(metadata->ofd, decode_data.text, DDICSIZ) != CL_SUCCESS) {
699 699
 					free(decode_data.text);
700
-					return CL_EIO;
700
+					return CL_EWRITE;
701 701
 				}
702 702
 			}
703 703
 		} else {
... ...
@@ -721,7 +721,7 @@ static int decode_f(int fd, arj_metadata_t *metadata)
721 721
 					out_ptr = 0;
722 722
 					if (write_text(metadata->ofd, decode_data.text, DDICSIZ) != CL_SUCCESS) {
723 723
 						free(decode_data.text);
724
-						return CL_EIO;
724
+						return CL_EWRITE;
725 725
 					}
726 726
 				}
727 727
 				if (++i >= DDICSIZ) {
... ...
@@ -1060,7 +1060,7 @@ int cli_unarj_extract_file(int fd, const char *dirname, arj_metadata_t *metadata
1060 1060
 		offset = lseek(fd, 0, SEEK_CUR) + metadata->comp_size;
1061 1061
 		cli_dbgmsg("Target offset: %ld\n", offset);
1062 1062
 		if (lseek(fd, offset, SEEK_SET) != offset) {
1063
-			return CL_EARJ;
1063
+			return CL_ESEEK;
1064 1064
 		}
1065 1065
 		return CL_SUCCESS;
1066 1066
 	}
... ...
@@ -1075,7 +1075,7 @@ int cli_unarj_extract_file(int fd, const char *dirname, arj_metadata_t *metadata
1075 1075
 		case 0:
1076 1076
 			ret = arj_unstore(fd, metadata->ofd, metadata->comp_size);
1077 1077
 			if (ret != metadata->comp_size) {
1078
-				ret = CL_EIO;
1078
+				ret = CL_EWRITE;
1079 1079
 			} else {
1080 1080
 				ret = CL_SUCCESS;
1081 1081
 			}
... ...
@@ -80,7 +80,7 @@ cli_untar(const char *dir, int desc, unsigned int posix, cli_ctx *ctx)
80 80
 			if(fout>=0)
81 81
 				close(fout);
82 82
 			cli_errmsg("cli_untar: block read error\n");
83
-			return CL_EIO;
83
+			return CL_EREAD;
84 84
 		}
85 85
 
86 86
 		if(!in_block) {
... ...
@@ -93,7 +93,7 @@ cli_untar(const char *dir, int desc, unsigned int posix, cli_ctx *ctx)
93 93
 				ret = cli_magic_scandesc(fout, ctx);
94 94
 				close(fout);
95 95
 				if (!ctx->engine->keeptmp)
96
-					if (cli_unlink(fullname)) return CL_EIO;
96
+					if (cli_unlink(fullname)) return CL_EUNLINK;
97 97
 				if (ret==CL_VIRUS)
98 98
 					return CL_VIRUS;
99 99
 				fout = -1;
... ...
@@ -200,7 +200,7 @@ cli_untar(const char *dir, int desc, unsigned int posix, cli_ctx *ctx)
200 200
 				cli_errmsg("cli_untar: only wrote %d bytes to file %s (out of disc space?)\n",
201 201
 					nwritten, fullname);
202 202
 				close(fout);
203
-				return CL_EIO;
203
+				return CL_EWRITE;
204 204
 			}
205 205
 			size -= nbytes;
206 206
 		}
... ...
@@ -212,7 +212,7 @@ cli_untar(const char *dir, int desc, unsigned int posix, cli_ctx *ctx)
212 212
 		ret = cli_magic_scandesc(fout, ctx);
213 213
 		close(fout);
214 214
 		if (!ctx->engine->keeptmp)
215
-			if (cli_unlink(fullname)) return CL_EIO;
215
+			if (cli_unlink(fullname)) return CL_EUNLINK;
216 216
 		if (ret==CL_VIRUS)
217 217
 			return CL_VIRUS;
218 218
 	}
... ...
@@ -91,7 +91,7 @@ static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, ui
91 91
   if((of = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRUSR|S_IWUSR))==-1) {
92 92
     cli_warnmsg("cli_unzip: failed to create temporary file %s\n", tempfile);
93 93
     if(!tmpd) free(tempfile);
94
-    return CL_EIO;
94
+    return CL_ECREAT;
95 95
   }
96 96
   switch (method) {
97 97
   case ALG_STORED:
... ...
@@ -109,7 +109,7 @@ static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, ui
109 109
 	cli_dbgmsg("cli_unzip: trimming output size to maxfilesize (%lu)\n", ctx->engine->maxfilesize);
110 110
 	csize = ctx->engine->maxfilesize;
111 111
       }
112
-      if(cli_writen(of, src, csize)!=(int)csize) ret = CL_EIO;
112
+      if(cli_writen(of, src, csize)!=(int)csize) ret = CL_EWRITE;
113 113
       else res=0;
114 114
     }
115 115
     break;
... ...
@@ -173,7 +173,7 @@ static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, ui
173 173
 	}
174 174
 	if(cli_writen(of, obuf, sizeof(obuf)-(*avail_out)) != (int)(sizeof(obuf)-(*avail_out))) {
175 175
 	  cli_warnmsg("cli_unzip: falied to write %lu inflated bytes\n", sizeof(obuf)-(*avail_out));
176
-	  ret = CL_EIO;
176
+	  ret = CL_EWRITE;
177 177
 	  res = 100;
178 178
 	  break;
179 179
 	}
... ...
@@ -217,7 +217,7 @@ static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, ui
217 217
 	}
218 218
 	if(cli_writen(of, obuf, sizeof(obuf)-strm.avail_out) != (int)(sizeof(obuf)-strm.avail_out)) {
219 219
 	  cli_warnmsg("cli_unzip: falied to write %lu bunzipped bytes\n", sizeof(obuf)-strm.avail_out);
220
-	  ret = CL_EIO;
220
+	  ret = CL_EWRITE;
221 221
 	  res = 100;
222 222
 	  break;
223 223
 	}
... ...
@@ -254,7 +254,7 @@ static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, ui
254 254
 	}
255 255
 	if(cli_writen(of, obuf, sizeof(obuf)-strm.avail_out) != (int)(sizeof(obuf)-strm.avail_out)) {
256 256
 	  cli_warnmsg("cli_unzip: falied to write %lu exploded bytes\n", sizeof(obuf)-strm.avail_out);
257
-	  ret = CL_EIO;
257
+	  ret = CL_EWRITE;
258 258
 	  res = 100;
259 259
 	  break;
260 260
 	}
... ...
@@ -304,14 +304,14 @@ static int unz(uint8_t *src, uint32_t csize, uint32_t usize, uint16_t method, ui
304 304
     ret = cli_magic_scandesc(of, ctx);
305 305
     close(of);
306 306
     if(!ctx->engine->keeptmp)
307
-      if(cli_unlink(tempfile)) ret = CL_EIO;
307
+      if(cli_unlink(tempfile)) ret = CL_EUNLINK;
308 308
     if(!tmpd) free(tempfile);
309 309
     return ret;
310 310
   }
311 311
 
312 312
   close(of);
313 313
   if(!ctx->engine->keeptmp)
314
-    if(cli_unlink(tempfile)) ret = CL_EIO;
314
+    if(cli_unlink(tempfile)) ret = CL_EUNLINK;
315 315
   if(!tmpd) free(tempfile);
316 316
   cli_dbgmsg("cli_unzip: extraction failed\n");
317 317
   return ret;
... ...
@@ -482,7 +482,7 @@ int cli_unzip(int f, cli_ctx *ctx) {
482 482
   cli_dbgmsg("in cli_unzip\n");
483 483
   if (fstat(f, &st)==-1) {
484 484
     cli_warnmsg("cli_unzip: fstat() failed\n");
485
-    return CL_EIO;
485
+    return CL_ESTAT;
486 486
   }
487 487
   fsize = (uint32_t)st.st_size;
488 488
   if(sizeof(off_t)!=sizeof(uint32_t) && (off_t)fsize!=st.st_size) {
... ...
@@ -497,7 +497,7 @@ int cli_unzip(int f, cli_ctx *ctx) {
497 497
 #if HAVE_MMAP
498 498
   if ((map = mmap(NULL, fsize, PROT_READ, MAP_PRIVATE, f, 0))==MAP_FAILED) {
499 499
     cli_dbgmsg("cli_unzip: mmap failed\n");
500
-    return CL_EMEM;
500
+    return CL_EMAP;
501 501
   }
502 502
 #else
503 503
   if(fsize > CLI_MAX_ALLOCATION) {
... ...
@@ -509,7 +509,7 @@ int cli_unzip(int f, cli_ctx *ctx) {
509 509
     return CL_EMEM;
510 510
   if(cli_readn(f, map, fsize)!=fsize) {
511 511
     free(map);
512
-    return CL_EIO;
512
+    return CL_EREAD;
513 513
   }
514 514
 #endif
515 515
 
... ...
@@ -572,7 +572,7 @@ int cli_unzip_single(int f, cli_ctx *ctx, off_t lhoffl) {
572 572
   cli_dbgmsg("in cli_unzip_single\n");
573 573
   if (fstat(f, &st)==-1) {
574 574
     cli_warnmsg("cli_unzip: fstat() failed\n");
575
-    return CL_EIO;
575
+    return CL_ESTAT;
576 576
   }
577 577
   fsize = (uint32_t)(st.st_size - lhoffl);
578 578
   if (lhoffl<0 || lhoffl>st.st_size || (sizeof(off_t)!=sizeof(uint32_t) && (off_t)fsize!=st.st_size - lhoffl)) {
... ...
@@ -587,7 +587,7 @@ int cli_unzip_single(int f, cli_ctx *ctx, off_t lhoffl) {
587 587
 #if HAVE_MMAP
588 588
   if ((map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, f, 0))==MAP_FAILED) {
589 589
     cli_dbgmsg("cli_unzip: mmap() failed\n");
590
-    return CL_EMEM;
590
+    return CL_EMAP;
591 591
   }
592 592
 #else
593 593
   if(st.st_size > CLI_MAX_ALLOCATION) {
... ...
@@ -599,7 +599,7 @@ int cli_unzip_single(int f, cli_ctx *ctx, off_t lhoffl) {
599 599
     return CL_EMEM;
600 600
   if(cli_readn(f, map, st.st_size)!=st.st_size) {
601 601
     free(map);
602
-    return CL_EIO;
602
+    return CL_EREAD;
603 603
   }
604 604
 #endif
605 605
   lhdr(&map[lhoffl], fsize, &fu, 0, NULL, &ret, ctx, NULL);
... ...
@@ -561,7 +561,7 @@ cli_scan_ole10(int fd, cli_ctx *ctx)
561 561
 		return CL_CLEAN;
562 562
 
563 563
 	if(fstat(fd, &statbuf) == -1)
564
-		return CL_EIO;
564
+		return CL_ESTAT;
565 565
 
566 566
 	if ((statbuf.st_size - object_size) >= 4) {
567 567
 		/* Probably the OLE type id */
... ...
@@ -596,7 +596,7 @@ cli_scan_ole10(int fd, cli_ctx *ctx)
596 596
 	if (ofd < 0) {
597 597
 		cli_warnmsg("cli_decode_ole_object: can't create %s\n",	fullname);
598 598
 		free(fullname);
599
-		return CL_EIO;
599
+		return CL_ECREAT;
600 600
 	}
601 601
 	cli_dbgmsg("cli_decode_ole_object: decoding to %s\n", fullname);
602 602
 	ole_copy_file_data(fd, ofd, object_size);
... ...
@@ -605,7 +605,7 @@ cli_scan_ole10(int fd, cli_ctx *ctx)
605 605
 	close(ofd);
606 606
 	if(ctx && !ctx->engine->keeptmp)
607 607
 	  if (cli_unlink(fullname))
608
-	    ret = CL_EIO;
608
+	    ret = CL_EUNLINK;
609 609
 	free(fullname);
610 610
 	return ret;
611 611
 }
... ...
@@ -301,21 +301,21 @@ static struct dsig_test {
301 301
     {"96b7feb3b2a863846438809fe481906f", "Zh5gmf09Zfj6V4gmRKu/NURzhFiE9VloI7w1G33BgDdGSs0Xhscx6sjPUpFSCPsjOalyS4L8q7RS+NdGvNCsLymiIH6RYItlOZsygFhcGuH4jt15KAaAkvEg2TwmqR8z41nUaMlZ0c8q1MXYCLvQJyFARsfzIxS3PAoN2Y3HPoe",
302 302
 	CL_SUCCESS},
303 303
     {"ae307614434715274c60854c931a26de", "Zh5gmf09Zfj6V4gmRKu/NURzhFiE9VloI7w1G33BgDdGSs0Xhscx6sjPUpFSCPsjOalyS4L8q7RS+NdGvNCsLymiIH6RYItlOZsygFhcGuH4jt15KAaAkvEg2TwmqR8z41nUaMlZ0c8q1MXYCLvQJyFARsfzIxS3PAoN2Y3HPoe",
304
-	CL_EDSIG},
304
+	CL_EVERIFY},
305 305
     {"96b7feb3b2a863846438809fe481906f", "60uhCFmiN48J8r6c7coBv9Q1mehAWEGh6GPYA+60VhQcuXfb0iV1O+sCEyMiRXt/iYF6vXtPXHVd6DiuZ4Gfrry7sVQqNTt3o1/KwU1rc0l5FHgX/nC99fdr/fjaFtinMtRnUXHLeu0j8e6HK+7JLBpD37fZ60GC9YY86EclYGe",
306
-	CL_EDSIG},
306
+	CL_EVERIFY},
307 307
     {"ae307614434715274060854c931a26de", "60uhCFmiN48J8r6c7coBv9Q1mehAWEGh6GPYA+60VhQcuXfb0iV1O+sCEyMiRXt/iYF6vXtPXHVd6DiuZ4Gfrry7sVQqNTt3o1/KwU1rc0l5FHgX/nC99fdr/fjaFtinMtRnUXHLeu0j8e6HK+7JLBpD37fZ60GC9YY86EclYGe",
308
-	CL_EDSIG},
308
+	CL_EVERIFY},
309 309
     {"ae307614434715274c60854c931a26de", "60uhCFmiN48J8r6c7coBv9Q1mehAWEGh6GPYA+60VhQcuXfb0iV1O+sCEyMiRXt/iYF6vXtPXHVd6DiuZ4Gfrry7sVQqNTt3o1/KwU1rc0l5FHgX/nC99fdr/fjaatinMtRnUXHLeu0j8e6HK+7JLBpD37fZ60GC9YY86EclYGe",
310
-	CL_EDSIG},
310
+	CL_EVERIFY},
311 311
     {"96b7feb3b2a863846438809fe481906f", "Zh5gmf09Zfj6V4gmRKu/NURzhFiE9VloI7w1G33BgDdGSs0Xhscx6sjPUpFSCPsjOalyS4L8q7RS+NdGvNCsLymiIH6RYItlOZsygFhcGuH4jt15KAaAkvEg2TwmqR8z41nUaMlZ0c8q1MYYCLvQJyFARsfzIxS3PAoN2Y3HPoe",
312
-	CL_EDSIG},
312
+	CL_EVERIFY},
313 313
     {"ge307614434715274c60854c931a26dee","60uhCFmiN48J8r6c7coBv9Q1mehAWEGh6GPYA+60VhQcuXfb0iV1O+sCEyMiRXt/iYF6vXtPXHVd6DiuZ4Gfrry7sVQqNTt3o1/KwU1rc0l5FHgX/nC99fdr/fjaFtinMtRnUXHLeu0j8e6HK+7JLBpD37fZ60GC9YY86EclYGe",
314
-	CL_EMD5},
314
+	CL_EVERIFY},
315 315
     {"ae307614434715274c60854c931a26de", "60uhCFmiN48J8r6c7coBv9Q1mehAWEGh6GPYA+60VhQcuXfb0iV1O+sCEyMiRXt/iYF6vXtPXHVd6DiuZ4Gfrry7sVQqNTt3o1/KwU1rc0l5FHgX/nC99fdr/fjaFtinMtRnUXHLeu0j8e6HK+7JLBpD37fZ60GC9YY86EclYGee", 
316
-	CL_EDSIG},
316
+	CL_EVERIFY},
317 317
     {"ae307614434715274c60854c931a26de", "60uhCFmiN48J8r6c7coBv9Q1mehAWEGh6GPYA+", 
318
-	CL_EDSIG}
318
+	CL_EVERIFY}
319 319
 };
320 320
 
321 321
 static const size_t dsig_tests_cnt = sizeof(dsig_tests)/sizeof(dsig_tests[0]);