home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / FLLOCK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  1.8 KB  |  68 lines

  1. /**
  2. *
  3. * Name        FLLOCK -- Lock or unlock a section of a file
  4. *              associated with a file handle.
  5. *
  6. * Synopsis    ercode = fllock (handle, option, offset, length);
  7. *
  8. *        int ercode      DOS function error code.
  9. *        int handle      File handle of open file.
  10. *        int option      FL_LOCK or FL_UNLOCK.
  11. *        unsigned long offset
  12. *                  Offset (in bytes) of beginning of
  13. *                  region to lock.
  14. *        unsigned long length
  15. *                  Length (in bytes) of beginning of
  16. *                  region to lock.
  17. *
  18. * Description    This function locks or unlocks a section of an open file
  19. *        associated with the specified handle.
  20. *
  21. *        DOS 3.10 or later is required.    Earlier versions of DOS
  22. *        return a value of 1 indicating that the function number
  23. *        is unknown.
  24. *
  25. *        The designated region of the file may extend beyond the
  26. *        end of the file.
  27. *
  28. *        Do not close the file or allow the program to terminate
  29. *        without removing all locks.
  30. *
  31. * Returns    ercode          DOS function return code
  32. *
  33. * Version    6.00 (C)Copyright Blaise Computing Inc. 1987, 1989
  34. *
  35. **/
  36.  
  37. #include <dos.h>
  38.  
  39. #include <bfiles.h>
  40.  
  41. #define LOCK_FUNC 0x5c
  42.  
  43. int fllock (handle, option, offset, length)
  44. int           handle, option;
  45. unsigned long  offset, length;
  46. {
  47.     union REGS regs;
  48.  
  49.     if (utdosmajor < 3)           /* DOS version 2.x:          */
  50.     return 1;              /* This function is unknown.    */
  51.  
  52.     /* (Note:  DOS 3.00 does not support function 0x5c but at least   */
  53.     /* it reports a valid error code & extended error information.)   */
  54.  
  55.     regs.x.ax = utbyword (LOCK_FUNC, option);
  56.     regs.x.bx = handle;
  57.     regs.x.cx = (int) uthiword (offset);
  58.     regs.x.dx = (int) utloword (offset);
  59.     regs.x.si = (int) uthiword (length);
  60.     regs.x.di = (int) utloword (length);
  61.  
  62.     int86 (FL_DOS_INT, ®s, ®s);
  63.  
  64.     return ((regs.x.cflag)
  65.         ? (regs.h.al)
  66.         : (0));
  67. }
  68.