]> arthur.barton.de Git - netatalk.git/blobdiff - bin/megatron/asingle.c
Ignore object files
[netatalk.git] / bin / megatron / asingle.c
index d9e728053d1f40d34ed4b1eec042a7c85801a717..60c754f0ac8fae5a6acd4679c806b8e6f7352007 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: asingle.c,v 1.8 2002-02-16 17:12:53 srittau Exp $
+ * $Id: asingle.c,v 1.14 2010-01-27 21:27:53 didg Exp $
  */
 
 #ifdef HAVE_CONFIG_H
        following globals; therefore this module can only be used
        for one of the two functions at a time.
  */
-struct single_file_data {
+static struct single_file_data {
     int                        filed;
     char               path[ MAXPATHLEN + 1];
     struct ad_entry    entry[ ADEID_MAX ];
 }              single;
 
 extern char    *forkname[];
-u_char         header_buf[ AD_HEADER_LEN ];
+static u_char  header_buf[ AD_HEADER_LEN ];
 
 /* 
  * single_open must be called first.  pass it a filename that is supposed
@@ -62,10 +62,7 @@ u_char               header_buf[ AD_HEADER_LEN ];
  * somewhat initialized; single_filed is set.
  */
 
-int single_open( singlefile, flags, fh, options )
-    char               *singlefile;
-    int                        flags, options;
-    struct FHeader     *fh;
+int single_open(char *singlefile, int flags, struct FHeader *fh, int options _U_)
 {
     int                        rc;
 
@@ -96,8 +93,7 @@ int single_open( singlefile, flags, fh, options )
  * Otherwise, a value of -1 is returned.
  */
 
-int single_close( keepflag )
-    int                        keepflag;
+int single_close( int keepflag)
 {
     if ( keepflag == KEEP ) {
        return( close( single.filed ));
@@ -116,9 +112,7 @@ int single_close( keepflag )
  * bytes of the other two forks can be read, as well.
  */
 
-int single_header_read( fh, version )
-    struct FHeader     *fh;
-    int                        version;
+int single_header_read( struct FHeader *fh, int version)
 {
 /*
  * entry_buf is used for reading in entry descriptors, and for reading in
@@ -131,7 +125,7 @@ int single_header_read( fh, version )
     u_short            num_entries;
     int                        n;
     int                        readlen;
-    int                        date_entry;
+    int                        date_entry = 0;
     off_t              pos;
 
 /*
@@ -180,17 +174,11 @@ int 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 );
@@ -274,7 +262,7 @@ int 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);
@@ -316,9 +304,9 @@ int 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 ) {
@@ -345,16 +333,16 @@ int single_header_read( fh, version )
  * "Macintosh       " (that is seven blanks of padding).
  */
 #define MACINTOSH      "Macintosh       "
-u_char         sixteennulls[] = { 0, 0, 0, 0, 0, 0, 0, 0,
+static u_char          sixteennulls[] = { 0, 0, 0, 0, 0, 0, 0, 0,
                                    0, 0, 0, 0, 0, 0, 0, 0 };
 
 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 );
     }
@@ -401,15 +389,12 @@ int single_header_test(void)
  *
  */
 
-int single_read( fork, buffer, length )
-    int                        fork;
-    char               *buffer;
-    int                        length;
+ssize_t single_read( int fork, char *buffer, size_t length)
 {
     u_int32_t          entry_id;
     char               *buf_ptr;
-    int                        readlen;
-    int                        cc = 1;
+    size_t             readlen;
+    ssize_t            cc = 1;
     off_t              pos;
 
     switch ( fork ) {
@@ -424,9 +409,9 @@ int 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 > 0x7FFFFFFF) {
+       fprintf(stderr, "single_read: Trying to read past end of fork!, ade_len == %u\n", single.entry[entry_id].ade_len);
+       return -1;
     }
     if ( single.entry[ entry_id ].ade_len == 0 ) {
        if ( fork == DATA ) {