[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / lib / std / cbits / renameDirectory.c
1 /* 
2  * (c) The GRASP/AQUA Project, Glasgow University, 1994-1998
3  *
4  * $Id: renameDirectory.c,v 1.3 1998/12/02 13:27:50 simonm Exp $
5  *
6  * renameDirectory 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 renameDirectory(opath, npath)
22 StgByteArray opath;
23 StgByteArray npath;
24 {
25     struct stat sb;
26
27     /* Check for an actual directory */
28     while (stat(opath, &sb) != 0) {
29         if (errno != EINTR) {
30             cvtErrno();
31             stdErrno();
32             return -1;
33         }
34     }
35     if (!S_ISDIR(sb.st_mode)) {
36         ghc_errtype = ERR_INAPPROPRIATETYPE;
37         ghc_errstr = "not a directory";
38         return -1;
39     }
40     while(rename(opath, npath) != 0) {
41         if (errno != EINTR) {
42             cvtErrno();
43             stdErrno();
44             return -1;
45         }
46     }
47     return 0;
48 }