t_badfile.mod 564 B

1234567891011121314151617
  1. MODULE TBadFile;
  2. // A failed file open returns NIL; file operations on it must degrade
  3. // safely (no SIGSEGV). The path below cannot be opened. Exit 42.
  4. IMPORT Files;
  5. VAR ExitCode : INTEGER;
  6. VAR f : Files.File;
  7. VAR n : INTEGER;
  8. BEGIN
  9. f := Files.OpenWrite("no/such/dir/_t_badfile.txt");
  10. Files.WriteChar(f, 'x'); (* NIL handle: must be a no-op *)
  11. Files.WriteInt(f, 123);
  12. Files.Close(f);
  13. f := Files.OpenRead("no/such/dir/_t_badfile.txt");
  14. n := Files.ReadInt(f); (* NIL handle: must return 0 *)
  15. Files.Close(f);
  16. ExitCode := 42
  17. END TBadFile.