diff options
author | obrien <obrien@FreeBSD.org> | 2008-01-13 20:35:16 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2008-01-13 20:35:16 +0000 |
commit | 6678cf7c2ac8c768ea5efe9fe0392f07e522c963 (patch) | |
tree | 5ce2a6ee53483b8b3a7ac87258304920c043207f /contrib/file/is_tar.c | |
parent | 240c77918bbcf0d5f67799916b808b8a65d434c5 (diff) | |
download | FreeBSD-src-6678cf7c2ac8c768ea5efe9fe0392f07e522c963.zip FreeBSD-src-6678cf7c2ac8c768ea5efe9fe0392f07e522c963.tar.gz |
Import file version 4.23 onto the vendor branch
Diffstat (limited to 'contrib/file/is_tar.c')
-rw-r--r-- | contrib/file/is_tar.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/contrib/file/is_tar.c b/contrib/file/is_tar.c index c7d4d4d..142b487 100644 --- a/contrib/file/is_tar.c +++ b/contrib/file/is_tar.c @@ -45,7 +45,7 @@ #include "tar.h" #ifndef lint -FILE_RCSID("@(#)$File: is_tar.c,v 1.27 2007/01/12 17:38:28 christos Exp $") +FILE_RCSID("@(#)$File: is_tar.c,v 1.29 2007/10/17 19:33:31 christos Exp $") #endif #define isodigit(c) ( ((c) >= '0') && ((c) <= '7') ) @@ -53,6 +53,12 @@ FILE_RCSID("@(#)$File: is_tar.c,v 1.27 2007/01/12 17:38:28 christos Exp $") private int is_tar(const unsigned char *, size_t); private int from_oct(int, const char *); /* Decode octal number */ +static const char *tartype[] = { + "tar archive", + "POSIX tar archive", + "POSIX tar archive (GNU)", +}; + protected int file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes) { @@ -60,26 +66,19 @@ file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes) * Do the tar test first, because if the first file in the tar * archive starts with a dot, we can confuse it with an nroff file. */ - switch (is_tar(buf, nbytes)) { - case 1: - if (file_printf(ms, (ms->flags & MAGIC_MIME) ? - "application/x-tar" : "tar archive") == -1) - return -1; - return 1; - case 2: - if (file_printf(ms, (ms->flags & MAGIC_MIME) ? - "application/x-tar, POSIX" : "POSIX tar archive") == -1) - return -1; - return 1; - case 3: - if (file_printf(ms, (ms->flags & MAGIC_MIME) ? - "application/x-tar, POSIX (GNU)" : - "POSIX tar archive (GNU)") == -1) - return -1; - return 1; - default: + int tar = is_tar(buf, nbytes); + int mime = ms->flags & MAGIC_MIME; + + if (tar < 1 || tar > 3) return 0; - } + + if (mime == MAGIC_MIME_ENCODING) + return 0; + + if (file_printf(ms, mime ? "application/x-tar" : + tartype[tar - 1]) == -1) + return -1; + return 1; } /* |