home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 5.ddi / CLIBSRC2.ZIP / DOSLOCK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.1 KB  |  102 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - doslock.c
  3.  *
  4.  * function(s)
  5.  *        _dos_lock   - sets file sharing locks
  6.  *        _dos_unlock - resets file sharing locks
  7.  *--------------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1991, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #include <_io.h>
  19. #include <dos.h>
  20.  
  21. /*-----------------------------------------------------------------------*
  22.  
  23. Name            _dos_lock - sets file sharing locks
  24.  
  25. Usage           unsigned _dos_lock(int handle, long offset, long length);
  26.  
  27. Related
  28. functions usage unsigned _dos_unlock(int handle, long offset, long length);
  29.  
  30. Prototype in    none
  31.  
  32. Description     _dos_lock and _dos_unlock provide an interface to the MS-DOS
  33.                 3.x file-sharing mechanism.
  34.  
  35.                 lock can be placed on arbitrary, non-overlapping regions of
  36.                 any file. A program attempting to read or write into a
  37.                 locked region will retry the operation three times. If all
  38.                 three retries fail, the call fails with an error.
  39.  
  40.                 _dos_unlock removes lock; to avoid error, lock must be removed
  41.                 before a file is closed. A program must release all lock(s)
  42.                 before completing.
  43.  
  44. Return value    Both functions return 0 on success.  Otherwise, they return
  45.                 the DOS error code and set errno as follows:
  46.  
  47.                 EBADF           Invalid file handle
  48.                 EACCESS         Locking violation (file already locked
  49.                                 or unlocked)
  50.  
  51. Portability     Unique to MS-DOS 3.x. Older versions of MS-DOS do
  52.                 not support these calls.
  53.  
  54. *------------------------------------------------------------------------*/
  55.  
  56. unsigned _dos_lock(int handle, long offset, long length)
  57. {
  58.     _BX = handle;
  59.     _CX = FP_SEG(offset);
  60.     _DX = FP_OFF(offset);
  61.     _SI = FP_SEG(length);
  62.     _DI = FP_OFF(length);
  63.     _AX = 0x5c00;
  64.     geninterrupt(0x21);
  65.     if (_FLAGS & 1)                     /* if carry set, error */
  66.         return (__DOSerror(_AX));       /* set errno */
  67.     else
  68.         return (0);
  69. }
  70.  
  71.  
  72. /*-----------------------------------------------------------------------*
  73.  
  74. Name            _dos_unlock - resets file sharing locks
  75.  
  76. Usage           int _dos_unlock(int handle, long offset, long length);
  77.  
  78. Related
  79. functions usage unsigned _dos_lock(int handle, long offset, long length);
  80.  
  81. Prototype in    none
  82.  
  83. Description     see _dos_lock above
  84.  
  85. Return value    see _dos_lock above
  86.  
  87. *------------------------------------------------------------------------*/
  88. unsigned _dos_unlock(int handle, long offset, long length)
  89. {
  90.     _BX = handle;
  91.     _CX = FP_SEG(offset);
  92.     _DX = FP_OFF(offset);
  93.     _SI = FP_SEG(length);
  94.     _DI = FP_OFF(length);
  95.     _AX = 0x5c01;
  96.     geninterrupt(0x21);
  97.     if (_FLAGS & 1)                     /* if carry set, error */
  98.         return (__DOSerror(_AX));       /* set errno */
  99.     else
  100.         return (0);
  101. }
  102.