home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / U4UNLOCK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  1.5 KB  |  97 lines

  1.  
  2. /* u4unlock.c    (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved.
  3.  
  4.    Returns
  5.       0   Normal
  6.      -1   Error
  7. */
  8.  
  9. #include "p4misc.h"
  10. #include "d4base.h"
  11. #include "u4error.h"
  12.  
  13. #include <errno.h>
  14.  
  15. #ifdef NO_LOCK
  16. u4unlock( int file_handle, long o_set, long num_bytes )
  17. {
  18.    return 0 ;
  19. }
  20. #endif
  21.  
  22. #ifdef LOCK_TRAP
  23. extern int u4lock_remove( int, long, long ) ;
  24. #endif
  25.  
  26. #ifdef DO_ERRNO
  27.    extern int  errno ;
  28. #endif
  29.  
  30. #ifdef DO_LOCK
  31.  
  32. #include <io.h>
  33.  
  34. u4unlock( int file_handle, long o_set, long num_bytes )
  35. {
  36.    int    rc ;
  37.  
  38.    #ifdef LOCK_TRAP
  39.       d4lock_remove( file_handle, o_set, num_bytes ) ;
  40.    #endif
  41.  
  42.    errno =  0 ;
  43.    rc =  unlock( file_handle, o_set, num_bytes ) ;
  44.    #ifdef IS_386
  45.       rc &= 0xFFFF ;
  46.    #endif
  47.  
  48.    if (rc < 0  && errno != EINVAL )
  49.    {
  50.       u4error( E_UNLOCK, (char *) 0 ) ;
  51.       return( -1) ;
  52.    }
  53.  
  54.    return 0 ;
  55. }
  56. #endif
  57.  
  58.  
  59. #ifdef DO_LOCKING
  60.  
  61. #ifndef UNIX
  62. #include <io.h>
  63. #endif
  64.  
  65. #ifdef UNIX
  66. #include <sys/locking.h>
  67. #else
  68. #include <sys\locking.h>
  69. #endif
  70.  
  71.  
  72. u4unlock( int file_handle, long o_set, long num_bytes )
  73. {
  74.    int    rc ;
  75.  
  76.    #ifdef LOCK_TRAP
  77.       d4lock_remove( file_handle, o_set, num_bytes ) ;
  78.    #endif
  79.  
  80.    errno =  0 ;
  81.  
  82.    lseek( file_handle, o_set, 0 ) ;
  83.    rc =  locking( file_handle, LK_UNLCK, num_bytes) ;
  84.    #ifdef IS_386
  85.       rc &= 0xFFFF ;
  86.    #endif
  87.  
  88.    if (rc < 0  && errno != EINVAL )
  89.    {
  90.       u4error( E_UNLOCK, (char *) 0 ) ;
  91.       return( -1) ;
  92.    }
  93.  
  94.    return 0 ;
  95. }
  96. #endif
  97.