summaryrefslogtreecommitdiff
path: root/src/is_tar.c
diff options
context:
space:
mode:
authorReuben Thomas <rrt@sc3d.org>2010-11-30 14:58:53 +0000
committerReuben Thomas <rrt@sc3d.org>2010-11-30 14:58:53 +0000
commita1d79b486f20e4be1d66c5b5d149bcbcd3661e2b (patch)
treed8b21fd7504be26640814e5f812679afd2780a2a /src/is_tar.c
parentc612d7f91428311e8909fd01e0238d83ec6defe3 (diff)
downloadfile-git-a1d79b486f20e4be1d66c5b5d149bcbcd3661e2b.tar.gz
Slight improvements to tar code, and fix to -e soft.
Diffstat (limited to 'src/is_tar.c')
-rw-r--r--src/is_tar.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/is_tar.c b/src/is_tar.c
index f962edbd..876c631b 100644
--- a/src/is_tar.c
+++ b/src/is_tar.c
@@ -2,7 +2,7 @@
* 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:
@@ -12,7 +12,7 @@
* 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
@@ -40,7 +40,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: is_tar.c,v 1.36 2009/02/03 20:27:51 christos Exp $")
+FILE_RCSID("@(#)$File: is_tar.c,v 1.37 2010/11/30 14:58:53 rrt Exp $")
#endif
#include "magic.h"
@@ -83,8 +83,8 @@ file_is_tar(struct magic_set *ms, const unsigned char *buf, size_t nbytes)
}
/*
- * 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.
@@ -95,7 +95,7 @@ is_tar(const unsigned char *buf, size_t nbytes)
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;
@@ -104,25 +104,20 @@ is_tar(const unsigned char *buf, size_t nbytes)
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 */
@@ -132,7 +127,7 @@ is_tar(const unsigned char *buf, size_t nbytes)
/*
* 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)
@@ -145,13 +140,13 @@ 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;
}