home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFPRC1
/
OPENREAD.SRF
< prev
next >
Wrap
Text File
|
1996-10-17
|
2KB
|
74 lines
/* ----------------------------------------------------------------------- */
/* OPEN_READ: keep trying to open a file (for msec seconds
. Argumentes:
afile == file to open
msec == quit trying after msec seconds
howopen = open mode (READ WRITE BOTH READ ) -- default is READ
Returns
Status, with values
-1 = no such file
-2 = error opening (say, NEW specified but file exists), or timeout
>0 = seconds it took to open
*/
/* ----------------------------------------------------------------------- */
sref_open_read:
parse upper arg afile , msec , howopen .
debug=0
howopen=translate(howopen)
if afile=0 | afile="" then do
if debug=1 then say "OPEN_READ: No file name provided "
return -1 /*no such file flat */
end
/* DISALLOW wildcarded files (they cause trouble below */
if pos('*',afile)>0 | pos('?',afile)>0 then do
if debug=1 then say "OPEN_READ: No wildcards allowed "
return -1
end
isfile=stream(afile,'c','query exists') ;
if howopen="NEW" then do
if isfile="" then
isfile=afile
else do
if debug=1 then say "OPEN_READ: NEW file already exists "
return -1
end /* Do */
end
else do
if isfile="" then do
if debug=1 then say 'OPEN_READ: Could not find ' afile
return -1 /*no such file */
end
end
sec1=time('RESET')
foy=time('ELAPSED')
do until time('ELAPSED') > msec
select
when howopen='BOTH' then
inuse=stream(isfile,'c','open')
when howopen='WRITE'| howopen="NEW" then do
inuse=stream(isfile,'c','open write')
end
otherwise do
inuse=stream(isfile,'c','open read')
end
end
if inuse<>'READY:' then do
foo=syssleep(1) /* wait a second, and try again */
iterate
end
/* Else, it's openable */
gog=time('ELAPSED')
return gog+0.01
end
if debug=1 then say " OPEN_READ: no time "
return -2 /* could not open in alloted time */