home *** CD-ROM | disk | FTP | other *** search
- {$A-,I-,X+}
- unit eco_lock;
- interface
- uses dos;
-
- type
- stream = file;
-
- const
- _keep_mode = -1; { do not change file mode in fopen }
- _readonly = $00; { share mode dos 3++ and above }
- _denyall = $10;
- _writeonly = $01;
- _denywrite = $20;
- _readwrite = $02;
- _denyread = $30;
- _denynone = $40;
-
- lockregion = 00;
- unlockregion = 01;
-
-
- function fopen(var fv : stream; fn : pathstr; mode : integer) : integer;
- function fclose(var fv : stream) : integer;
- function shareloaded : boolean;
- function filelock(
- handle : word;
- action : byte;
- start,
- bytes : longint;
- var ax : integer
- ): boolean;
-
-
-
-
-
-
- implementation
-
-
-
-
-
-
- function fopen; {open untyped file return the dos error code}
- var fm : byte;
- begin
- assign(fv,fn);
- fm := filemode;
- if mode <> _keep_mode then filemode := mode;
- reset(fv,1);
- fopen := ioresult;
- filemode := fm;
- end;
-
-
-
-
- function fclose(var fv : stream) : integer;
- begin
- close(fv);
- fclose := ioresult;
- end;
-
-
-
- function shareloaded : boolean;
- var reg : registers;
- begin
- reg.ax := $1000;
- intr($2f,reg);
- shareloaded := ((reg.flags and $01) = 0) and (reg.al = $ff);
- end;
-
-
-
- {
-
- Lock or Unlock region of file.
-
- Input : Handle - turbo untype file variable handle (filerec(fv).handle)
- input : action - action to take. See constants above;
- input : start - beginging file position to lock.
- input : bytes - number of bytes to lock.
- output : ax - ax register return value
-
- returns TRUE if lock is successful, False otherwise (check AX)
-
- }
-
-
-
- function filelock(handle : word; action : byte; start,bytes : longint; var ax : integer): boolean;
- var reg : registers;
- begin
- reg.ax := $5c00 + action;
- reg.bx := handle;
- reg.cx := hi(start);
- reg.dx := lo(start);
- reg.si := hi(bytes);
- reg.di := lo(bytes);
- intr($21,reg);
- filelock := (reg.flags and $01) = $00;
- ax := reg.ax;
- end;
-
- end.
-