home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
CMDS
/
file.lzh
/
istar.c
< prev
next >
Wrap
Text File
|
1995-04-27
|
1KB
|
56 lines
/***************************************
* istar.c *
***************************************
* determine if a passed buffer is a *
* valid tar format. Will return 0 if *
* not, 1 if old tar, 2 if POSIX tar. *
***************************************
* original code: Scott McGee 12/08/93 *
**************************************/
/***********************************************************************
revision history:
who when what
------------------------------------------------------------------------
sam 04/04/95 added size parameter to checkMagic()
***********************************************************************/
#include <file.h>
int istar(buf, size)
char *buf;
int size;
{
char *ptr = buf;
char *end;
long chksum = 0x0;
long recsum;
int i;
if(size < TAR_MAGIC_OFFSET)
return(NOT_TAR);
if(strncmp(buf+TAR_MAGIC_OFFSET, TAR_MAGIC, TAR_MAGIC_SIZE) == 0)
return(POSIX_TAR);
recsum = strtoul(buf+TAR_CHKSUM_OFFSET, &end, 8);
for(i=0;i<TAR_REC_SIZE;i++){
chksum = chksum + (0xff & *ptr);
ptr++;
}
for(i=0;i<TAR_CHKSUM_OFFSET;i++){
chksum = chksum - (0xff & (buf+TAR_CHKSUM_OFFSET)[i]);
}
chksum = chksum + ' '*TAR_CHKSUM_SIZE;
if((chksum != recsum) && ((chksum + 0x20) != recsum))
return(NOT_TAR);
return(OLD_TAR);
}