[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / lib / std / cbits / removeFile.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
3 %
4 \subsection[removeFile.lc]{removeFile Runtime Support}
5
6 \begin{code}
7
8 #include "rtsdefs.h"
9 #include "stgio.h"
10
11 #ifdef HAVE_SYS_TYPES_H
12 #include <sys/types.h>
13 #endif
14
15 #ifdef HAVE_SYS_STAT_H
16 #include <sys/stat.h>
17 #endif
18
19 StgInt
20 removeFile(path)
21 StgByteArray path;
22 {
23     struct stat sb;
24
25     /* Check for a non-directory */
26     while (stat(path, &sb) != 0) {
27         if (errno != EINTR) {
28             cvtErrno();
29             stdErrno();
30             return -1;
31         }
32     }
33     if (S_ISDIR(sb.st_mode)) {
34         ghc_errtype = ERR_INAPPROPRIATETYPE;
35         ghc_errstr = "file is a directory";
36         return -1;
37     }
38     while (unlink(path) != 0) {
39         if (errno != EINTR) {
40             cvtErrno();
41             stdErrno();
42             return -1;
43         }
44     }
45     return 0;
46 }
47
48 \end{code}