#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.74 2014/10/26 20:23:30 christos Exp $")
#endif
#include "magic.h"
const unsigned char *old, unsigned char **newch, size_t n)
{
int fdin[2], fdout[2];
+ int status;
ssize_t r;
pid_t pid;
/*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;
(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) {
strerror(errno));
#endif
free(*newch);
- n = 0;
+ n = NODATA;
*newch = NULL;
goto err;
} else {
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;