summaryrefslogtreecommitdiffstats
path: root/compress.c
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2011-10-06 06:01:12 +0000
committerobrien <obrien@FreeBSD.org>2011-10-06 06:01:12 +0000
commit75c49f9dd6a0ff710f7c791a485899c7a07af444 (patch)
treed25590ff6bfc3386fbca9494d26b8761e3d33410 /compress.c
parent862d9405b857dba35f8f2eb6d0623b9a552d4353 (diff)
downloadFreeBSD-src-75c49f9dd6a0ff710f7c791a485899c7a07af444.zip
FreeBSD-src-75c49f9dd6a0ff710f7c791a485899c7a07af444.tar.gz
Virgin import of Christos Zoulas's FILE 5.09.
Diffstat (limited to 'compress.c')
-rw-r--r--compress.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/compress.c b/compress.c
index 28dacd3..b82ab7b 100644
--- a/compress.c
+++ b/compress.c
@@ -35,7 +35,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: compress.c,v 1.63 2009/03/23 14:21:51 christos Exp $")
+FILE_RCSID("@(#)$File: compress.c,v 1.67 2011/09/01 12:12:37 christos Exp $")
#endif
#include "magic.h"
@@ -45,7 +45,9 @@ FILE_RCSID("@(#)$File: compress.c,v 1.63 2009/03/23 14:21:51 christos Exp $")
#endif
#include <string.h>
#include <errno.h>
+#ifndef __MINGW32__
#include <sys/ioctl.h>
+#endif
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
@@ -77,14 +79,14 @@ private const struct {
{ "BZh", 3, { "bzip2", "-cd", NULL }, 1 }, /* bzip2-ed */
{ "LZIP", 4, { "lzip", "-cdq", NULL }, 1 },
{ "\3757zXZ\0",6,{ "xz", "-cd", NULL }, 1 }, /* XZ Utils */
+ { "LRZI", 4, { "lrzip", "-dqo-", NULL }, 1 }, /* LRZIP */
};
-private size_t ncompr = sizeof(compr) / sizeof(compr[0]);
-
#define NODATA ((size_t)~0)
-
private ssize_t swrite(int, const void *, size_t);
+#if HAVE_FORK
+private size_t ncompr = sizeof(compr) / sizeof(compr[0]);
private size_t uncompressbuf(struct magic_set *, int, size_t,
const unsigned char *, unsigned char **, size_t);
#ifdef BUILTIN_DECOMPRESS
@@ -137,14 +139,14 @@ error:
ms->flags |= MAGIC_COMPRESS;
return rv;
}
-
+#endif
/*
* `safe' write for sockets and pipes.
*/
private ssize_t
swrite(int fd, const void *buf, size_t n)
{
- int rv;
+ ssize_t rv;
size_t rn = n;
do
@@ -155,7 +157,7 @@ swrite(int fd, const void *buf, size_t n)
return -1;
default:
n -= rv;
- buf = ((const char *)buf) + rv;
+ buf = CAST(const char *, buf) + rv;
break;
}
while (n > 0);
@@ -167,9 +169,12 @@ swrite(int fd, const void *buf, size_t n)
* `safe' read for sockets and pipes.
*/
protected ssize_t
-sread(int fd, void *buf, size_t n, int canbepipe)
+sread(int fd, void *buf, size_t n, int canbepipe __attribute__ ((unused)))
{
- int rv, cnt;
+ ssize_t rv;
+#ifdef FD_ZERO
+ ssize_t cnt;
+#endif
#ifdef FIONREAD
int t = 0;
#endif
@@ -235,7 +240,11 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf,
size_t nbytes)
{
char buf[4096];
- int r, tfd;
+ ssize_t r;
+ int tfd;
+#ifdef HAVE_MKSTEMP
+ int te;
+#endif
(void)strlcpy(buf, "/tmp/file.XXXXXX", sizeof buf);
#ifndef HAVE_MKSTEMP
@@ -248,9 +257,9 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf,
}
#else
tfd = mkstemp(buf);
- r = errno;
+ te = errno;
(void)unlink(buf);
- errno = r;
+ errno = te;
#endif
if (tfd == -1) {
file_error(ms, errno,
@@ -293,7 +302,7 @@ file_pipe2file(struct magic_set *ms, int fd, const void *startbuf,
}
return fd;
}
-
+#if HAVE_FORK
#ifdef BUILTIN_DECOMPRESS
#define FHCRC (1 << 1)
@@ -337,13 +346,14 @@ uncompressgzipped(struct magic_set *ms, const unsigned char *old,
/* XXX: const castaway, via strchr */
z.next_in = (Bytef *)strchr((const char *)old + data_start,
old[data_start]);
- z.avail_in = n - data_start;
+ z.avail_in = CAST(uint32_t, (n - data_start));
z.next_out = *newch;
z.avail_out = HOWMANY;
z.zalloc = Z_NULL;
z.zfree = Z_NULL;
z.opaque = Z_NULL;
+ /* LINTED bug in header macro */
rc = inflateInit2(&z, -15);
if (rc != Z_OK) {
file_error(ms, 0, "zlib: %s", z.msg);
@@ -371,7 +381,8 @@ 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 r;
+ ssize_t r;
+ pid_t pid;
#ifdef BUILTIN_DECOMPRESS
/* FIXME: This doesn't cope with bzip2 */
@@ -385,7 +396,7 @@ uncompressbuf(struct magic_set *ms, int fd, size_t method,
file_error(ms, errno, "cannot create pipe");
return NODATA;
}
- switch (fork()) {
+ switch (pid = fork()) {
case 0: /* child */
(void) close(0);
if (fd != -1) {
@@ -482,7 +493,7 @@ err:
(void) close(fdin[1]);
(void) close(fdout[0]);
#ifdef WNOHANG
- while (waitpid(-1, NULL, WNOHANG) != -1)
+ while (waitpid(pid, NULL, WNOHANG) != -1)
continue;
#else
(void)wait(NULL);
@@ -492,3 +503,4 @@ err:
return n;
}
}
+#endif
OpenPOWER on IntegriCloud