ca76526b11
if it exists.
285 lines
10 KiB
Plaintext
285 lines
10 KiB
Plaintext
--- bin/megatron/nad.c.orig Sat Feb 17 09:40:32 1996
|
|
+++ bin/megatron/nad.c Thu Nov 11 17:45:21 1999
|
|
@@ -11,7 +11,8 @@
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
-#include <strings.h>
|
|
+#include <unistd.h>
|
|
+#include <string.h>
|
|
#include <syslog.h>
|
|
#include <dirent.h>
|
|
#include <fcntl.h>
|
|
@@ -22,6 +23,8 @@
|
|
|
|
static char hexdig[] = "0123456789abcdef";
|
|
|
|
+int nad_header_read(), nad_header_write();
|
|
+
|
|
char *mtoupath( mpath )
|
|
char *mpath;
|
|
{
|
|
@@ -61,6 +64,7 @@
|
|
struct adouble ad;
|
|
} nad;
|
|
|
|
+int
|
|
nad_open( path, openflags, fh )
|
|
char *path;
|
|
int openflags;
|
|
@@ -76,9 +80,10 @@
|
|
*/
|
|
|
|
if ( openflags == O_RDONLY ) {
|
|
- strcpy( nad.adpath[0], path );
|
|
- strcpy( nad.adpath[1],
|
|
- ad_path( nad.adpath[0], ADFLAGS_DF|ADFLAGS_HF ));
|
|
+ (void)strlcpy( nad.adpath[0], path, sizeof (nad.adpath[0]) );
|
|
+ (void)strlcpy( nad.adpath[1],
|
|
+ ad_path( nad.adpath[0], ADFLAGS_DF|ADFLAGS_HF ),
|
|
+ sizeof(nad.adpath[1]));
|
|
for ( fork = 0 ; fork < NUMFORKS ; fork++ ) {
|
|
if ( stat( nad.adpath[ fork ], &st ) < 0 ) {
|
|
if ( errno == ENOENT ) {
|
|
@@ -102,10 +107,12 @@
|
|
return( nad_header_read( fh ));
|
|
|
|
} else {
|
|
- strcpy( nad.macname, fh->name );
|
|
- strcpy( nad.adpath[0], mtoupath( nad.macname ));
|
|
- strcpy( nad.adpath[1],
|
|
- ad_path( nad.adpath[0], ADFLAGS_DF|ADFLAGS_HF ));
|
|
+ (void)strlcpy( nad.macname, fh->name, sizeof(nad.macname) );
|
|
+ (void)strlcpy( nad.adpath[0], mtoupath( nad.macname ),
|
|
+ sizeof(nad.adpath[0]));
|
|
+ (void)strlcpy( nad.adpath[1],
|
|
+ ad_path( nad.adpath[0], ADFLAGS_DF|ADFLAGS_HF ),
|
|
+ sizeof(nad.adpath[0]));
|
|
#if DEBUG
|
|
fprintf(stderr, "%s\n", nad.macname);
|
|
fprintf(stderr, "%s is adpath[0]\n", nad.adpath[0]);
|
|
@@ -125,16 +132,17 @@
|
|
}
|
|
}
|
|
|
|
+int
|
|
nad_header_read( fh )
|
|
struct FHeader *fh;
|
|
{
|
|
- long temptime;
|
|
+ int32_t temptime;
|
|
struct stat st;
|
|
|
|
- bcopy( ad_entry( &nad.ad, ADEID_NAME ), nad.macname,
|
|
+ memcpy( nad.macname, ad_entry( &nad.ad, ADEID_NAME ),
|
|
ad_getentrylen( &nad.ad, ADEID_NAME ));
|
|
nad.macname[ ad_getentrylen( &nad.ad, ADEID_NAME ) ] = '\0';
|
|
- strcpy( fh->name, nad.macname );
|
|
+ (void)strlcpy( fh->name, nad.macname, sizeof(fh->name) );
|
|
if ( stat( nad.adpath[ DATA ], &st ) < 0 ) {
|
|
perror( "stat of datafork failed" );
|
|
return( -1 );
|
|
@@ -153,51 +161,51 @@
|
|
fprintf( stderr, "get info comment\t\t\"%s\"\n", fh->comment );
|
|
#endif
|
|
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_CREATE ), &temptime,
|
|
+ memcpy( &temptime, (ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_CREATE ),
|
|
sizeof( temptime ));
|
|
temptime = htonl( ntohl( temptime ) + TIME_DIFF );
|
|
- bcopy( &temptime, &fh->create_date, sizeof( temptime ));
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_MODIFY ), &temptime,
|
|
+ memcpy( &fh->create_date, &temptime, sizeof( temptime ));
|
|
+ memcpy( &temptime, (ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_MODIFY ),
|
|
sizeof( temptime ));
|
|
temptime = htonl( ntohl( temptime ) + TIME_DIFF );
|
|
- bcopy( &temptime, &fh->mod_date, sizeof( temptime ));
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_BACKUP ), &temptime,
|
|
+ memcpy( &fh->mod_date, &temptime, sizeof( temptime ));
|
|
+ memcpy( &temptime, (ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_BACKUP ),
|
|
sizeof( temptime ));
|
|
temptime = htonl( ntohl( temptime ) + TIME_DIFF );
|
|
- bcopy( &temptime, &fh->backup_date, sizeof( temptime ));
|
|
+ memcpy( &fh->backup_date, &temptime, sizeof( temptime ));
|
|
|
|
#if DEBUG
|
|
- bcopy( &fh->create_date, &temptime, sizeof( temptime ));
|
|
+ memcpy( &temptime, &fh->create_date, sizeof( temptime ));
|
|
temptime = ntohl( temptime );
|
|
fprintf( stderr, "create_date seconds\t\t%lu\n", temptime );
|
|
- bcopy( &fh->mod_date, &temptime, sizeof( temptime ));
|
|
+ memcpy( &temptime, &fh->mod_date, sizeof( temptime ));
|
|
temptime = ntohl( temptime );
|
|
fprintf( stderr, "mod_date seconds\t\t%lu\n", temptime );
|
|
- bcopy( &fh->backup_date, &temptime, sizeof( temptime ));
|
|
+ memcpy( &temptime, &fh->backup_date, sizeof( temptime ));
|
|
temptime = ntohl( temptime );
|
|
fprintf( stderr, "backup_date seconds\t\t%lu\n", temptime );
|
|
fprintf( stderr, "size of finder_info\t\t%d\n", sizeof( fh->finder_info ));
|
|
#endif
|
|
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_TYPE ),
|
|
- (char *)&fh->finder_info.fdType,
|
|
+ memcpy( (char *)&fh->finder_info.fdType,
|
|
+ (ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_TYPE ),
|
|
sizeof( fh->finder_info.fdType ));
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_CREATOR ),
|
|
- (char *)&fh->finder_info.fdCreator,
|
|
+ memcpy( (char *)&fh->finder_info.fdCreator,
|
|
+ (ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_CREATOR ),
|
|
sizeof( fh->finder_info.fdCreator ));
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_FLAGS ),
|
|
- (char *)&fh->finder_info.fdFlags,
|
|
+ memcpy( (char *)&fh->finder_info.fdFlags,
|
|
+ (ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_FLAGS ),
|
|
sizeof( fh->finder_info.fdFlags ));
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_LOC ),
|
|
- (char *)&fh->finder_info.fdLocation,
|
|
+ memcpy( (char *)&fh->finder_info.fdLocation,
|
|
+ (ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_LOC ),
|
|
sizeof( fh->finder_info.fdLocation ));
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_FLDR ),
|
|
- (char *)&fh->finder_info.fdFldr,
|
|
+ memcpy( (char *)&fh->finder_info.fdFldr,
|
|
+ (ad_entry( &nad.ad, ADEID_FINDERI ) + FINDERIOFF_FLDR ),
|
|
sizeof( fh->finder_info.fdFldr ));
|
|
|
|
#if DEBUG
|
|
{
|
|
- short flags;
|
|
+ int16_t flags;
|
|
fprintf( stderr, "finder_info.fdType\t\t%.*s\n",
|
|
sizeof( fh->finder_info.fdType ), &fh->finder_info.fdType );
|
|
fprintf( stderr, "finder_info.fdCreator\t\t%.*s\n",
|
|
@@ -207,9 +215,9 @@
|
|
sizeof( fh->finder_info.fdType ) +
|
|
sizeof( fh->finder_info.fdCreator ),
|
|
ad_entry( &nad.ad, ADEID_FINDERI ));
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FINDERI ) +
|
|
+ memcpy( &flags, (ad_entry( &nad.ad, ADEID_FINDERI ) +
|
|
sizeof( fh->finder_info.fdType ) +
|
|
- sizeof( fh->finder_info.fdCreator ) ), &flags, sizeof( flags ));
|
|
+ sizeof( fh->finder_info.fdCreator ) ), sizeof( flags ));
|
|
fprintf( stderr, "nad.ad flags\t\t\t%x\n", flags );
|
|
fprintf( stderr, "fh flags\t\t\t%x\n", fh->finder_info.fdFlags );
|
|
}
|
|
@@ -221,13 +229,14 @@
|
|
|
|
}
|
|
|
|
+int
|
|
nad_header_write( fh )
|
|
struct FHeader *fh;
|
|
{
|
|
- long temptime;
|
|
+ int32_t temptime;
|
|
|
|
ad_setentrylen( &nad.ad, ADEID_NAME, strlen( nad.macname ));
|
|
- bcopy( nad.macname, ad_entry( &nad.ad, ADEID_NAME ),
|
|
+ memcpy( ad_entry( &nad.ad, ADEID_NAME ), nad.macname,
|
|
ad_getentrylen( &nad.ad, ADEID_NAME ));
|
|
ad_setentrylen( &nad.ad, ADEID_RFORK, ntohl( fh->forklen[ RESOURCE ] ));
|
|
|
|
@@ -244,46 +253,46 @@
|
|
ad_entry( &nad.ad, ADEID_NAME ));
|
|
#endif
|
|
|
|
- bcopy( &fh->create_date, &temptime, sizeof( temptime ));
|
|
+ memcpy( &temptime, &fh->create_date, sizeof( temptime ));
|
|
temptime = htonl( ntohl( temptime ) - TIME_DIFF );
|
|
- bcopy( &temptime, ( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_CREATE ),
|
|
- sizeof( temptime ));
|
|
- bcopy( &fh->mod_date, &temptime, sizeof( temptime ));
|
|
+ memcpy( ( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_CREATE ),
|
|
+ &temptime, sizeof( temptime ));
|
|
+ memcpy( &temptime, &fh->mod_date, sizeof( temptime ));
|
|
temptime = htonl( ntohl( temptime ) - TIME_DIFF );
|
|
- bcopy( &temptime, ( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_MODIFY ),
|
|
- sizeof( temptime ));
|
|
+ memcpy( ( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_MODIFY ),
|
|
+ &temptime, sizeof( temptime ));
|
|
|
|
#if DEBUG
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_CREATE ),
|
|
- &temptime, sizeof( temptime ));
|
|
+ memcpy( &temptime, ( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_CREATE ),
|
|
+ sizeof( temptime ));
|
|
temptime = ntohl( temptime );
|
|
fprintf(stderr, "FILEIOFF_CREATE seconds\t\t%ld\n", temptime );
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_MODIFY ),
|
|
- &temptime, sizeof( temptime ));
|
|
+ memcpy( &temptime, ( ad_entry( &nad.ad, ADEID_FILEI ) + FILEIOFF_MODIFY ),
|
|
+ sizeof( temptime ));
|
|
temptime = ntohl( temptime );
|
|
fprintf(stderr, "FILEIOFF_MODIFY seconds\t\t%ld\n", temptime );
|
|
#endif
|
|
|
|
- bzero( ad_entry( &nad.ad, ADEID_FINDERI ), ADEDLEN_FINDERI );
|
|
- bcopy( (char *)&fh->finder_info.fdType,
|
|
- ad_entry( &nad.ad, ADEID_FINDERI ),
|
|
+ memset( ad_entry( &nad.ad, ADEID_FINDERI ), 0, ADEDLEN_FINDERI );
|
|
+ memcpy( ad_entry( &nad.ad, ADEID_FINDERI ),
|
|
+ (char *)&fh->finder_info.fdType,
|
|
sizeof( fh->finder_info.fdType ));
|
|
- bcopy( (char *)&fh->finder_info.fdCreator,
|
|
- ad_entry( &nad.ad, ADEID_FINDERI ) +
|
|
- sizeof( fh->finder_info.fdType ),
|
|
+ memcpy( ad_entry( &nad.ad, ADEID_FINDERI ) +
|
|
+ sizeof( fh->finder_info.fdType ),
|
|
+ (char *)&fh->finder_info.fdCreator,
|
|
sizeof( fh->finder_info.fdCreator ));
|
|
- bcopy( (char *)&fh->finder_info.fdFlags,
|
|
- ad_entry( &nad.ad, ADEID_FINDERI ) +
|
|
- sizeof( fh->finder_info.fdType ) +
|
|
- sizeof( fh->finder_info.fdCreator ),
|
|
+ memcpy( ad_entry( &nad.ad, ADEID_FINDERI ) +
|
|
+ sizeof( fh->finder_info.fdType ) +
|
|
+ sizeof( fh->finder_info.fdCreator ),
|
|
+ (char *)&fh->finder_info.fdFlags,
|
|
sizeof( fh->finder_info.fdFlags ));
|
|
|
|
#if DEBUG
|
|
{
|
|
- short flags;
|
|
- bcopy(( ad_entry( &nad.ad, ADEID_FINDERI ) +
|
|
+ int16_t flags;
|
|
+ memcpy(( &flags, ad_entry( &nad.ad, ADEID_FINDERI ) +
|
|
sizeof( fh->finder_info.fdType ) +
|
|
- sizeof( fh->finder_info.fdCreator ) ), &flags, sizeof( flags ));
|
|
+ sizeof( fh->finder_info.fdCreator ) ), sizeof( flags ));
|
|
fprintf( stderr, "nad.ad flags\t\t\t%x\n", flags );
|
|
fprintf( stderr, "fh flags\t\t\t%x\n", fh->finder_info.fdFlags );
|
|
fprintf( stderr, "type and creator\t\t%.*s\n\n",
|
|
@@ -306,6 +315,7 @@
|
|
|
|
int forkeid[] = { ADEID_DFORK, ADEID_RFORK };
|
|
|
|
+int
|
|
nad_read( fork, forkbuf, bufc )
|
|
int fork;
|
|
char *forkbuf;
|
|
@@ -331,6 +341,7 @@
|
|
return( cc );
|
|
}
|
|
|
|
+int
|
|
nad_write( fork, forkbuf, bufc )
|
|
int fork;
|
|
char *forkbuf;
|
|
@@ -366,6 +377,7 @@
|
|
return( bufc );
|
|
}
|
|
|
|
+int
|
|
nad_close( status )
|
|
int status;
|
|
{
|
|
@@ -387,5 +399,6 @@
|
|
perror ( nad.adpath[ 1 ] );
|
|
}
|
|
return( 0 );
|
|
- } else return( -1 );
|
|
+ }
|
|
+ return( -1 );
|
|
}
|