home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-1.ZIP / SOURCE.ZIP / D4UNLOCK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-14  |  1.5 KB  |  74 lines

  1.  
  2. /*
  3.     d4unlock()   (c)Copyright Sequiter Software Inc., 1987, 1988, 1989.  All rights reserved.
  4.  
  5.     - unlocks the previos lock for that database
  6. */
  7.  
  8. #include "d4base.h"
  9. #include "u4error.h"
  10. #ifndef UNIX
  11.    #include <io.h>
  12.    #include <errno.h>
  13.  
  14.    #ifndef TURBO
  15.       #include <sys\locking.h>
  16.    #endif
  17. #endif
  18. #include <stdlib.h>
  19.  
  20. #ifdef UNIX
  21.    extern int  errno ;
  22. #endif
  23.  
  24. extern BASE  *v4base ;
  25. extern int    v4cur_base ;
  26.  
  27.  
  28. int d4unlock( lock_code )
  29. long  lock_code ;
  30. {
  31.    int    rc ;
  32.    BASE  *base_ptr ;
  33.  
  34.    if ( v4cur_base < 0 )
  35.    {
  36.       u4error( E_D_MISSING, (char *) 0 ) ;
  37.       return( -1 ) ;
  38.    }
  39.  
  40.    #ifndef SMALL
  41.       if ( lock_code == -1 )
  42.      if ( i4unlock( -1 ) < 0 )  return( -1 ) ;
  43.    #endif
  44.  
  45.    base_ptr  =  v4base + v4cur_base ;
  46.    rc =  errno =  0 ;
  47.  
  48.    if ( base_ptr->file_lock == 1  &&  lock_code == -1 )
  49.    {
  50.       /* The Whole File */
  51.       rc =  u4unlock( base_ptr->dos_file, LOCK_START, LOCK_START ) ;
  52.       base_ptr->file_lock =  0 ;
  53.       base_ptr->rec_lock  =  0 ;
  54.    }
  55.    else
  56.    {
  57.       if ( base_ptr->file_lock == 2 &&  (lock_code == -1 || lock_code == 0) )
  58.       {
  59.      /* Record Count Bytes */
  60.      rc =  u4unlock(base_ptr->dos_file, LOCK_START, 1L) ;
  61.      base_ptr->file_lock =  0 ;
  62.       }
  63.  
  64.       if ( base_ptr->rec_lock > 0  &&  (lock_code == -1 || lock_code > 0) )
  65.       {
  66.      rc = u4unlock(base_ptr->dos_file, LOCK_START+base_ptr->rec_lock, 1L) ;
  67.      base_ptr->rec_lock =  0 ;
  68.       }
  69.    }
  70.  
  71.    return( rc ) ;
  72. }
  73.  
  74.