home *** CD-ROM | disk | FTP | other *** search
-
- /* d4close.c (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved.
-
- Closes a database file.
- */
-
- #include "d4base.h"
- #ifndef UNIX
- #include <io.h>
- #endif
- #include <string.h>
-
- #include "u4error.h"
-
- extern BASE *v4base ;
- extern int v4cur_base ;
- extern int v4last_base ;
-
- d4close( )
- {
- int dos_file, rc, close_return ;
- long disk_time, header_time ;
- BASE *base_ptr ;
- struct
- {
- char yy ;
- char mm ;
- char dd ;
- } disk_update, header_update ;
-
- base_ptr = v4base + v4cur_base ;
- if ( v4cur_base < 0 )
- {
- u4error( E_D_MISSING, (char *) 0 ) ;
- return( -1 ) ;
- }
-
- close_return = 0 ;
-
- h4free_memory( base_ptr->old_buf ) ;
- h4free_memory( (char *) base_ptr->fields ) ;
-
- #ifndef SMALL
- /* Close the Index Files */
- while ( base_ptr->index_ref >= 0 )
- i4close( base_ptr->index_ref ) ;
- #endif
-
- /* Close the Memo Files */
- if ( base_ptr->memo_file >= 0 )
- close( base_ptr->memo_file ) ;
-
- memcpy( (char *) &header_update, &base_ptr->yy, 3) ;
- dos_file = base_ptr->dos_file ;
-
- /* Lock the header update time & close the file */
- d4lock( 0L,1 ) ;
-
- lseek( dos_file, 1L, 0 ) ;
- if ( read( dos_file, (char *) &disk_update, 3) != 3)
- {
- u4error( E_READ, base_ptr->name, (char *) 0) ;
- close_return = -1 ;
- }
- else
- {
- disk_time = ((long)disk_update.yy<<16) + ((long)disk_update.mm<<8) +
- (long)disk_update.dd ;
- header_time= ((long)header_update.yy<<16)+ ((long)header_update.mm<<8)+
- (long)header_update.dd ;
- if ( disk_time < header_time )
- {
- /* Compare as Another User Might Have Modified More Recently */
- lseek( dos_file, 1L, 0) ;
- if( write( dos_file, (char *) &header_update, 3) != 3)
- {
- u4error( E_WRITE, base_ptr->name, (char *) 0) ;
- close_return = -1 ;
- }
- }
- }
-
- if ( d4unlock( -1L ) < 0 ) close_return = -1 ;
-
- rc = h4free( (char **) &v4base, v4cur_base ) ;
- if ( v4cur_base == v4last_base )
- v4last_base = rc ;
- v4cur_base = v4last_base ;
-
- close( dos_file) ;
-
- return( close_return ) ;
- }
-
-
- d4close_all()
- {
- while( v4last_base >= 0 ) if ( d4close() < 0 ) return( -1 ) ;
- return( 0 ) ;
- }