mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 18:03:36 +00:00
library/io.file.m:
library/io.m:
Move two sections of io.m, the "file handling predicates" section
and the "handling temporary files" section to the new submodule io.file.m.
Leave behind in io.m "forwarding predicates", predicates that do nothing
except call the moved predicates in io.file.m, to provide backward
compatibility. But do mark the forwarding predicates as obsolete,
to tell people to update their (at their leisure, since the obsoleteness
warning can be turned off).
Also leave behind in io.m the definitions of the two types used
by some parameters of some of the moved predicates. Document the reason
why this is done.
library/MODULES_DOC:
List the new module among the documented modules.
NEWS:
Announce the changes.
browser/browse.m:
browser/interactive_query.m:
browser/listing.m:
compiler/analysis.file.m:
compiler/compile_target_code.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/parse_module.m:
compiler/passes_aux.m:
compiler/prog_event.m:
compiler/recompilation.check.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
library/dir.m:
mdbcomp/program_representation.m:
ssdb/ssdb.m:
Call the file operation predicates directly in io.file.m, not indirectly
through io.m.
In two modules, add a #include of fcntl.h in C code. These modules contain
C code that needs this #include, but until now, they got it via a copy
in an automatically generated C header file of a foreign_decl pragma
in io.m that contained that #include. This diff moves that foreign_decl
to io.file.m, removing that crutch.
tests/debugger/browser_test.m:
tests/hard_coded/bit_buffer_test.m:
tests/hard_coded/bitmap_test.m:
tests/hard_coded/construct_bug.m:
tests/hard_coded/dir_fold.m:
tests/hard_coded/dir_test.m:
tests/hard_coded/read_binary_int16.m:
tests/hard_coded/read_binary_int32.m:
tests/hard_coded/read_binary_int64.m:
tests/hard_coded/read_binary_uint16.m:
tests/hard_coded/read_binary_uint32.m:
tests/hard_coded/read_binary_uint64.m:
tests/hard_coded/read_bitmap_size.m:
tests/hard_coded/remove_file.m:
tests/hard_coded/write_binary.m:
tests/hard_coded/write_binary_int8.m:
tests/hard_coded/write_binary_multibyte_int.m:
tests/hard_coded/write_binary_uint8.m:
Call the file operation predicates directly in io.file.m, not indirectly
through io.m.
77 lines
2.6 KiB
Mathematica
77 lines
2.6 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% If this test fails when run natively under Win32 (no cygwin) then make
|
|
% sure that either the TMPDIR environment variable points somewhere
|
|
% sensible or that a directory <drive letter>:\tmp exists.
|
|
%
|
|
% The .exp file is for the C backends.
|
|
% The .exp3 file is for the Java backend.
|
|
% The .exp4 file is for the C# backend.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module remove_file.
|
|
:- interface.
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module exception.
|
|
:- import_module io.file.
|
|
|
|
main(!IO) :-
|
|
io.file.make_temp_file(NameResult, !IO),
|
|
(
|
|
NameResult = ok(Name)
|
|
;
|
|
NameResult = error(Error),
|
|
throw(Error)
|
|
),
|
|
%%%%%%% io.print("Temp file name = ", !IO), io.print_line(Name, !IO),
|
|
io.open_output(Name, OpenOutputResult, !IO),
|
|
(
|
|
OpenOutputResult = io.ok(Stream),
|
|
io.print_line(Stream, "Just testing", !IO),
|
|
io.close_output(Stream, !IO),
|
|
io.file.remove_file(Name, RemoveResult, !IO),
|
|
(
|
|
RemoveResult = io.ok,
|
|
io.open_input(Name, OpenInputResult, !IO),
|
|
(
|
|
OpenInputResult = io.ok(_Stream),
|
|
io.print("Remove didn't remove file\n", !IO),
|
|
io.set_exit_status(1, !IO)
|
|
;
|
|
OpenInputResult = io.error(_),
|
|
io.print("Test passed\n", !IO)
|
|
)
|
|
;
|
|
RemoveResult = io.error(RemoveError),
|
|
io.print("Remove failed: ", !IO),
|
|
io.error_message(RemoveError, RemoveErrorMsg),
|
|
io.print_line(RemoveErrorMsg, !IO),
|
|
io.set_exit_status(1, !IO)
|
|
),
|
|
io.file.remove_file(Name, RemoveAgainResult, !IO),
|
|
(
|
|
RemoveAgainResult = io.ok,
|
|
io.print("Second remove didn't report failure\n", !IO),
|
|
io.set_exit_status(1, !IO)
|
|
;
|
|
RemoveAgainResult = io.error(RemoveAgainError),
|
|
io.print("Second remove failed, as expected: ", !IO),
|
|
io.error_message(RemoveAgainError, RemoveAgainErrorMsg),
|
|
io.print_line(RemoveAgainErrorMsg, !IO)
|
|
)
|
|
;
|
|
OpenOutputResult = io.error(OpenOutputError),
|
|
io.print("Open for output failed: ", !IO),
|
|
io.error_message(OpenOutputError, OpenOutputErrorMsg),
|
|
io.print_line(OpenOutputErrorMsg, !IO),
|
|
io.set_exit_status(1, !IO)
|
|
).
|