tw0754.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. program test_open_files;
  2. const
  3. MaxOpenTest = 150;
  4. var
  5. f : array [1..MaxOpenTest] of text;
  6. i,count : longint;
  7. error : word;
  8. s : string;
  9. storeexit : pointer;
  10. Max : longint;
  11. procedure Errorexit;
  12. begin
  13. exitproc:=storeexit;
  14. if errorcode=4 then
  15. begin
  16. if count<=15 then
  17. begin
  18. Writeln('The program could not open more than 15 files !');
  19. Writeln('Retry after addition of the following line to config.sys file');
  20. Writeln('FILES=60');
  21. Writeln('If it still does not work after this change');
  22. Writeln('you probably use a too old RTL version');
  23. Writeln('that does not support more than 15 files');
  24. Writeln('open at the same time');
  25. end
  26. else
  27. begin
  28. Writeln('The program was able to open ',count,' files simultaneously');
  29. Writeln('If you need to be able to have more opened files');
  30. Writeln('Try to increase the FILES=XX value in config.sys file');
  31. { This is not a RTL error anymore
  32. as we increased the size over the ordinary 15 limit }
  33. erroraddr:=nil;
  34. errorcode:=0;
  35. exitcode:=0;
  36. end;
  37. { close all left open files }
  38. for i:=count downto 1 do
  39. begin
  40. close(f[i]);
  41. erase(f[i]);
  42. end;
  43. end;
  44. end;
  45. begin
  46. StoreExit:=exitproc;
  47. ExitProc:=@ErrorExit;
  48. Max:=MaxOpenTest;
  49. if paramcount>0 then
  50. begin
  51. val(paramstr(1),count,error);
  52. if error = 0 then
  53. Max:=count;
  54. count:=0;
  55. end;
  56. for i:=1 to Max do
  57. begin
  58. str(i,s);
  59. s:='file'+s+'.tmp';
  60. assign(f[i],s);
  61. rewrite(f[i]);
  62. count:=i;
  63. Writeln(f[i],'This is file ',i);
  64. Writeln(i,' files open');
  65. { no closing so they are finally all open }
  66. end;
  67. for i:=Max downto 1 do
  68. begin
  69. close(f[i]);
  70. erase(f[i]);
  71. end;
  72. end.