home *** CD-ROM | disk | FTP | other *** search
-
- /*
- d4unlock() (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- - unlocks the previos lock for that database
- */
-
- #include "d4all.h"
- #include "u4error.h"
-
- #ifdef LOG
- extern void logger( char *, char *) ;
- #endif
-
- extern BASE *v4base ;
- extern int v4cur_base ;
-
-
- int d4unlock( long lock_code )
- {
- int rc ;
- BASE *base_ptr ;
-
- if ( v4cur_base < 0 )
- {
- u4error( E_D_MISSING, (char *) 0 ) ;
- return( -1 ) ;
- }
-
- base_ptr = v4base + v4cur_base ;
- rc = 0 ;
-
- if ( base_ptr->file_lock == 1 && lock_code == -1L )
- {
- #ifndef SMALL
- /* The Whole File */
- if ( d4buf_clear_base( v4cur_base) < 0 ) return -1 ;
- #endif
-
- #ifdef LOG
- logger( d4name(), "File Unlock" ) ;
- #endif
- rc = u4unlock( base_ptr->file_hand, LOCK_START, LOCK_START ) ;
- base_ptr->file_lock = -1 ;
- base_ptr->rec_lock = 0L ;
- base_ptr->num_recs = -1L ;
- }
- else
- {
- if ( base_ptr->file_lock == 0 && (lock_code == -1L || lock_code == 0L))
- {
- #ifndef SMALL
- /* Record Count Bytes */
- if ( d4buf_clear_base(v4cur_base) < 0 ) return -1 ;
- #endif
- #ifdef LOG
- logger( d4name(), "Count Unlock" ) ;
- #endif
- rc = u4unlock(base_ptr->file_hand, LOCK_START, 1L) ;
- base_ptr->num_recs = -1L ;
- base_ptr->file_lock = -1 ;
- }
-
- if ( base_ptr->rec_lock > 0L && (lock_code == -1L || lock_code > 0L) )
- {
- #ifdef LOG
- char buf[20] ;
- c4ltoa( -base_ptr->rec_lock, buf, 10 ) ;
- buf[10] = '\000' ;
- logger( d4name(), buf ) ;
- #endif
- #ifndef SMALL
- if ( d4buf_clear_base(v4cur_base) < 0 ) return -1 ;
- #endif
- rc = u4unlock(base_ptr->file_hand, LOCK_START+base_ptr->rec_lock, 1L) ;
- base_ptr->rec_lock = 0 ;
- }
- }
-
- #ifndef SMALL
- if ( lock_code == -1 )
- if ( i4unlock( -1 ) < 0 ) return( -1 ) ;
- #endif
-
- return( rc ) ;
- }
-
-