home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / CLIBSRC1.ZIP / LOCK.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.8 KB  |  101 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.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #pragma inline
  19. #include <io.h>
  20. #include <_io.h>
  21.  
  22. /*-----------------------------------------------------------------------*
  23.  
  24. Name            lock - sets file sharing locks
  25.  
  26. Usage           int lock(int handle, long ofs, long length);
  27.  
  28. Related
  29. functions usage int unlock(int handle, long ofs, long length);
  30.  
  31. Prototype in    io.h
  32.  
  33. Description     lock and unlock provide an interface to the MS-DOS
  34.                 3.x file-sharing mechanism.
  35.  
  36.                 lock can be placed on arbitrary, non-overlapping regions of
  37.                 any file. A program attempting to read or write into a
  38.                 locked region will retry the operation three times. If all
  39.                 three retries fail, the call fails with an error.
  40.  
  41.                 unlock removes lock; to avoid error, lock must be removed
  42.                 before a file is closed. A program must release all lock(s)
  43.                 before completing.
  44.  
  45. Return value    Both functions return 0 on success, -1 on error.
  46.  
  47. Portability     Unique to MS-DOS 3.x. Older versions of MS-DOS do
  48.                 not support these calls.
  49.  
  50. *------------------------------------------------------------------------*/
  51.  
  52. int _FARFUNC lock(int handle, long ofs, long length)
  53. {
  54. asm     mov     ax, 05C00h
  55. asm     mov     bx, handle
  56. asm     mov     cx, ofs+2
  57. asm     mov     dx, ofs
  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 ofs, long length);
  74.  
  75. Related
  76. functions usage int lock(int handle, long ofs, 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.  
  86. int _FARFUNC unlock(int handle, long ofs, long length)
  87. {
  88. asm     mov     ax, 05C01h
  89. asm     mov     bx, handle
  90. asm     mov     cx, ofs+2
  91. asm     mov     dx, ofs
  92. asm     mov     si, length+2
  93. asm     mov     di, length
  94. asm     int     021h
  95. asm     jc      unlockFailed
  96.         return(0);
  97.  
  98. unlockFailed:
  99.         return __IOerror (_AX);
  100. }
  101.