home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / D4UNLOCK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-19  |  2.0 KB  |  88 lines

  1.  
  2. /*
  3.     d4unlock()   (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved.
  4.  
  5.     - unlocks the previos lock for that database
  6. */
  7.  
  8. #include "d4all.h"
  9. #include "u4error.h"
  10.  
  11. #ifdef LOG
  12.    extern void logger( char *, char *) ;
  13. #endif
  14.  
  15. extern BASE  *v4base ;
  16. extern int    v4cur_base ;
  17.  
  18.  
  19. int d4unlock( long lock_code )
  20. {
  21.    int    rc ;
  22.    BASE  *base_ptr ;
  23.  
  24.    if ( v4cur_base < 0 )
  25.    {
  26.       u4error( E_D_MISSING, (char *) 0 ) ;
  27.       return( -1 ) ;
  28.    }
  29.  
  30.    base_ptr  =  v4base + v4cur_base ;
  31.    rc =  0 ;
  32.  
  33.    if ( base_ptr->file_lock == 1  &&  lock_code == -1L )
  34.    {
  35.       #ifndef SMALL
  36.      /* The Whole File */
  37.      if ( d4buf_clear_base( v4cur_base) < 0 )  return -1 ;
  38.       #endif
  39.  
  40.       #ifdef LOG
  41.          logger( d4name(), "File Unlock" ) ;
  42.       #endif
  43.       rc =  u4unlock( base_ptr->file_hand, LOCK_START, LOCK_START ) ;
  44.       base_ptr->file_lock =  -1 ;
  45.       base_ptr->rec_lock  =  0L ;
  46.       base_ptr->num_recs = -1L ;
  47.    }
  48.    else
  49.    {
  50.       if ( base_ptr->file_lock == 0 && (lock_code == -1L || lock_code == 0L))
  51.       {
  52.      #ifndef SMALL
  53.         /* Record Count Bytes */
  54.         if ( d4buf_clear_base(v4cur_base) < 0 )  return -1 ;
  55.      #endif
  56.          #ifdef LOG
  57.             logger( d4name(), "Count Unlock" ) ;
  58.          #endif
  59.      rc =  u4unlock(base_ptr->file_hand, LOCK_START, 1L) ;
  60.      base_ptr->num_recs = -1L ;
  61.          base_ptr->file_lock =  -1 ;
  62.       }
  63.  
  64.       if ( base_ptr->rec_lock > 0L  &&  (lock_code == -1L || lock_code > 0L) )
  65.       {
  66.          #ifdef LOG
  67.             char buf[20] ;
  68.             c4ltoa( -base_ptr->rec_lock, buf, 10 ) ;
  69.             buf[10] = '\000' ;
  70.             logger( d4name(), buf ) ;
  71.          #endif
  72.      #ifndef SMALL
  73.         if ( d4buf_clear_base(v4cur_base) < 0 )  return -1 ;
  74.      #endif
  75.      rc = u4unlock(base_ptr->file_hand, LOCK_START+base_ptr->rec_lock, 1L) ;
  76.      base_ptr->rec_lock =  0 ;
  77.       }
  78.    }
  79.  
  80.    #ifndef SMALL
  81.       if ( lock_code == -1 )
  82.          if ( i4unlock( -1 ) < 0 )  return( -1 ) ;
  83.    #endif
  84.  
  85.    return( rc ) ;
  86. }
  87.  
  88.