summaryrefslogtreecommitdiffstats
path: root/contrib/file/src/compress.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/file/src/compress.c')
-rw-r--r--contrib/file/src/compress.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/contrib/file/src/compress.c b/contrib/file/src/compress.c
index 45251b1..4a6f42e 100644
--- a/contrib/file/src/compress.c
+++ b/contrib/file/src/compress.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.73 2014/01/05 15:55:21 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.75 2014/12/04 15:56:46 christos Exp $")
#endif
#include "magic.h"
@@ -45,7 +45,7 @@ FILE_RCSID("@(#)$File: compress.c,v 1.73 2014/01/05 15:55:21 christos Exp $")
#endif
#include <string.h>
#include <errno.h>
-#ifndef __MINGW32__
+#if !defined(__MINGW32__) && !defined(WIN32)
#include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_WAIT_H
@@ -377,6 +377,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
const unsigned char *old, unsigned char **newch, size_t n)
{
int fdin[2], fdout[2];
+ int status;
ssize_t r;
pid_t pid;
@@ -459,7 +460,17 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
/*NOTREACHED*/
default: /* parent */
- break;
+ if (wait(&status) == -1) {
+#ifdef DEBUG
+ (void)fprintf(stderr,
+ "Wait failed (%s)\n",
+ strerror(errno));
+#endif
+ exit(1);
+ }
+ exit(WIFEXITED(status) ?
+ WEXITSTATUS(status) : 1);
+ /*NOTREACHED*/
}
(void) close(fdin[1]);
fdin[1] = -1;
@@ -470,7 +481,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
(void)fprintf(stderr, "Malloc failed (%s)\n",
strerror(errno));
#endif
- n = 0;
+ n = NODATA;
goto err;
}
if ((r = sread(fdout[0], *newch, HOWMANY, 0)) <= 0) {
@@ -479,7 +490,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
strerror(errno));
#endif
free(*newch);
- n = 0;
+ n = NODATA;
*newch = NULL;
goto err;
} else {
@@ -491,12 +502,19 @@ err:
if (fdin[1] != -1)
(void) close(fdin[1]);
(void) close(fdout[0]);
-#ifdef WNOHANG
- while (waitpid(pid, NULL, WNOHANG) != -1)
- continue;
-#else
- (void)wait(NULL);
+ if (wait(&status) == -1) {
+#ifdef DEBUG
+ (void)fprintf(stderr, "Wait failed (%s)\n",
+ strerror(errno));
#endif
+ n = NODATA;
+ } else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+#ifdef DEBUG
+ (void)fprintf(stderr, "Child status (0x%x)\n", status);
+#endif
+ n = NODATA;
+ }
+
(void) close(fdin[0]);
return n;
OpenPOWER on IntegriCloud