openbsd-ports/net/netatalk/patches/patch-binmegatron-macbinc

227 lines
7.5 KiB
Plaintext

--- bin/megatron/macbin.c.orig Sun Sep 27 01:15:08 1998
+++ bin/megatron/macbin.c Thu Nov 11 17:16:22 1999
@@ -4,7 +4,7 @@
#include <sys/param.h>
#include <fcntl.h>
#include <unistd.h>
-#include <strings.h>
+#include <string.h>
#include <syslog.h>
#include <ctype.h>
#include <stdio.h>
@@ -30,22 +30,24 @@
*/
#define HEADBUFSIZ 128
-u_short updcrc();
+u_int16_t updcrc();
char *mtoupath();
+int test_header();
+int bin_header_read(), bin_header_write();
/* Both input and output routines use this struct and the
following globals; therefore this module can only be used
for one of the two functions at a time.
*/
struct bin_file_data {
- long forklen[ NUMFORKS ];
+ int32_t forklen[ NUMFORKS ];
char path[ MAXPATHLEN ];
int filed;
- u_short headercrc;
+ u_int16_t headercrc;
} bin;
extern char *forkname[];
-u_char head_buf[HEADBUFSIZ];
+u_int8_t head_buf[HEADBUFSIZ];
/*
* bin_open must be called first. pass it a filename that is supposed
@@ -53,6 +55,7 @@
* somewhat initialized; bin_filed is set.
*/
+int
bin_open( binfile, flags, fh )
char *binfile;
int flags;
@@ -113,6 +116,7 @@
* Otherwise, a value of -1 is returned.
*/
+int
bin_close( keepflag )
int keepflag;
{
@@ -138,6 +142,7 @@
* return zero and no more than that.
*/
+int
bin_read( fork, buffer, length )
int fork;
char *buffer;
@@ -209,6 +214,7 @@
* bin_write
*/
+int
bin_write( fork, buffer, length )
int fork;
char *buffer;
@@ -218,7 +224,7 @@
int writelen;
int cc = 0;
off_t pos;
- u_char padchar = 0;
+ u_int8_t padchar = 0;
#if DEBUG >= 3
fprintf( stderr, "bin_write: fork is %s\n", forkname[ fork ] );
@@ -292,11 +298,12 @@
* of the bytes of the other two forks can be read, as well.
*/
+int
bin_header_read( fh, revision )
struct FHeader *fh;
int revision;
{
- u_short mask;
+ u_int16_t mask;
/*
* Set the appropriate finder flags mask for the type of macbinary
@@ -308,8 +315,8 @@
switch ( revision ) {
case 2 :
mask = htons( 0xfcee );
- bcopy( (char *)&head_buf[ 101 ],
- ((char *)&fh->finder_info.fdFlags) + 1, 1 );
+ memcpy( ((char *)&fh->finder_info.fdFlags) + 1,
+ (char *)&head_buf[ 101 ], 1 );
break;
case 1 :
mask = htons( 0xfc00 );
@@ -324,18 +331,18 @@
* MacBinary header into the fh struct. What fun!
*/
- bcopy( (char *)&head_buf[ 2 ], (char *)fh->name, head_buf[ 1 ] );
- bcopy( (char *)&head_buf[ 91 ], (char *)&fh->create_date, 4 );
- bcopy( (char *)&head_buf[ 95 ], (char *)&fh->mod_date, 4 );
+ memcpy( (char *)fh->name, (char *)&head_buf[ 2 ], head_buf[ 1 ] );
+ memcpy( (char *)&fh->create_date, (char *)&head_buf[ 91 ], 4 );
+ memcpy( (char *)&fh->mod_date, (char *)&head_buf[ 95 ], 4 );
fh->backup_date = 0;
- bcopy( (char *)&head_buf[ 65 ], (char *)&fh->finder_info, 8 );
- bcopy( (char *)&head_buf[ 73 ], (char *)&fh->finder_info.fdFlags, 1 );
+ memcpy( (char *)&fh->finder_info, (char *)&head_buf[ 65 ], 8 );
+ memcpy( (char *)&fh->finder_info.fdFlags, (char *)&head_buf[ 73 ], 1 );
fh->finder_info.fdFlags = fh->finder_info.fdFlags & mask;
- bcopy( (char *)&head_buf[ 75 ], (char *)&fh->finder_info.fdLocation, 4 );
- bcopy( (char *)&head_buf[ 79 ], (char *)&fh->finder_info.fdFldr, 2 );
- bcopy( (char *)&head_buf[ 83 ], (char *)&fh->forklen[ DATA ], 4 );
+ memcpy( (char *)&fh->finder_info.fdLocation, (char *)&head_buf[ 75 ], 4 );
+ memcpy( (char *)&fh->finder_info.fdFldr, (char *)&head_buf[ 79 ], 2 );
+ memcpy( (char *)&fh->forklen[ DATA ], (char *)&head_buf[ 83 ], 4 );
bin.forklen[ DATA ] = ntohl( fh->forklen[ DATA ] );
- bcopy( (char *)&head_buf[ 87 ], (char *)&fh->forklen[ RESOURCE ], 4 );
+ memcpy( (char *)&fh->forklen[ RESOURCE ], (char *)&head_buf[ 87 ], 4 );
bin.forklen[ RESOURCE ] = ntohl( fh->forklen[ RESOURCE ] );
fh->comment[0] = '\0';
@@ -352,7 +359,7 @@
fprintf( stderr, "creator\t\t\t%.*s\n",
sizeof( fh->finder_info.fdCreator ),
&fh->finder_info.fdCreator );
- bcopy( (char *)&fh->finder_info.fdFlags, (char *)&flags,
+ memcpy( (char *)&flags, (char *)&fh->finder_info.fdFlags,
sizeof( flags ));
flags = ntohs( flags );
fprintf( stderr, "flags\t\t\t%x\n", flags );
@@ -372,6 +379,7 @@
* bin_header_write and bin_header_read are opposites.
*/
+int
bin_header_write( fh )
struct FHeader *fh;
{
@@ -379,24 +387,24 @@
int wc;
int wr;
- bzero( (char *)head_buf, sizeof( head_buf ));
- head_buf[ 1 ] = (u_char)strlen( fh->name );
- bcopy( (char *)fh->name, (char *)&head_buf[ 2 ], head_buf[ 1 ] );
- bcopy( (char *)&fh->finder_info, (char *)&head_buf[ 65 ], 8 );
- bcopy( (char *)&fh->finder_info.fdFlags, (char *)&head_buf[ 73 ], 1 );
- bcopy( (char *)&fh->finder_info.fdLocation, (char *)&head_buf[ 75 ], 4 );
- bcopy( (char *)&fh->finder_info.fdFldr, (char *)&head_buf[ 79 ], 2 );
- bcopy( (char *)&fh->forklen[ DATA ], (char *)&head_buf[ 83 ], 4 );
- bcopy( (char *)&fh->forklen[ RESOURCE ], (char *)&head_buf[ 87 ], 4 );
- bcopy( (char *)&fh->create_date, (char *)&head_buf[ 91 ], 4 );
- bcopy( (char *)&fh->mod_date, (char *)&head_buf[ 95 ], 4 );
- bcopy( ((char *)&fh->finder_info.fdFlags) + 1,
- (char *)&head_buf[ 101 ], 1 );
+ memset( (char *)head_buf, 0, sizeof( head_buf ));
+ head_buf[ 1 ] = (u_int8_t)strlen( fh->name );
+ memcpy( (char *)&head_buf[ 2 ], (char *)fh->name, head_buf[ 1 ] );
+ memcpy( (char *)&head_buf[ 65 ], (char *)&fh->finder_info, 8 );
+ memcpy( (char *)&head_buf[ 73 ], (char *)&fh->finder_info.fdFlags, 1 );
+ memcpy( (char *)&head_buf[ 75 ], (char *)&fh->finder_info.fdLocation, 4 );
+ memcpy( (char *)&head_buf[ 79 ], (char *)&fh->finder_info.fdFldr, 2 );
+ memcpy( (char *)&head_buf[ 83 ], (char *)&fh->forklen[ DATA ], 4 );
+ memcpy( (char *)&head_buf[ 87 ], (char *)&fh->forklen[ RESOURCE ], 4 );
+ memcpy( (char *)&head_buf[ 91 ], (char *)&fh->create_date, 4 );
+ memcpy( (char *)&head_buf[ 95 ], (char *)&fh->mod_date, 4 );
+ memcpy( (char *)&head_buf[ 101 ], ((char *)&fh->finder_info.fdFlags) + 1,
+ 1 );
head_buf[ 122 ] = 129;
head_buf[ 123 ] = 129;
- bin.headercrc = htons( updcrc( (u_short) 0, head_buf, 124 ));
- bcopy( (char *)&bin.headercrc, (char *)&head_buf[ 124 ],
+ bin.headercrc = htons( updcrc( (u_int16_t) 0, head_buf, 124 ));
+ memcpy( (char *)&head_buf[ 124 ], (char *)&bin.headercrc,
sizeof( bin.headercrc ));
bin.forklen[ DATA ] = ntohl( fh->forklen[ DATA ] );
@@ -444,11 +452,12 @@
* and bytes 101 through 125 are all zero, then the file is a MacBinary.
*/
+int
test_header()
{
int cc;
- u_short header_crc;
- u_char namelen;
+ u_int16_t header_crc;
+ u_int8_t namelen;
#if DEBUG
fprintf( stderr, "entering test_header\n" );
@@ -472,8 +481,8 @@
fprintf( stderr, "byte 0 and 74 are both zero\n" );
#endif
- bin.headercrc = updcrc( (u_short) 0, head_buf, 124 );
- bcopy( &head_buf[ 124 ], (char *)&header_crc, sizeof( header_crc ));
+ bin.headercrc = updcrc( (u_int16_t) 0, head_buf, 124 );
+ memcpy( (char *)&header_crc, &head_buf[ 124 ], sizeof( header_crc ));
header_crc = ntohs( header_crc );
if ( header_crc == bin.headercrc ) {
return( 2 );
@@ -486,7 +495,7 @@
if ( head_buf[ 82 ] != 0 ) {
return( -1 );
}
- bcopy( &head_buf[ 1 ], (char *)&namelen, sizeof( namelen ));
+ memcpy( (char *)&namelen, &head_buf[ 1 ], sizeof( namelen ));
#if DEBUG
fprintf( stderr, "name length is %d\n", namelen );
#endif