summaryrefslogtreecommitdiffstats
path: root/contrib/file/compress.c
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2012-04-19 03:20:13 +0000
committerobrien <obrien@FreeBSD.org>2012-04-19 03:20:13 +0000
commit248502d7f08de3125e3e3cc808446294565ba5df (patch)
treec7640efe490a887a5460d7a88d62aca990489d21 /contrib/file/compress.c
parent86e3fa59a2a400ec95b0c84576fb00815631d92f (diff)
parent15f98df7891f1853090ecb6c4a9cc734e671ef6b (diff)
downloadFreeBSD-src-248502d7f08de3125e3e3cc808446294565ba5df.zip
FreeBSD-src-248502d7f08de3125e3e3cc808446294565ba5df.tar.gz
Update file(1) to version 5.11.
Diffstat (limited to 'contrib/file/compress.c')
-rw-r--r--contrib/file/compress.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/contrib/file/compress.c b/contrib/file/compress.c
index 28dacd3..4308abf 100644
--- a/contrib/file/compress.c
+++ b/contrib/file/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.68 2011/12/08 12:38:24 rrt 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
@@ -132,19 +134,18 @@ file_zmagic(struct magic_set *ms, int fd, const char *name,
}
}
error:
- if (newbuf)
- free(newbuf);
+ free(newbuf);
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 +156,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 +168,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 +239,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 +256,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 +301,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 +345,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 +380,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 +395,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 +492,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 +502,4 @@ err:
return n;
}
}
+#endif
OpenPOWER on IntegriCloud