[project @ 1998-11-26 09:17:22 by sof]
[ghc-hetmet.git] / ghc / lib / std / cbits / renameDirectory.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
3 %
4 \subsection[renameDirectory.lc]{renameDirectory 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 renameDirectory(opath, npath)
21 StgByteArray opath;
22 StgByteArray npath;
23 {
24     struct stat sb;
25
26     /* Check for an actual directory */
27     while (stat(opath, &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 = "not a directory";
37         return -1;
38     }
39     while(rename(opath, npath) != 0) {
40         if (errno != EINTR) {
41             cvtErrno();
42             stdErrno();
43             return -1;
44         }
45     }
46     return 0;
47 }
48 \end{code}