home *** CD-ROM | disk | FTP | other *** search
-
- /* d4close.c (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Closes a database file.
- */
-
- #include "d4all.h"
- #include "u4error.h"
-
- #include <time.h>
- #ifndef UNIX
- #include <io.h>
- #endif
-
- extern BASE *v4base ;
- extern int v4cur_base ;
- extern int v4last_base ;
-
- d4close()
- {
- int file_hand, rc, close_return ;
- BASE *base_ptr ;
-
- long time_val ; /* For Update Time */
- struct tm *tm_ptr ;
-
- x4filter_reset() ;
- x4relate_reset() ;
-
- base_ptr = v4base + v4cur_base ;
- if ( v4cur_base < 0 )
- {
- u4error( E_D_MISSING, (char *) 0 ) ;
- return( -1 ) ;
- }
-
- close_return = 0 ;
-
- if ( d4flush(v4cur_base) < 0 ) close_return = -1 ;
- h4free_memory( base_ptr->old_buf ) ;
- h4free_memory( (char *) base_ptr->fields ) ;
-
- if ( d4buf_total( 0L, 0, 1) < 0 )
- close_return = -1 ;
-
- #ifndef SMALL
- /* Close the Index Files */
- while ( base_ptr->index_ref >= 0 )
- if ( i4close( base_ptr->index_ref) < 0 ) close_return = -1 ;
- #endif
-
- /* Close the Memo Files */
- if ( base_ptr->memo_file >= 0 )
- close( base_ptr->memo_file ) ;
-
- file_hand = base_ptr->file_hand ;
-
- /* Lock the header, update the header, and close the file */
- if ( d4lock( 0L,1 ) == -1 ) close_return = -1 ;
- d4reccount() ; /* Fills in the 'header 'num_recs' */
-
- /* Update the last Update Time */
- time ( (time_t *) &time_val) ;
- tm_ptr = localtime( (time_t *) &time_val) ;
-
- base_ptr->yy = (char) tm_ptr->tm_year ;
- base_ptr->mm = (char) tm_ptr->tm_mon+ (char) 1 ;
- base_ptr->dd = (char) tm_ptr->tm_mday ;
-
- lseek( file_hand, 1L, 0 ) ;
- if( write( file_hand, (char *) &base_ptr->yy, 7) != 7)
- {
- 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( file_hand) ;
-
- return( close_return ) ;
- }
-
-
- d4close_all()
- {
- while( v4last_base >= 0 ) if ( d4close() < 0 ) return( -1 ) ;
- return( 0 ) ;
- }
-