#include "names.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: ascmagic.c,v 1.36 2003/03/26 15:35:30 christos Exp $")
+FILE_RCSID("@(#)$Id: ascmagic.c,v 1.37 2003/03/27 18:34:21 christos Exp $")
#endif /* lint */
typedef unsigned long unichar;
int last_line_end = -1;
int has_long_lines = 0;
- /*
- * 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 (file_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;
- }
-
/*
* Undo the NUL-termination kindly provided by process()
* but leave at least one byte to look at
*/
/*
* file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.51 2003/03/26 16:25:58 christos Exp $
+ * @(#)$Id: file.h,v 1.52 2003/03/27 18:34:21 christos Exp $
*/
#ifndef __file_h__
protected int file_tryelf(struct magic_set *, int, const unsigned char *, size_t);
protected int file_zmagic(struct magic_set *, const unsigned char *, size_t);
protected int file_ascmagic(struct magic_set *, const unsigned char *, size_t);
-protected int file_is_tar(const unsigned char *, size_t);
+protected int file_is_tar(struct magic_set *, const unsigned char *, size_t);
protected int file_softmagic(struct magic_set *, const unsigned char *, size_t);
protected struct mlist *file_apprentice(struct magic_set *, const char *, int);
protected uint32_t file_signextend(struct magic_set *, struct magic *, uint32_t);
int m;
/* try compression stuff */
if ((m = file_zmagic(ms, buf, nb)) == 0) {
- /* try tests in /etc/magic (or surrogate magic file) */
- if ((m = file_softmagic(ms, buf, nb)) == 0) {
- /* try known keywords, check whether it is ASCII */
- if ((m = file_ascmagic(ms, buf, nb)) == 0) {
- /* abandon hope, all ye who remain here */
- if (file_printf(ms, ms->flags & MAGIC_MIME ?
- "application/octet-stream" : "data") == -1)
- return -1;
- m = 1;
+ /* Check if we have a tar file */
+ if ((m = file_is_tar(ms, buf, nb)) == 0) {
+ /* try tests in /etc/magic (or surrogate magic file) */
+ if ((m = file_softmagic(ms, buf, nb)) == 0) {
+ /* try known keywords, check whether it is ASCII */
+ if ((m = file_ascmagic(ms, buf, nb)) == 0) {
+ /* abandon hope, all ye who remain here */
+ if (file_printf(ms, ms->flags & MAGIC_MIME ?
+ "application/octet-stream" : "data") == -1)
+ return -1;
+ m = 1;
+ }
}
}
}
#include "tar.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: is_tar.c,v 1.20 2003/03/26 15:35:30 christos Exp $")
+FILE_RCSID("@(#)$Id: is_tar.c,v 1.21 2003/03/27 18:34:21 christos Exp $")
#endif
#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
+private int is_tar(const unsigned char *, size_t);
private int from_oct(int, const char *); /* Decode octal number */
+protected int
+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;
+ default:
+ return 0;
+ }
+}
+
/*
* Return
* 0 if the checksum is bad (i.e., probably not a tar archive),
* 1 for old UNIX tar file,
* 2 for Unix Std (POSIX) tar file.
*/
-protected int
-file_is_tar(const unsigned char *buf, size_t nbytes)
+private int
+is_tar(const unsigned char *buf, size_t nbytes)
{
const union record *header = (const union record *)(const void *)buf;
int i;