home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / OS2ASM.ZIP / LOCKING.ASM < prev    next >
Assembly Source File  |  1991-09-13  |  2KB  |  95 lines

  1. ;_ locking.asm   Fri Dec 15 1989   Modified by: Walter Bright */
  2. ;Copyright (C) 1989-1990 by Walter Bright
  3. ;All rights reserved.
  4. ;Written by Dave Mansell
  5.  
  6. include macros.asm
  7.  
  8.     begdata
  9.  
  10.     extrn    _errno:word
  11.  
  12.     enddata
  13.  
  14. EDEADLOCK equ 36
  15.  
  16.     begcode
  17.  
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;    int locking(int fd, int mode, long size);
  20.  
  21. count    equ    byte ptr -1[EBP]
  22. mins    equ    byte ptr -2[EBP]
  23. hundredths equ    word ptr -4[EBP]
  24.  
  25.     c_public locking
  26. func    locking
  27.     push    EBP
  28.     mov    EBP,ESP
  29.     sub    ESP,4
  30.     uses    <EBX,ESI,EDI>
  31.     mov    AX,4201h
  32.     mov    EBX,P[EBP]        ;get file handle
  33.     clr    ECX
  34.     mov    EDX,ECX
  35.     bdos                ;seek to current position in file
  36.     jc    Lerr
  37.     mov    ECX,EDX            ;high word of region offset
  38.     mov    EDX,EAX            ;low word of region offset
  39.     mov    AX,5C00h
  40.     mov    DI,P+4+4[EBP]        ;low word of region length
  41.     mov    SI,P+4+4+2[EBP]        ;high word of region length
  42.     _ifs    <byte ptr P+4[EBP]> ne AL, L1
  43.     inc    AL
  44. L1:    bdos
  45.     jnc    Lok
  46.     _ifs    AX e 1, Lerr
  47.     test    byte ptr P+4[EBP], 1
  48.     je    Lerr
  49.  
  50.     mov    count,11
  51. L2:    dec    count
  52.     je    Ldeadlock
  53.     push    ECX
  54.     push    EDX
  55.     bdos    2Ch            ;get system time
  56.     movzx    EAX,DH            ;EAX = seconds (0-59)
  57.     imul    EAX,100
  58.     movzx    EDX,DL
  59.     add    EAX,EDX
  60.     mov    mins,CL
  61.     mov    hundredths,AX
  62. L4:    bdos    2Ch
  63.     movzx    EAX,DH
  64.     imul    EAX,100
  65.     movzx    EDX,DL
  66.     add    EAX,EDX
  67.     cmp    CL,mins
  68.     je    L5
  69.     add    AX,6000
  70. L5:    sub    AX,hundredths
  71.     _ifs    AX l 100, L4
  72.     pop    EDX
  73.     pop    ECX
  74.     mov    AX,5C00h
  75.     mov    EBX,P[EBP]        ;fd
  76.     mov    DI,P+4+4[EBP]
  77.     mov    SI,P+4+4+2[EBP]
  78.     bdos
  79.     jc    L2
  80. Lok:    clr    EAX
  81. Lx:    unuse    <EDI,ESI,EBX>
  82.     mov    ESP,EBP
  83.     pop    EBP
  84.     ret
  85.  
  86. Ldeadlock:
  87.     mov    EAX,EDEADLOCK
  88. Lerr:    mov    _errno,AX
  89.     mov    EAX,-1
  90.     jmp    Lx
  91. c_endp    locking
  92.  
  93.     endcode
  94.     end
  95.