]> arthur.barton.de Git - netatalk.git/blobdiff - bin/megatron/asingle.c
Merge master
[netatalk.git] / bin / megatron / asingle.c
index b9756e82e91dc43f6d2168a5b570f2b81bd3548e..73e4ffaaff1022e6bc60a160ae2d550338b56d17 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: asingle.c,v 1.12 2009-10-13 22:55:36 didg Exp $
+ * $Id: asingle.c,v 1.14 2010-01-27 21:27:53 didg Exp $
  */
 
 #ifdef HAVE_CONFIG_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 <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"
        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
@@ -118,7 +115,7 @@ int single_header_read( struct FHeader *fh, int version)
  * 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_char             entry_buf[ADEDLEN_FINDERI];
     u_int32_t          entry_id;
     u_int32_t          time_seconds;
     u_short            mask = 0xfcee;
@@ -204,15 +201,14 @@ int single_header_read( struct FHeader *fh, int version)
            return( -1 );
        }
     }
-    if (( single.entry[ ADEID_FINDERI ].ade_len < 16 ) ||
+    if (( single.entry[ ADEID_FINDERI ].ade_len < ADEDLEN_FINDERI ) ||
            ( single.entry[ ADEID_FINDERI ].ade_off <= AD_HEADER_LEN )) {
        fprintf( stderr, "%s has bogus FinderInfo.\n", single.path );
        return( -1 );
     } else {
        pos = lseek( single.filed,
                single.entry[ ADEID_FINDERI ].ade_off, SEEK_SET );
-       if ( read( single.filed, (char *)entry_buf, sizeof( entry_buf )) !=
-               sizeof( entry_buf )) {
+       if ( read( single.filed, (char *)entry_buf, ADEDLEN_FINDERI) != ADEDLEN_FINDERI) {
            perror( "Premature end of file :" );
            return( -1 );
        }
@@ -333,7 +329,7 @@ int single_header_read( struct FHeader *fh, int 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)
@@ -389,12 +385,12 @@ int single_header_test(void)
  *
  */
 
-int single_read( int fork, char *buffer, u_int32_t 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 ) {
@@ -409,9 +405,9 @@ int single_read( int fork, char *buffer, u_int32_t length)
            break;
     }
 
-    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 > 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 ) {