add tmp_file/2

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2241 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc
2008-05-22 23:25:21 +00:00
parent 73cf1fbafa
commit a70fb91592
5 changed files with 83 additions and 7 deletions

View File

@@ -43,6 +43,7 @@
system/2,
mktime/2,
tmpnam/1,
tmp_file/2,
wait/2,
working_directory/2
]).
@@ -51,6 +52,8 @@
:- load_foreign_files([sys], [], init_sys).
:- dynamic tmp_file_sequence_counter/1.
% time builtins
datime(X) :-
@@ -398,7 +401,7 @@ shell(Command, Status) :-
do_shell(Shell, Opt, Command, Status, Error),
handle_system_error(Error, off, G).
protect_command([], [0'"]).
protect_command([], [0'"]). % "
protect_command([H|L], [H|NL]) :-
protect_command(L, NL).
@@ -493,3 +496,26 @@ mktemp(X,Y) :-
tmpnam(X) :-
tmpnam(X, Error),
handle_system_error(Error, off, tmpnam(X)).
tmp_file(Base,X) :-
var(Base), !,
throw(error(instantiation_error,tmp_file(Base,X))).
tmp_file(Base,X) :-
atom(Base), !,
tmpdir(Dir, Error),
handle_system_error(Error, off, tmp_file(Base,Error)),
pid(PID, Error),
handle_system_error(Error, off, tmp_file(Base,Error)),
tmp_file_sequence(I),
dir_separator(D),
atomic_concat([Dir,D,yap_,Base,'_',PID,'_',I],X).
tmp_file(Base,X) :-
throw(error(type_error(atom,Base),tmp_file(Base,X))).
tmp_file_sequence(X) :-
retract(tmp_file_sequence_counter(X)),
X1 is X+1,
assert(tmp_file_sequence_counter(X1)).
tmp_file_sequence(0) :-
assert(tmp_file_sequence_counter(1)).