ca76526b11
if it exists.
304 lines
9.0 KiB
Plaintext
304 lines
9.0 KiB
Plaintext
--- bin/megatron/asingle.c.orig Sat Feb 17 09:15:16 1996
|
|
+++ bin/megatron/asingle.c Thu Nov 11 17:31:12 1999
|
|
@@ -3,7 +3,7 @@
|
|
#include <sys/time.h>
|
|
#include <sys/param.h>
|
|
#include <fcntl.h>
|
|
-#include <strings.h>
|
|
+#include <string.h>
|
|
#include <syslog.h>
|
|
#include <ctype.h>
|
|
#include <stdio.h>
|
|
@@ -55,8 +55,8 @@
|
|
*/
|
|
|
|
struct entry_info {
|
|
- long offset;
|
|
- long length;
|
|
+ int32_t offset;
|
|
+ int32_t length;
|
|
};
|
|
|
|
/* Both input and output routines use this struct and the
|
|
@@ -70,7 +70,9 @@
|
|
} single;
|
|
|
|
extern char *forkname[];
|
|
-u_char header_buf[ HEADERSIZ ];
|
|
+u_int8_t header_buf[ HEADERSIZ ];
|
|
+
|
|
+int single_header_test(), single_header_read(), single_close();
|
|
|
|
/*
|
|
* single_open must be called first. pass it a filename that is supposed
|
|
@@ -78,40 +80,42 @@
|
|
* somewhat initialized; single_filed is set.
|
|
*/
|
|
|
|
+int
|
|
single_open( singlefile, flags, fh )
|
|
char *singlefile;
|
|
int flags;
|
|
struct FHeader *fh;
|
|
{
|
|
- int maxlen;
|
|
int rc;
|
|
|
|
- if ( flags == O_RDONLY ) {
|
|
+ if ( flags != O_RDONLY) return( -1 );
|
|
+
|
|
if ( strcmp( singlefile, STDIN ) == 0 ) {
|
|
- single.filed = fileno( stdin );
|
|
+ single.filed = fileno( stdin );
|
|
} else if (( single.filed = open( singlefile, flags )) < 0 ) {
|
|
- perror( singlefile );
|
|
- return( -1 );
|
|
- }
|
|
+ perror( singlefile );
|
|
+ return( -1 );
|
|
+ }
|
|
strncpy( single.path, singlefile, MAXPATHLEN );
|
|
#if DEBUG
|
|
fprintf( stderr, "opened %s for read\n", single.path );
|
|
#endif
|
|
if ((( rc = single_header_test()) > 0 ) &&
|
|
( single_header_read( fh, rc ) == 0 )) {
|
|
- return( 0 );
|
|
- }
|
|
- single_close( KEEP );
|
|
- return( -1 );
|
|
- }
|
|
+ return( 0 );
|
|
+ }
|
|
+ single_close( KEEP );
|
|
+ return( -1 );
|
|
+
|
|
}
|
|
-
|
|
-/*
|
|
+
|
|
+/*
|
|
* single_close must be called before a second file can be opened using
|
|
* single_open. Upon successful completion, a value of 0 is returned.
|
|
* Otherwise, a value of -1 is returned.
|
|
*/
|
|
|
|
+int
|
|
single_close( keepflag )
|
|
int keepflag;
|
|
{
|
|
@@ -132,6 +136,7 @@
|
|
* bytes of the other two forks can be read, as well.
|
|
*/
|
|
|
|
+int
|
|
single_header_read( fh, version )
|
|
struct FHeader *fh;
|
|
int version;
|
|
@@ -140,11 +145,11 @@
|
|
* entry_buf is used for reading in entry descriptors, and for reading in
|
|
* the actual entries of FILEINFO, FINDERINFO, and DATES.
|
|
*/
|
|
- u_char entry_buf[ 16 ];
|
|
- u_long entry_id;
|
|
- u_long time_seconds;
|
|
- u_short mask = 0xfcee;
|
|
- u_short num_entries;
|
|
+ u_int8_t entry_buf[ 16 ];
|
|
+ u_int32_t entry_id;
|
|
+ u_int32_t time_seconds;
|
|
+ u_int16_t mask = 0xfcee;
|
|
+ u_int16_t num_entries;
|
|
int n;
|
|
int readlen;
|
|
int date_entry;
|
|
@@ -160,7 +165,7 @@
|
|
single.entry[ n ].offset = 0;
|
|
single.entry[ n ].length = 0;
|
|
}
|
|
- bcopy( (char *)&header_buf[ 24 ], (char *)&num_entries,
|
|
+ memcpy( (char *)&num_entries, (char *)&header_buf[ 24 ],
|
|
sizeof( num_entries ));
|
|
num_entries = ntohs( num_entries );
|
|
#if DEBUG >= 2
|
|
@@ -172,15 +177,15 @@
|
|
perror( "Premature end of file :" );
|
|
return( -1 );
|
|
}
|
|
- bcopy( (char *)entry_buf, (char *)&entry_id, sizeof( entry_id ));
|
|
+ memcpy( (char *)&entry_id, (char *)entry_buf, sizeof( entry_id ));
|
|
entry_id = ntohl( entry_id );
|
|
- bcopy( (char *)&entry_buf[ 4 ],
|
|
- (char *)&single.entry[ entry_id ].offset,
|
|
+ memcpy( (char *)&single.entry[ entry_id ].offset,
|
|
+ (char *)&entry_buf[ 4 ],
|
|
sizeof( single.entry[ entry_id ].offset ));
|
|
single.entry[ entry_id ].offset =
|
|
ntohl( single.entry[ entry_id ].offset );
|
|
- bcopy( (char *)&entry_buf[ 8 ],
|
|
- (char *)&single.entry[ entry_id ].length,
|
|
+ memcpy( (char *)&single.entry[ entry_id ].length,
|
|
+ (char *)&entry_buf[ 8 ],
|
|
sizeof( single.entry[ entry_id ].length ));
|
|
single.entry[ entry_id ].length =
|
|
ntohl( single.entry[ entry_id ].length );
|
|
@@ -196,19 +201,11 @@
|
|
* it is a Macintosh file if dealing with version two format file.
|
|
*/
|
|
|
|
- if ( version == 1 ) {
|
|
- if ( single.entry[ ENTRYID_FILEINFO ].length > 0 ) {
|
|
- date_entry = ENTRYID_FILEINFO;
|
|
- } else {
|
|
- date_entry = 0;
|
|
- }
|
|
- } else if ( version == 2 ) {
|
|
- if ( single.entry[ ENTRYID_DATES ].length > 0 ) {
|
|
- date_entry = ENTRYID_DATES;
|
|
- } else {
|
|
- date_entry = 0;
|
|
- }
|
|
- }
|
|
+ date_entry = 0;
|
|
+ if ( version == 1 && single.entry[ ENTRYID_FILEINFO ].length > 0 )
|
|
+ date_entry = ENTRYID_FILEINFO;
|
|
+ else if ( version == 2 && single.entry[ ENTRYID_DATES ].length > 0 )
|
|
+ date_entry = ENTRYID_DATES;
|
|
#if DEBUG
|
|
fprintf( stderr, "date_entry = %d\n", date_entry );
|
|
#endif
|
|
@@ -245,21 +242,21 @@
|
|
perror( "Premature end of file :" );
|
|
return( -1 );
|
|
}
|
|
- bcopy( (char *)&entry_buf[ FINDERIOFF_TYPE ],
|
|
- (char *)&fh->finder_info.fdType,
|
|
+ memcpy( (char *)&fh->finder_info.fdType,
|
|
+ (char *)&entry_buf[ FINDERIOFF_TYPE ],
|
|
sizeof( fh->finder_info.fdType ));
|
|
- bcopy( (char *)&entry_buf[ FINDERIOFF_CREATOR ],
|
|
- (char *)&fh->finder_info.fdCreator,
|
|
+ memcpy( (char *)&fh->finder_info.fdCreator,
|
|
+ (char *)&entry_buf[ FINDERIOFF_CREATOR ],
|
|
sizeof( fh->finder_info.fdCreator ));
|
|
- bcopy( (char *)&entry_buf[ FINDERIOFF_FLAGS ],
|
|
- (char *)&fh->finder_info.fdFlags,
|
|
+ memcpy( (char *)&fh->finder_info.fdFlags,
|
|
+ (char *)&entry_buf[ FINDERIOFF_FLAGS ],
|
|
sizeof( fh->finder_info.fdFlags ));
|
|
fh->finder_info.fdFlags = fh->finder_info.fdFlags & mask;
|
|
- bcopy( (char *)&entry_buf[ FINDERIOFF_LOC ],
|
|
- (char *)&fh->finder_info.fdLocation,
|
|
+ memcpy( (char *)&fh->finder_info.fdLocation,
|
|
+ (char *)&entry_buf[ FINDERIOFF_LOC ],
|
|
sizeof( fh->finder_info.fdLocation ));
|
|
- bcopy( (char *)&entry_buf[ FINDERIOFF_FLDR ],
|
|
- (char *)&fh->finder_info.fdFldr,
|
|
+ memcpy( (char *)&fh->finder_info.fdFldr,
|
|
+ (char *)&entry_buf[ FINDERIOFF_FLDR ],
|
|
sizeof( fh->finder_info.fdFldr ));
|
|
#if DEBUG
|
|
{
|
|
@@ -298,9 +295,9 @@
|
|
} else {
|
|
time_seconds = htonl( time_seconds + TIME_DIFF );
|
|
}
|
|
- bcopy( (char *)&time_seconds, (char *)&fh->create_date,
|
|
+ memcpy( (char *)&fh->create_date, (char *)&time_seconds,
|
|
sizeof( fh->create_date ));
|
|
- bcopy( (char *)&time_seconds, (char *)&fh->mod_date,
|
|
+ memcpy( (char *)&fh->mod_date, (char *)&time_seconds,
|
|
sizeof( fh->mod_date ));
|
|
fh->backup_date = htonl( TIME_ZERO );
|
|
} else if ( single.entry[ date_entry ].length != 16 ) {
|
|
@@ -315,9 +312,9 @@
|
|
perror( "Premature end of file :" );
|
|
return( -1 );
|
|
}
|
|
- bcopy( (char *)&entry_buf[ 0 ], (char *)&fh->create_date,
|
|
+ memcpy( (char *)&fh->create_date, (char *)&entry_buf[ 0 ],
|
|
sizeof( fh->create_date ));
|
|
- bcopy( (char *)&entry_buf[ 4 ], (char *)&fh->mod_date,
|
|
+ memcpy( (char *)&fh->mod_date, (char *)&entry_buf[ 4 ],
|
|
sizeof( fh->mod_date ));
|
|
fh->backup_date = htonl( TIME_ZERO );
|
|
} else if ( date_entry == ENTRYID_DATES ) {
|
|
@@ -329,11 +326,11 @@
|
|
perror( "Premature end of file :" );
|
|
return( -1 );
|
|
}
|
|
- bcopy( (char *)&entry_buf[ 0 ], (char *)&fh->create_date,
|
|
+ memcpy( (char *)&fh->create_date, (char *)&entry_buf[ 0 ],
|
|
sizeof( fh->create_date ));
|
|
fh->create_date = htonl( time_seconds -
|
|
( 0L - ntohl( fh->create_date )));
|
|
- bcopy( (char *)&entry_buf[ 4 ], (char *)&fh->mod_date,
|
|
+ memcpy( (char *)&fh->mod_date, (char *)&entry_buf[ 4 ],
|
|
sizeof( fh->mod_date ));
|
|
fh->mod_date = htonl( time_seconds - ( 0L - ntohl( fh->mod_date )));
|
|
fh->backup_date = htonl( TIME_ZERO );
|
|
@@ -371,15 +368,13 @@
|
|
#define VERSIONONE 0x00010000L
|
|
#define VERSIONTWO 0x00020000L
|
|
#define MACINTOSH "Macintosh "
|
|
-u_char sixteennulls[] = { 0, 0, 0, 0, 0, 0, 0, 0,
|
|
+u_int8_t sixteennulls[] = { 0, 0, 0, 0, 0, 0, 0, 0,
|
|
0, 0, 0, 0, 0, 0, 0, 0 };
|
|
-
|
|
+int
|
|
single_header_test()
|
|
{
|
|
int cc;
|
|
- u_long templong;
|
|
- u_short header_crc;
|
|
- u_char namelen;
|
|
+ u_int32_t templong;
|
|
|
|
cc = read( single.filed, (char *)header_buf, sizeof( header_buf ));
|
|
if ( cc < sizeof( header_buf )) {
|
|
@@ -387,17 +382,17 @@
|
|
return( -1 );
|
|
}
|
|
|
|
- bcopy( (char *)&header_buf[ 0 ], (char *)&templong, sizeof( templong ));
|
|
+ memcpy( (char *)&templong, (char *)&header_buf[ 0 ], sizeof( templong ));
|
|
if ( ntohl( templong ) != ASMAGIC ) {
|
|
fprintf( stderr, "%s is not an AppleSingle file.\n", single.path );
|
|
return( -1 );
|
|
}
|
|
|
|
- bcopy( (char *)&header_buf[ 4 ], (char *)&templong, sizeof( templong ));
|
|
+ memcpy( (char *)&templong, (char *)&header_buf[ 4 ], sizeof( templong ));
|
|
templong = ntohl( templong );
|
|
if ( templong == VERSIONONE ) {
|
|
cc = 1;
|
|
- if ( bcmp( MACINTOSH, &header_buf[ 8 ], sizeof( MACINTOSH ) - 1 )
|
|
+ if ( memcmp( MACINTOSH, &header_buf[ 8 ], sizeof( MACINTOSH ) - 1 )
|
|
!= 0 ) {
|
|
fprintf( stderr, "%s is not a Macintosh AppleSingle file.\n",
|
|
single.path );
|
|
@@ -405,7 +400,7 @@
|
|
}
|
|
} else if ( templong == VERSIONTWO ) {
|
|
cc = 2;
|
|
- if ( bcmp( sixteennulls, &header_buf[ 8 ], sizeof( sixteennulls ))
|
|
+ if ( memcmp( sixteennulls, &header_buf[ 8 ], sizeof( sixteennulls ))
|
|
!= 0 ) {
|
|
fprintf( stderr,
|
|
"Warning: %s may be a corrupt AppleSingle file.\n",
|
|
@@ -429,12 +424,13 @@
|
|
*
|
|
*/
|
|
|
|
+int
|
|
single_read( fork, buffer, length )
|
|
int fork;
|
|
char *buffer;
|
|
int length;
|
|
{
|
|
- u_long entry_id;
|
|
+ u_int32_t entry_id;
|
|
char *buf_ptr;
|
|
int readlen;
|
|
int cc = 1;
|