+2010-11-26 18:39 Reuben Thomas <rrt@sc3d.org>
+ * Fix "-e soft": it was ignored when softmagic was called
+ during asciimagic.
+ * Improve comments and use "unsigned char" in tar.h/is_tar.c.
+
2010-11-05 17:26 Reuben Thomas <rrt@sc3d.org>
* Make bug reporting addresses more visible.
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: ascmagic.c,v 1.75 2009/02/03 20:27:51 christos Exp $")
+FILE_RCSID("@(#)$File: ascmagic.c,v 1.76 2010/10/08 21:58:44 christos Exp $")
#endif /* lint */
#include "magic.h"
goto done;
}
- rv = file_ascmagic_with_encoding(ms, buf, nbytes, ubuf, ulen, code,
+ rv = file_ascmagic_with_encoding(ms, buf, nbytes, ubuf, ulen, code,
type);
done:
goto done;
}
- /* Convert ubuf to UTF-8 and try text soft magic */
- /* malloc size is a conservative overestimate; could be
- improved, or at least realloced after conversion. */
- mlen = ulen * 6;
- if ((utf8_buf = CAST(unsigned char *, malloc(mlen))) == NULL) {
- file_oomem(ms, mlen);
- goto done;
+ if ((ms->flags & MAGIC_NO_CHECK_SOFT) == 0) {
+ /* Convert ubuf to UTF-8 and try text soft magic */
+ /* malloc size is a conservative overestimate; could be
+ improved, or at least realloced after conversion. */
+ mlen = ulen * 6;
+ if ((utf8_buf = CAST(unsigned char *, malloc(mlen))) == NULL) {
+ file_oomem(ms, mlen);
+ goto done;
+ }
+ if ((utf8_end = encode_utf8(utf8_buf, mlen, ubuf, ulen)) == NULL)
+ goto done;
+ if ((rv = file_softmagic(ms, utf8_buf, (size_t)(utf8_end - utf8_buf),
+ TEXTTEST)) != 0)
+ goto done;
+ else
+ rv = -1;
}
- if ((utf8_end = encode_utf8(utf8_buf, mlen, ubuf, ulen)) == NULL)
- goto done;
- if ((rv = file_softmagic(ms, utf8_buf, (size_t)(utf8_end - utf8_buf),
- TEXTTEST)) != 0)
- goto done;
- else
- rv = -1;
/* look for tokens from names.h - this is expensive! */
if ((ms->flags & MAGIC_NO_CHECK_TOKENS) != 0)
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.138 2010/09/20 21:00:44 rrt Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.139 2010/10/08 22:03:57 christos Exp $")
#endif /* lint */
#include "magic.h"
flags |= MAGIC_DEVICES;
break;
case 'v':
- if (magicfile == NULL)
+ if (magicfile == NULL)
magicfile = magic_getpath(magicfile, action);
(void)fprintf(stderr, "%s-%d.%.2d\n", progname,
FILE_VERSION_MAJOR, patchlevel);
if (wid > 0 && !bflag) {
(void)printf("%s", std_in ? "/dev/stdin" : inname);
if (nulsep)
- (void)putc('\0', stdout);
+ (void)putc('\0', stdout);
(void)printf("%s", separator);
(void)printf("%*s ",
(int) (nopad ? 0 : (wid - file_mbswidth(inname))), "");
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
* maintained 1995-present by Christos Zoulas and others.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: is_tar.c,v 1.35 2008/11/07 18:57:28 christos Exp $")
+FILE_RCSID("@(#)$File: is_tar.c,v 1.36 2009/02/03 20:27:51 christos Exp $")
#endif
#include "magic.h"
}
/*
- * Return
- * 0 if the checksum is bad (i.e., probably not a tar archive),
+ * 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,
* 3 for GNU tar file.
const union record *header = (const union record *)(const void *)buf;
int i;
int sum, recsum;
- const char *p;
+ const unsigned char *p;
if (nbytes < sizeof(union record))
return 0;
sum = 0;
p = header->charptr;
- for (i = sizeof(union record); --i >= 0;) {
- /*
- * We cannot use unsigned char here because of old compilers,
- * e.g. V7.
- */
- sum += 0xFF & *p++;
- }
+ for (i = sizeof(union record); --i >= 0;)
+ sum += *p++;
/* Adjust checksum to count the "chksum" field as blanks. */
for (i = sizeof(header->header.chksum); --i >= 0;)
- sum -= 0xFF & header->header.chksum[i];
- sum += ' '* sizeof header->header.chksum;
+ sum -= header->header.chksum[i];
+ sum += ' ' * sizeof header->header.chksum;
if (sum != recsum)
return 0; /* Not a tar archive */
-
- if (strcmp(header->header.magic, GNUTMAGIC) == 0)
+
+ if (strcmp(header->header.magic, GNUTMAGIC) == 0)
return 3; /* GNU Unix Standard tar archive */
- if (strcmp(header->header.magic, TMAGIC) == 0)
+ if (strcmp(header->header.magic, TMAGIC) == 0)
return 2; /* Unix Standard tar archive */
return 1; /* Old fashioned tar archive */
/*
* Quick and dirty octal conversion.
*
- * Result is -1 if the field is invalid (all blank, or nonoctal).
+ * Result is -1 if the field is invalid (all blank, or non-octal).
*/
private int
from_oct(int digs, const char *where)
return -1; /* All blank field */
}
value = 0;
- while (digs > 0 && isodigit(*where)) { /* Scan til nonoctal */
+ while (digs > 0 && isodigit(*where)) { /* Scan til non-octal */
value = (value << 3) | (*where++ - '0');
--digs;
}
if (digs > 0 && *where && !isspace((unsigned char)*where))
- return -1; /* Ended on non-space/nul */
+ return -1; /* Ended on non-(space/NUL) */
return value;
}
* Copyright (c) Ian F. Darwin 1986-1995.
* Software written by Ian F. Darwin and others;
* maintained 1995-present by Christos Zoulas and others.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
*
* Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
*
- * $File: tar.h,v 1.11 2007/01/16 14:56:45 ljt Exp $ # checkin only
+ * $File: tar.h,v 1.12 2008/02/07 00:58:52 christos Exp $ # checkin only
*/
/*
#define TGNMLEN 32
union record {
- char charptr[RECORDSIZE];
+ unsigned char charptr[RECORDSIZE];
struct header {
char name[NAMSIZ];
char mode[8];