home *** CD-ROM | disk | FTP | other *** search
-
- /*
- d4lock( lock_code ) (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved.
-
- - if (lock_code > 0) the record is locked
- - if (lock_code -1 ) lock the whole file
- - if (lock_code == 0) lock the record count bytes
-
- rc
- 0 - SUCCESS
- -1 - Error
- -2 - Locked by Another Station
- */
-
-
-
- #include "d4base.h"
- #include "u4error.h"
-
- extern BASE *v4base ;
- extern int v4cur_base ;
-
- extern long lseek(int, long, int) ;
-
-
- int d4lock( lock_code, do_wait )
- long lock_code ;
- int do_wait ;
- {
- int rc ;
- BASE *base_ptr ;
-
- if ( v4cur_base < 0 )
- {
- u4error( E_D_MISSING, (char *) 0 ) ;
- return( -1 ) ;
- }
-
- base_ptr = v4base+ v4cur_base ;
- if ( lock_code < -1 ) lock_code = -1 ;
-
- /* if file is already locked, return normally */
- if ( base_ptr->file_lock == 1 )
- return( 0 ) ;
-
- /* if record is already locked, return normally */
- if ( lock_code > 0 )
- if ( base_ptr->rec_lock == lock_code)
- return( 0) ;
-
- /* if record count bytes are already locked, return normally */
- if ( lock_code == 0 )
- if ( base_ptr->file_lock == 2 )
- return( 0) ;
-
- /* do any necessary unlocking */
- if ( lock_code == -1 )
- if ( d4unlock( -1L ) < 0 ) return( -1 ) ;
- if ( lock_code > 0 )
- if ( base_ptr->rec_lock > 0 )
- if ( d4unlock( 1L ) < 0 ) return( -1 ) ;
-
- rc = 0 ;
-
- if (lock_code > 0)
- {
- /* Specified Record Number */
- rc = u4lock( base_ptr->dos_file, LOCK_START+ lock_code, 1L, do_wait) ;
- if ( rc == 0 ) base_ptr->rec_lock = lock_code ;
- }
- else
- {
- if (lock_code == 0)
- {
- /* Record Count Bytes */
- rc = u4lock( base_ptr->dos_file, LOCK_START, 1L, do_wait ) ;
- if ( rc == 0 ) base_ptr->file_lock = 2 ;
- }
- else
- {
- /* Whole File */
- rc = u4lock( base_ptr->dos_file, LOCK_START, LOCK_START, do_wait) ;
- if ( rc == 0 ) base_ptr->file_lock = 1 ;
- }
- }
- return( rc ) ;
- }
-
-