fixes and extensions to file_property

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@524 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2002-06-11 05:30:05 +00:00
parent 0871e5b323
commit a254dad245
4 changed files with 43 additions and 18 deletions

3
configure vendored
View File

@ -10186,7 +10186,8 @@ done
for ac_func in popen putenv rand random regexec
for ac_func in popen putenv rand random readlink regexec
do do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5 echo "$as_me:$LINENO: checking for $ac_func" >&5

View File

@ -777,7 +777,7 @@ AC_CHECK_FUNCS(gethostbyname gethostid gethostname)
AC_CHECK_FUNCS(gethrtime getpwnam getrusage gettimeofday getwd) AC_CHECK_FUNCS(gethrtime getpwnam getrusage gettimeofday getwd)
AC_CHECK_FUNCS(isatty isnan kill labs link localtime lstat) AC_CHECK_FUNCS(isatty isnan kill labs link localtime lstat)
AC_CHECK_FUNCS(memcpy memmove mkstemp mktemp mmap opendir) AC_CHECK_FUNCS(memcpy memmove mkstemp mktemp mmap opendir)
AC_CHECK_FUNCS(popen putenv rand random regexec) AC_CHECK_FUNCS(popen putenv rand random readlink regexec)
AC_CHECK_FUNCS(rename rint rl_set_prompt sbrk select) AC_CHECK_FUNCS(rename rint rl_set_prompt sbrk select)
AC_CHECK_FUNCS(setbuf setlinebuf shmat sigaction siggetmask siginterrupt) AC_CHECK_FUNCS(setbuf setlinebuf shmat sigaction siggetmask siginterrupt)
AC_CHECK_FUNCS(signal sigprocmask sleep snprintf socket stat) AC_CHECK_FUNCS(signal sigprocmask sleep snprintf socket stat)

View File

@ -82,7 +82,7 @@ process_delete_file_opts(Opts, _, _, _, T) :-
throw(error(domain_error(delete_file_option,Opts),T)). throw(error(domain_error(delete_file_option,Opts),T)).
delete_file(File, Dir, Recurse, Ignore) :- delete_file(File, Dir, Recurse, Ignore) :-
file_property(File, Type, _, _, _Permissions, Ignore), file_property(File, Type, _, _, _Permissions, _, Ignore),
delete_file(Type, File, Dir, Recurse, Ignore). delete_file(Type, File, Dir, Recurse, Ignore).
delete_file(N, File, _Dir, _Recurse, Ignore) :- number(N), !, % error. delete_file(N, File, _Dir, _Recurse, Ignore) :- number(N), !, % error.
@ -137,14 +137,19 @@ handle_system_error(Error, off, G) :-
throw(error(system_error(Message),G)). throw(error(system_error(Message),G)).
file_property(File, type(Type)) :- file_property(File, type(Type)) :-
file_property(File, Type, _Size, _Date). file_property(File, Type, _Size, _Date, _Permissions, _LinkName).
file_property(File, size(Size)) :- file_property(File, size(Size)) :-
file_property(File, _Type, Size, _Date). file_property(File, _Type, Size, _Date, _Permissions, _LinkName).
file_property(File, mod_time(Date)) :- file_property(File, mod_time(Date)) :-
file_property(File, _Type, _Size, Date). file_property(File, _Type, _Size, Date, _Permissions, _LinkName).
file_property(File, mode(Permissions)) :-
file_property(File, _Type, _Size, _Date, Permissions, _LinkName).
file_property(File, linkto(LinkName)) :-
file_property(File, _Type, _Size, _Date, _Permissions, LinkName),
atom(LinkName).
file_property(File, Type, Size, Date) :- file_property(File, Type, Size, Date, Permissions, LinkName) :-
file_property(File, Type, Size, Date, _Permissions, Error), file_property(File, Type, Size, Date, Permissions, LinkName, Error),
handle_system_error(Error, off, file_property(File)). handle_system_error(Error, off, file_property(File)).
file_exists(File) :- file_exists(File) :-
@ -154,7 +159,7 @@ file_exists(File) :-
\+ atom(File), !, \+ atom(File), !,
throw(error(type_error(atom,File),file_exists(File))). throw(error(type_error(atom,File),file_exists(File))).
file_exists(File) :- file_exists(File) :-
file_property(File, _Type, _Size, _Date, _Permissions, Error), file_property(File, _Type, _Size, _Date, _Permissions, _, Error),
var(Error). var(Error).
file_exists(File, Permissions) :- file_exists(File, Permissions) :-
@ -164,7 +169,7 @@ file_exists(File, Permissions) :-
\+ atom(File), !, \+ atom(File), !,
throw(error(type_error(atom,File),file_exists(File, Permissions))). throw(error(type_error(atom,File),file_exists(File, Permissions))).
file_exists(File, Permissions) :- file_exists(File, Permissions) :-
file_property(File, _Type, _Size, _Date, FPermissions, Error), file_property(File, _Type, _Size, _Date, FPermissions, _, Error),
var(Error), var(Error),
process_permissions(Permissions, Perms), process_permissions(Permissions, Perms),
FPermissions /\ Perms =:= Perms. FPermissions /\ Perms =:= Perms.

View File

@ -256,25 +256,44 @@ file_property(void)
fd = AtomName(AtomOfTerm(ARG1)); fd = AtomName(AtomOfTerm(ARG1));
if (lstat(fd, &buf) == -1) { if (lstat(fd, &buf) == -1) {
/* return an error number */ /* return an error number */
return(unify(ARG6, MkIntTerm(errno))); return(unify(ARG7, MkIntTerm(errno)));
} }
if (S_ISREG(buf.st_mode)) { if (S_ISREG(buf.st_mode)) {
if (!unify(ARG2, MkAtomTerm(LookupAtom("regular")))) if (!(unify(ARG2, MkAtomTerm(LookupAtom("regular"))) &&
unify(ARG6, YapMkIntTerm(0))))
return(FALSE); return(FALSE);
} else if (S_ISDIR(buf.st_mode)) { } else if (S_ISDIR(buf.st_mode)) {
if (!unify(ARG2, MkAtomTerm(LookupAtom("directory")))) if (!(unify(ARG2, MkAtomTerm(LookupAtom("directory"))) &&
unify(ARG6, YapMkIntTerm(0))))
return(FALSE); return(FALSE);
} else if (S_ISFIFO(buf.st_mode)) { } else if (S_ISFIFO(buf.st_mode)) {
if (!unify(ARG2, MkAtomTerm(LookupAtom("fifo")))) if (!(unify(ARG2, MkAtomTerm(LookupAtom("fifo"))) &&
unify(ARG6, YapMkIntTerm(0))))
return(FALSE); return(FALSE);
} else if (S_ISLNK(buf.st_mode)) { } else if (S_ISLNK(buf.st_mode)) {
if (!unify(ARG2, MkAtomTerm(LookupAtom("symlink")))) if (!unify(ARG2, MkAtomTerm(LookupAtom("symlink"))))
return(FALSE); return(FALSE);
#if HAVE_READLINK
{
char tmp[256];
if (readlink(fd,tmp,256) == -1) {
return(unify(ARG7, MkIntTerm(errno)));
}
if(!unify(ARG6,MkAtomTerm(LookupAtom(tmp)))) {
return(FALSE);
}
}
#else
if (!unify(ARG6, YapMkIntTerm(0)))
return(FALSE);
#endif
} else if (S_ISSOCK(buf.st_mode)) { } else if (S_ISSOCK(buf.st_mode)) {
if (!unify(ARG2, MkAtomTerm(LookupAtom("socket")))) if (!(unify(ARG2, MkAtomTerm(LookupAtom("socket"))) &&
unify(ARG6, YapMkIntTerm(0))))
return(FALSE); return(FALSE);
} else { } else {
if (!unify(ARG2, MkAtomTerm(LookupAtom("unknown")))) if (!(unify(ARG2, MkAtomTerm(LookupAtom("unknown"))) &&
unify(ARG6, YapMkIntTerm(0))))
return(FALSE); return(FALSE);
} }
#elif defined(__MINGW32__) || _MSC_VER #elif defined(__MINGW32__) || _MSC_VER
@ -284,7 +303,7 @@ file_property(void)
fd = AtomName(AtomOfTerm(ARG1)); fd = AtomName(AtomOfTerm(ARG1));
if (stat(fd, &buf) != 0) { if (stat(fd, &buf) != 0) {
/* return an error number */ /* return an error number */
return(unify(ARG6, MkIntTerm(errno))); return(unify(ARG7, MkIntTerm(errno)));
} }
if (buf.st_mode & S_IFREG) { if (buf.st_mode & S_IFREG) {
if (!unify(ARG2, MkAtomTerm(LookupAtom("regular")))) if (!unify(ARG2, MkAtomTerm(LookupAtom("regular"))))
@ -774,7 +793,7 @@ init_sys(void)
{ {
UserCPredicate("datime", datime, 2); UserCPredicate("datime", datime, 2);
UserCPredicate("list_directory", list_directory, 3); UserCPredicate("list_directory", list_directory, 3);
UserCPredicate("file_property", file_property, 6); UserCPredicate("file_property", file_property, 7);
UserCPredicate("unlink", p_unlink, 2); UserCPredicate("unlink", p_unlink, 2);
UserCPredicate("mkdir", p_mkdir, 2); UserCPredicate("mkdir", p_mkdir, 2);
UserCPredicate("rmdir", p_rmdir, 2); UserCPredicate("rmdir", p_rmdir, 2);