rfh3273@galileo.rtn.ca.boeing.com (Dick Harrigill) (05/14/91)
I've just experienced a strange error with TP6. I'm using a function that I've successfully used for years to check the existance of a file: FUNCTION this_file_exists (VAR s:string) : boolean; VAR f:file; BEGIN {$I-} assign(f,s); reset(f); this_file_exists:=(IOError=0); close(f); {$I+} END; This week, for the first time, passing a bad file name to this file somehow closed standard output when the close(f) statement was run. A successive statement such as writeln('Hi') yeilds a runtime error 103 - file not open. I have gotten around the problem by placing an IF test in the function and not doing the close if the file was not properly opened. I am, however, intrigued by this phenomenon. The close(f) function should simply (with $I-) give an IOErorr, not screw other things up. Can anyone give some insight? -- Dick Harrigill, an independent voice from: Boeing Commercial Airplanes M/S 9R-49 PO BOX 3707 Renton Avionics/Flight Systems Seattle, WA 91824 Computing Support (206) 393-9539 rfh3273@galileo.rtn.ca.boeing.com
dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (05/14/91)
In article <382@galileo.rtn.ca.boeing.com> rfh3273@galileo.rtn.ca.boeing.com (Dick Harrigill) writes: >I've just experienced a strange error with TP6. I'm using a function >that I've successfully used for years to check the existance of a file: > > FUNCTION this_file_exists (VAR s:string) : boolean; > VAR f:file; > BEGIN > {$I-} > assign(f,s); reset(f); > this_file_exists:=(IOError=0); > close(f); > {$I+} > END; > >This week, for the first time, passing a bad file name to this file >somehow closed standard output when the close(f) statement was run. >A successive statement such as writeln('Hi') yeilds a runtime error >103 - file not open. If the file doesn't exist, the Close will fail - this will cause subsequent I/O requests to be ignored, because you didn't clear IOError. I imagine the problem in this case was that you tried a reset on output after running this function. It was ignored, so output stayed closed. Duncan Murdoch dmurdoch@watstat.wateroo.edu
terra@diku.dk (Morten Welinder) (05/14/91)
rfh3273@galileo.rtn.ca.boeing.com (Dick Harrigill) writes: >I've just experienced a strange error with TP6. I'm using a function >that I've successfully used for years to check the existance of a file: > FUNCTION this_file_exists (VAR s:string) : boolean; > VAR f:file; > BEGIN > {$I-} > assign(f,s); reset(f); > this_file_exists:=(IOError=0); > close(f); > {$I+} > END; >This week, for the first time, passing a bad file name to this file >somehow closed standard output when the close(f) statement was run. >A successive statement such as writeln('Hi') yeilds a runtime error >103 - file not open. I have gotten around the problem by placing an >IF test in the function and not doing the close if the file was not >properly opened. I am, however, intrigued by this phenomenon. The >close(f) function should simply (with $I-) give an IOErorr, not >screw other things up. Can anyone give some insight? a) close() is an error if the file is not open. b) try using GETFATTR to check if the file exists.