home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / LOCK.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.9 KB  |  100 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - lock.cas
  3.  *
  4.  * function(s)
  5.  *        lock   - sets file sharing locks
  6.  *        unlock - resets file sharing locks
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*[]------------------------------------------------------------[]*/
  10. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #pragma inline
  20. #include <io.h>
  21. #include <_io.h>
  22.  
  23. /*-----------------------------------------------------------------------*
  24.  
  25. Name          lock - sets file sharing locks
  26.  
  27. Usage        int lock(int handle, long offset, long length);
  28.  
  29. Related
  30. functions usage    int unlock(int handle, long offset, long length);
  31.  
  32. Prototype in    io.h
  33.  
  34. Description    lock and unlock provide an interface to the MS-DOS
  35.         3.x file-sharing mechanism.
  36.  
  37.         lock can be placed on arbitrary, non-overlapping regions of
  38.         any file. A program attempting to read or write into a
  39.         locked region will retry the operation three times. If all
  40.         three retries fail, the call fails with an error.
  41.  
  42.         unlock removes lock; to avoid error, lock must be removed
  43.         before a file is closed. A program must release all lock(s)
  44.         before completing.
  45.  
  46. Return value    Both functions return 0 on success, -1 on error.
  47.  
  48. Portability    Unique to MS-DOS 3.x. Older versions of MS-DOS do
  49.         not support these calls.
  50.  
  51. *------------------------------------------------------------------------*/
  52. int lock(int handle, long offset, long length)
  53. {
  54. asm    mov    ax, 05C00h
  55. asm    mov    bx, handle
  56. asm    mov    cx, offset+2
  57. asm    mov    dx, offset
  58. asm    mov    si, length+2
  59. asm    mov    di, length
  60. asm    int    021h
  61. asm    jc    lockFailed
  62.     return(0);
  63.  
  64. lockFailed:
  65.     return __IOerror (_AX);
  66. }
  67.  
  68.  
  69. /*-----------------------------------------------------------------------*
  70.  
  71. Name          unlock - resets file sharing locks
  72.  
  73. Usage        int unlock(int handle, long offset, long length);
  74.  
  75. Related
  76. functions usage    int lock(int handle, long offset, long length);
  77.  
  78. Prototype in    io.h
  79.  
  80. Description    see lock above
  81.  
  82. Return value    Both functions return 0 on success, -1 on error.
  83.  
  84. *------------------------------------------------------------------------*/
  85. int unlock(int handle, long offset, long length)
  86. {
  87. asm    mov    ax, 05C01h
  88. asm    mov    bx, handle
  89. asm    mov    cx, offset+2
  90. asm    mov    dx, offset
  91. asm    mov    si, length+2
  92. asm    mov    di, length
  93. asm    int    021h
  94. asm    jc    unlockFailed
  95.     return(0);
  96.  
  97. unlockFailed:
  98.     return __IOerror (_AX);
  99. }
  100.