]> arthur.barton.de Git - netatalk.git/blobdiff - bin/megatron/asingle.c
Use correct member of forklen array, from Olaf Hering
[netatalk.git] / bin / megatron / asingle.c
index a27ae34d573b714e0cbdd05c17406813049d70ba..818c198aead473077679ce45cb0f895762e0720d 100644 (file)
@@ -1,19 +1,28 @@
+/*
+ * $Id: asingle.c,v 1.11 2006-02-26 22:45:05 didg Exp $
+ */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#endif /* HAVE_CONFIG_H */
 
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <sys/time.h>
 #include <sys/param.h>
+#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
+#endif /* HAVE_FCNTL_H */
+#include <time.h>
 #include <string.h>
-#include <syslog.h>
 #include <ctype.h>
 #include <stdio.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif /* HAVE_UNISTD_H */
 #include <atalk/adouble.h>
 #include <netatalk/endian.h>
+#include "asingle.h"
 #include "megatron.h"
 
 /*     String used to indicate standard input instead of a disk
@@ -53,9 +62,9 @@ u_char                header_buf[ AD_HEADER_LEN ];
  * somewhat initialized; single_filed is set.
  */
 
-single_open( singlefile, flags, fh, options )
+int single_open( singlefile, flags, fh, options )
     char               *singlefile;
-    int                        flags, options;
+    int                        flags, options _U_;
     struct FHeader     *fh;
 {
     int                        rc;
@@ -70,7 +79,7 @@ single_open( singlefile, flags, fh, options )
        strncpy( single.path, singlefile, MAXPATHLEN );
 #if DEBUG
        fprintf( stderr, "opened %s for read\n", single.path );
-#endif
+#endif /* DEBUG */
        if ((( rc = single_header_test()) > 0 ) && 
                ( single_header_read( fh, rc ) == 0 )) {
            return( 0 );
@@ -78,6 +87,7 @@ single_open( singlefile, flags, fh, options )
        single_close( KEEP );
        return( -1 );
     }
+    return( 0 );
 }
 
 /* 
@@ -86,7 +96,7 @@ single_open( singlefile, flags, fh, options )
  * Otherwise, a value of -1 is returned.
  */
 
-single_close( keepflag )
+int single_close( keepflag )
     int                        keepflag;
 {
     if ( keepflag == KEEP ) {
@@ -106,7 +116,7 @@ single_close( keepflag )
  * bytes of the other two forks can be read, as well.
  */
 
-single_header_read( fh, version )
+int single_header_read( fh, version )
     struct FHeader     *fh;
     int                        version;
 {
@@ -121,7 +131,7 @@ single_header_read( fh, version )
     u_short            num_entries;
     int                        n;
     int                        readlen;
-    int                        date_entry;
+    int                        date_entry = 0;
     off_t              pos;
 
 /*
@@ -138,7 +148,7 @@ single_header_read( fh, version )
     num_entries = ntohs( num_entries );
 #if DEBUG >= 2
     fprintf( stderr, "The number of entries is %d\n", num_entries );
-#endif
+#endif /* DEBUG */
     for ( ; num_entries > 0 ; num_entries-- ) {
        if ( read( single.filed, (char *)entry_buf, AD_ENTRY_LEN )
                != AD_ENTRY_LEN ) {
@@ -161,7 +171,7 @@ single_header_read( fh, version )
        fprintf( stderr, "entry_id\t%d\n", entry_id );
        fprintf( stderr, "\toffset\t\t%d\n", single.entry[ entry_id ].ade_off );
        fprintf( stderr, "\tlength\t\t%d\n", single.entry[ entry_id ].ade_len );
-#endif
+#endif /* DEBUG */
     }
 
 /*
@@ -170,21 +180,15 @@ single_header_read( fh, version )
  */
 
     if ( version == 1 ) {
-       if ( single.entry[ ADEID_FILEI ].ade_len > 0 ) {
+       if ( single.entry[ ADEID_FILEI ].ade_len > 0 )
            date_entry = ADEID_FILEI;
-       } else {
-           date_entry = 0;
-       }
     } else if ( version == 2 ) {
-       if ( single.entry[ ADEID_FILEDATESI ].ade_len > 0 ) {
+       if ( single.entry[ ADEID_FILEDATESI ].ade_len > 0 )
            date_entry = ADEID_FILEDATESI;
-       } else {
-           date_entry = 0;
-       }
     }
 #if DEBUG
     fprintf( stderr, "date_entry = %d\n", date_entry );
-#endif
+#endif /* DEBUG */
 
 /*
  * Go through and copy all the information you can get from 
@@ -242,7 +246,7 @@ single_header_read( fh, version )
            type[4] = creator[4] = '\0';
            fprintf( stderr, "type is %s, creator is %s\n", type, creator );
        }
-#endif
+#endif /* DEBUG */
     }
     if (( single.entry[ ADEID_COMMENT ].ade_len == 0 ) || 
            ( single.entry[ ADEID_COMMENT ].ade_off <= AD_HEADER_LEN )) {
@@ -264,7 +268,7 @@ single_header_read( fh, version )
  * Unless I can't get the current date, in which case use time zero.
  */
     if (( date_entry < 7 ) || ( date_entry > 8 )) {
-       if (( time_seconds = time( NULL )) == -1 ) {
+       if (( time_seconds = time( NULL )) == (u_int32_t)-1 ) {
            time_seconds = AD_DATE_START;
        } else {
            time_seconds = AD_DATE_FROM_UNIX(time_seconds);
@@ -306,9 +310,9 @@ single_header_read( fh, version )
                sizeof(fh->backup_date));
     }
     if ( single.entry[ ADEID_RFORK ].ade_off == 0 ) {
-       fh->forklen[ ADEID_RFORK ] = 0;
+       fh->forklen[RESOURCE] = 0;
     } else {
-       fh->forklen[ ADEID_RFORK ] =
+       fh->forklen[RESOURCE] =
                htonl( single.entry[ ADEID_RFORK ].ade_len );
     }
     if ( single.entry[ ADEID_DFORK ].ade_off == 0 ) {
@@ -338,13 +342,13 @@ single_header_read( fh, version )
 u_char         sixteennulls[] = { 0, 0, 0, 0, 0, 0, 0, 0,
                                    0, 0, 0, 0, 0, 0, 0, 0 };
 
-single_header_test()
+int single_header_test(void)
 {
-    int                        cc;
+    ssize_t            cc;
     u_int32_t          templong;
 
     cc = read( single.filed, (char *)header_buf, sizeof( header_buf ));
-    if ( cc < sizeof( header_buf )) {
+    if ( cc < (ssize_t)sizeof( header_buf )) {
        perror( "Premature end of file :" );
        return( -1 );
     }
@@ -391,10 +395,10 @@ single_header_test()
  *
  */
 
-single_read( fork, buffer, length )
+int single_read( fork, buffer, length )
     int                        fork;
     char               *buffer;
-    int                        length;
+    u_int32_t          length;
 {
     u_int32_t          entry_id;
     char               *buf_ptr;
@@ -414,9 +418,9 @@ single_read( fork, buffer, length )
            break;
     }
 
-    if ( single.entry[ entry_id ].ade_len < 0 ) {
-       fprintf( stderr, "single_read: Trying to read past end of fork!\n" );
-       return( single.entry[ entry_id ].ade_len );
+    if (single.entry[entry_id].ade_len > length) {
+       fprintf(stderr, "single_read: Trying to read past end of fork!, length %d, ade_len == %u\n", length, single.entry[entry_id].ade_len);
+       return single.entry[entry_id].ade_len;
     }
     if ( single.entry[ entry_id ].ade_len == 0 ) {
        if ( fork == DATA ) {