home *** CD-ROM | disk | FTP | other *** search
-
- /* u4lock.c (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved.
-
- Returns
- 0 Normal
- -1 Error
- -2 Locked by other User
- */
-
- #include "d4base.h"
- #include "u4error.h"
-
- #ifndef UNIX
- #include <io.h>
- #endif
- #ifndef TURBO
- #ifdef UNIX
- #include <sys/locking.h>
- #else
- #include <sys\locking.h>
- #endif
- #endif
-
- #include <stdlib.h>
- #include <errno.h>
- #include <stdlib.h>
-
- extern long time( long *) ;
-
-
- u4lock( file_handle, o_set, num_bytes, do_wait )
- int file_handle ;
- long o_set, num_bytes ;
- int do_wait ;
- {
- int rc ;
-
- errno = 0 ;
-
- #ifdef TURBO
- rc = lock( file_handle, o_set, num_bytes ) ;
- #else
- lseek( file_handle, o_set, 0 ) ;
- rc = locking( file_handle, LK_NBLCK, num_bytes) ;
- #endif
-
- if (rc == 0 || errno == EINVAL) return( 0) ; /* Single User or Success */
-
- #ifndef UNIX
- if (errno != EACCES)
- {
- u4error( E_LOCK, (char *) 0 ) ;
- return( -1) ;
- }
- #endif
-
- if ( ! do_wait ) return( -2 ) ;
-
- while (1)
- {
- #ifdef TURBO
- long old_time ;
-
- time( &old_time) ; /* wait a second & try lock again */
- while ( time( (long*)0 ) <= old_time) ;
-
- if ( lock( file_handle, o_set, num_bytes ) == 0 )
- return( 0) ;
- #else
- lseek( file_handle, o_set, 0 ) ;
- if ( locking( file_handle, LK_LOCK, num_bytes) == 0)
- return( 0) ;
- #endif
- }
- }
-