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