home *** CD-ROM | disk | FTP | other *** search
-
- /* u4write.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved. */
-
- #include "p4misc.h"
- #include "d4all.h"
- #include "u4error.h"
-
- #ifndef UNIX
- #include <io.h>
- #endif
-
- static int hand ;
- static unsigned int len_buffer, tot_len_buffer ;
- static unsigned int bytes_avail ; /* Write- # of bytes left in the buffer */
-
- static char H_PTR buffer ;
-
- int u4write( char H_PTR ptr, unsigned int len_ptr )
- {
- unsigned int first_len ;
- if ( len_buffer == 0 )
- {
- if ( u4huge_write( hand, ptr, (long) len_ptr ) < 0 )
- return -1 ;
- return 0 ;
- }
-
- if ( bytes_avail > 0 )
- {
- if ( bytes_avail >= len_ptr )
- {
- u4huge_cpy( buffer+ (len_buffer-bytes_avail), ptr, (long) len_ptr ) ;
- bytes_avail -= len_ptr ;
- return 0 ;
- }
- else
- {
- if ( u4write(ptr, first_len = bytes_avail) < 0) return -1 ;
- if ( u4write(ptr+first_len, len_ptr-first_len) < 0) return -1 ;
-
- return 0 ;
- }
- }
-
- /* bytes_avail is zero */
- if ( u4huge_write( hand, buffer, (long) len_buffer ) < 0 )
- return -1 ;
-
- bytes_avail = len_buffer = tot_len_buffer ;
-
- if ( u4write(ptr,len_ptr) < 0 ) return -1 ;
- return 0 ;
- }
-
- int u4write_flush()
- {
- if ( buffer == (char H_PTR) 0 || len_buffer == bytes_avail) return 0 ;
-
- if ( u4huge_write( hand, buffer, (long) len_buffer-bytes_avail ) < 0 )
- return -1 ;
-
- bytes_avail = len_buffer = tot_len_buffer ;
- return 0 ;
- }
-
-
- int u4write_init( int handle, char H_PTR ptr, unsigned int len_ptr,
- long start_offset )
- {
- len_ptr &= 0xFC00 ; /* Make it a multiple of 1K */
-
- if ( lseek( handle, start_offset, 0) != start_offset )
- {
- u4error( E_LSEEK, (char *) 0 ) ;
- return -1 ;
- }
-
- hand = handle ;
- buffer= ptr ;
- tot_len_buffer = len_ptr ;
- if ( len_ptr == 0 )
- bytes_avail = len_buffer = 0 ;
- else
- bytes_avail = len_buffer = len_ptr - (0x400 - (unsigned) (start_offset % 0x400)) ;
-
- return 0 ;
- }
-
-