/*
- * $Id: macbin.c,v 1.11 2003-12-15 05:27:24 srittau Exp $
+ * $Id: macbin.c,v 1.12 2005-04-28 20:49:19 bfernhomberg Exp $
*/
#ifdef HAVE_CONFIG_H
/* call localtime so that we get the timezone offset */
bin.gmtoff = 0;
-#ifdef HAVE_STRUCT_TM_TM_GMTOFF
+#ifndef NO_STRUCT_TM_GMTOFF
time(&t);
tp = localtime(&t);
if (tp)
bin.gmtoff = tp->tm_gmtoff;
-#endif /* HAVE_STRUCT_TM_TM_GMTOFF */
+#endif /* ! NO_STRUCT_TM_GMTOFF */
if ( flags == O_RDONLY ) { /* input */
if ( strcmp( binfile, STDIN ) == 0 ) {
fprintf( stderr, "bin_read: remaining length is %d\n", bin.forklen[fork] );
#endif /* DEBUG >= 3 */
- if ( bin.forklen[ fork ] < 0 ) {
- fprintf( stderr, "This should never happen, dude!\n" );
- return( bin.forklen[ fork ] );
+ if (bin.forklen[fork] > length) {
+ fprintf(stderr, "This should never happen, dude! length %d, fork length == %u\n", length, bin.forklen[fork]);
+ return bin.forklen[fork];
}
if ( bin.forklen[ fork ] == 0 ) {
perror( "Couldn't write to macbinary file:" );
return( cc );
}
- bin.forklen[ fork ] -= length;
- if ( bin.forklen[ fork ] < 0 ) {
- fprintf( stderr, "This should never happen, dude!\n" );
- return( bin.forklen[ fork ] );
+ if (length > bin.forklen[fork]) {
+ fprintf(stderr, "This should never happen, dude! length %d, fork length %u\n", length, bin.forklen[fork]);
+ return bin.forklen[fork];
}
+ bin.forklen[fork] -= length;
+
/*
* add the padding at end of data and resource forks
*/
return -1;
/* macbinary forks aren't larger than 0x7FFFFF */
+ /* we allow forks to be larger, breaking the specs */
memcpy(&cc, head_buf + 83, sizeof(cc));
cc = ntohl(cc);
- if (cc > 0x7FFFFF)
+ if (cc > 0x7FFFFFFF)
return -1;
memcpy(&cc, head_buf + 87, sizeof(cc));
cc = ntohl(cc);
- if (cc > 0x7FFFFF)
+ if (cc > 0x7FFFFFFF)
return -1;