With ghc-2.08 under x86_Solaris2.5.1, the included program, "lc_1f.hs", failed to
execute due to the following troubles:
(1) A bug in cbits/getDirectoryContents.lc
# Sorry, if this bug has already been reported.
The fix is included.
(2) "doesDirectoryExist" failed due to EVERFLOW.
I'm not sure why this trouble happened, but the function failed to execute
because of an internal error: according to the report generated by the "truss"
command, the stat(2) system call often failed because of EOVERFLOW.
After several trials, I found that the _casm_ calling had not worked as expected.
I avoided the trouble by replacing direct calling of stat(2) with indirect
calling:
- Add "cstat.lc" under ghc/lib/cbits (see below) to define cstat(), and
- Modify "ghc/lib/required/Directorry.lhs" so that it calls stat()
indirectly through cstat().
Did I overlook anything important? I appreciate it if someone could
explain what is really happening in my environment.
Thanks in advance.
----
Yoshihiko Ichikawa, Dept of Info Sci, Fac of Sci, Ochanomizu University
Phone: +81-3-5978-5708 (Dial-in) / +81-3-5978-5704 (Library of Department)
Fax: +81-3-5978-5898 (Faculty) / +81-3-5878-5705 (Library of Department)
E-mail: [EMAIL PROTECTED]
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A. ls_1f.hs
module Main(main) where
import IO
import System
import Directory
import Monad
main = do comname <- getProgName
argv <- getArgs
let argc = length argv
unless (argc == 1) (
error $ "Usage: " ++ comname ++ " <directory>.\n" )
let dname = argv !! 0
b <- doesDirectoryExist dname
unless b ( error $ "Error: " ++ dname ++ " does not exist.\n" )
dols dname
return ()
dols dname
= do entries <- getDirectoryContents dname
setCurrentDirectory dname
sequence (map doEntry entries)
doEntry entry
= do perm <- getPermissions entry
let permString = show perm
putStr (permString ++ " " ++ entry ++ "\n")
B. The bug fix.
-------%< ghc/lib/cbits/getDirectoryContents fix ---------------------
*** getDirectoryContents.lc.OLD Thu Nov 20 18:00:09 1997
--- getDirectoryContents.lc Thu Nov 20 18:00:14 1997
***************
*** 102,104 ****
}
! if ((entries[count] = malloc(strlen(d->d_name))) == NULL) {
ghc_errtype = ERR_RESOURCEEXHAUSTED;
--- 102,104 ----
}
! if ((entries[count] = malloc(strlen(d->d_name)+1)) == NULL) {
ghc_errtype = ERR_RESOURCEEXHAUSTED;
----------------------------------------------------------------------
C. ghc/lib/cbits/cstat.lhs
\begin{code}
#include <sys/types.h>
#include <sys/stat.h>
int cstat(char *path, struct stat *st)
{
return stat(path, st);
}
\end{code}