--- /dev/null
+%
+% (c) The GRASP/AQUA Project, Glasgow University, 1998
+%
+\subsection[directoryAux.lc]{Support functions for manipulating directories}
+
+\begin{code}
+
+#include "rtsdefs.h"
+#include "stgio.h"
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+
+StgAddr
+openDir__(path)
+StgByteArray path;
+{
+ struct stat sb;
+ DIR *dir;
+
+ /* Check for an actual directory */
+ while (stat(path, &sb) != 0) {
+ if (errno != EINTR) {
+ cvtErrno();
+ stdErrno();
+ return NULL;
+ }
+ }
+ if (!S_ISDIR(sb.st_mode)) {
+ ghc_errtype = ERR_INAPPROPRIATETYPE;
+ ghc_errstr = "not a directory";
+ return NULL;
+ }
+
+ while ((dir = opendir(path)) == NULL) {
+ if (errno != EINTR) {
+ cvtErrno();
+ stdErrno();
+ return NULL;
+ }
+ }
+ return dir;
+}
+
+StgAddr
+readDir__(dir)
+StgAddr dir;
+{
+ struct dirent *d;
+ while ((d = readdir((DIR*)dir)) == NULL) {
+ if (errno == 0) {
+ (void) closedir((DIR*)dir);
+ return NULL;
+ } else if (errno != EINTR) {
+ cvtErrno();
+ stdErrno();
+ (void) closedir((DIR*)dir);
+ return 1;
+ }
+ errno = 0;
+ }
+ return d;
+}
+
+\end{code}