]> arthur.barton.de Git - netatalk.git/blobdiff - bin/megatron/hqx.c
Use correct member of forklen array, from Olaf Hering
[netatalk.git] / bin / megatron / hqx.c
index 2b4e3952d16062d77b461e6ce5521d19af4d60dc..3f0406d55ade78b48eb394a5e24dff28b45e8787 100644 (file)
@@ -1,32 +1,35 @@
 /*
- * $Id: hqx.c,v 1.6 2001-05-01 13:58:43 srittau Exp $
+ * $Id: hqx.c,v 1.14 2005-04-28 20:49:19 bfernhomberg Exp $
  */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#endif /* HAVE_CONFIG_H */
 
-#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <sys/time.h>
 #include <sys/param.h>
-#ifdef notdef
-#if BSD >= 199006
-# include <machine/endian.h>
-#else
-# include <netinet/in.h>
-#endif
-#endif notdef
-#include <time.h>
-#include <fcntl.h>
+
 #include <string.h>
-#include <syslog.h>
 #include <ctype.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include <unistd.h>
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif /* HAVE_FCNTL_H */
+
+#include <netinet/in.h>
+
 #include <atalk/adouble.h>
 #include <netatalk/endian.h>
+
 #include "megatron.h"
+#include "nad.h"
+#include "hqx.h"
 
 #define HEXOUTPUT      0
 
@@ -35,7 +38,7 @@
  */
 #ifndef        STDIN
 #      define  STDIN   "-"
-#endif
+#endif /* ! STDIN */
 
 /*     Yes and no
  */
@@ -75,7 +78,7 @@ int hqx7_fill(u_char *hqx7_ptr);
 
 #if HEXOUTPUT
 FILE           *rawhex, *expandhex;
-#endif
+#endif /* HEXOUTPUT */
 
 struct hqx_file_data {
     u_int32_t          forklen[ NUMFORKS ];
@@ -107,13 +110,14 @@ int hqx_open( hqxfile, flags, fh, options )
 
 #if DEBUG
     fprintf( stderr, "megatron: entering hqx_open\n" );
-#endif
+#endif /* DEBUG */
+    select_charset( options);
     if ( flags == O_RDONLY ) {
 
 #if HEXOUTPUT
        rawhex = fopen( "rawhex.unhex", "w" );
        expandhex = fopen( "expandhex.unhex", "w" );
-#endif
+#endif /* HEXOUTPUT */
 
        first_flag = 0;
 
@@ -129,9 +133,9 @@ int hqx_open( hqxfile, flags, fh, options )
 #if DEBUG
                off_t   pos;
 
-               pos = lseek( hqx.filed, 0, L_INCR );
+               pos = lseek( hqx.filed, 0, SEEK_CUR );
                fprintf( stderr, "megatron: current position is %ld\n", pos );
-#endif
+#endif /* DEBUG */
                return( 0 );
            }
        }
@@ -196,16 +200,16 @@ int hqx_read( fork, buffer, length )
 #if DEBUG >= 3
     {
        off_t   pos;
-       pos = lseek( hqx.filed, 0, L_INCR );
+       pos = lseek( hqx.filed, 0, SEEK_CUR );
        fprintf( stderr, "hqx_read: current position is %ld\n", pos );
     }
     fprintf( stderr, "hqx_read: fork is %s\n", forkname[ fork ] );
     fprintf( stderr, "hqx_read: remaining length is %d\n", hqx.forklen[fork] );
-#endif
+#endif /* DEBUG >= 3 */
 
-    if ( hqx.forklen[ fork ] < 0 ) {
-       fprintf( stderr, "This should never happen, dude!\n" );
-       return( hqx.forklen[ fork ] );
+    if (hqx.forklen[fork] > length) {
+       fprintf(stderr, "This should never happen, dude! length %d, fork length == %u\n", length, hqx.forklen[fork]);
+       return hqx.forklen[fork];
     }
 
     if ( hqx.forklen[ fork ] == 0 ) {
@@ -215,7 +219,7 @@ int hqx_read( fork, buffer, length )
 #if DEBUG >= 4
     fprintf( stderr, "hqx_read: storedcrc\t\t%x\n", storedcrc );
     fprintf( stderr, "hqx_read: observed crc\t\t%x\n\n", hqx.forkcrc[fork] );
-#endif
+#endif /* DEBUG >= 4 */
            if ( storedcrc == hqx.forkcrc[ fork ] ) {
                return( 0 );
            }
@@ -232,7 +236,7 @@ int hqx_read( fork, buffer, length )
     }
 #if DEBUG >= 3
     fprintf( stderr, "hqx_read: readlen is %d\n", readlen );
-#endif
+#endif /* DEBUG >= 3 */
 
     cc = hqx_7tobin( buffer, readlen );
     if ( cc > 0 ) {
@@ -242,7 +246,7 @@ int hqx_read( fork, buffer, length )
     }
 #if DEBUG >= 3
     fprintf( stderr, "hqx_read: chars read is %d\n", cc );
-#endif
+#endif /* DEBUG >= 3 */
     return( cc );
 }
 
@@ -266,7 +270,7 @@ int hqx_header_read( fh )
 #if HEXOUTPUT
     int                headerfork;
     headerfork = open( "headerfork", O_WRONLY|O_CREAT, 0622 );
-#endif
+#endif /* HEXOUTPUT */
 
     mask = htons( 0xfcee );
     hqx.headercrc = 0;
@@ -280,7 +284,7 @@ int hqx_header_read( fh )
 
 #if HEXOUTPUT
     write( headerfork, &namelen, sizeof( namelen ));
-#endif
+#endif /* HEXOUTPUT */
 
     if (( headerbuf = 
            (char *)malloc( (unsigned int)( namelen + BHH_HEADSIZ ))) == 0 ) {
@@ -297,7 +301,7 @@ int hqx_header_read( fh )
 
 #if HEXOUTPUT
     write( headerfork, headerbuf, ( namelen + BHH_HEADSIZ ));
-#endif
+#endif /* HEXOUTPUT */
 
 /*
  * stuff from the hqx file header
@@ -351,7 +355,7 @@ int hqx_header_read( fh )
        fprintf( stderr, "observed crc\t\t%x\n", hqx.headercrc );
        fprintf( stderr, "\n" );
     }
-#endif
+#endif /* DEBUG >= 5 */
 
 /*
  * create and modify times are figured from right now
@@ -389,7 +393,7 @@ int hqx_header_read( fh )
  */
 
 int hqx_header_write( fh )
-    struct FHeader     *fh;
+    struct FHeader     *fh _U_;
 {
     return( -1 );
 }
@@ -592,7 +596,7 @@ int hqx_7tobin( outbuf, datalen )
 #if DEBUG
     fprintf( stderr, "hqx_7tobin: datalen entering %d\n", datalen );
     fprintf( stderr, "hqx_7tobin: hqx8i entering %d\n", hqx8i );
-#endif
+#endif /* DEBUG */
 
     if ( first_flag == 0 ) {
        prev_hqx8 = 0;
@@ -605,7 +609,7 @@ int hqx_7tobin( outbuf, datalen )
 
 #if DEBUG
     fprintf( stderr, "hqx_7tobin: hqx8i entering %d\n", hqx8i );
-#endif
+#endif /* DEBUG */
 
     out_first = outbuf;
     out_last = out_first + datalen;
@@ -665,14 +669,14 @@ int hqx_7tobin( outbuf, datalen )
 #if HEXOUTPUT
            putc( hqx8i, rawhex );
             putc( hqx8[ hqx8i ], rawhex );
-#endif
+#endif /* HEXOUTPUT */
 
            if ( prev_hqx8 == RUNCHAR ) {
                if ( hqx8[ hqx8i ] == 0 ) {
                    *out_first = prev_hqx8;
 #if HEXOUTPUT
                    putc( *out_first, expandhex );
-#endif
+#endif /* HEXOUTPUT */
                    prev_out = prev_hqx8;
                    out_first++;
                }
@@ -680,7 +684,7 @@ int hqx_7tobin( outbuf, datalen )
                    *out_first = prev_out;
 #if HEXOUTPUT
                    putc( *out_first, expandhex );
-#endif
+#endif /* HEXOUTPUT */
                    hqx8[ hqx8i ]--;
                    out_first++;
                }
@@ -696,7 +700,7 @@ int hqx_7tobin( outbuf, datalen )
                *out_first = prev_hqx8;
 #if HEXOUTPUT
                putc( *out_first, expandhex );
-#endif
+#endif /* HEXOUTPUT */
                prev_out = prev_hqx8;
                out_first++;
            }