]> git.lyx.org Git - lyx.git/blob - src/support/mkdir.C
Fix several filename and environment variable encoding problems
[lyx.git] / src / support / mkdir.C
1 /**
2  * \file mkdir.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "support/lyxlib.h"
14 #include "support/filename.h"
15
16 #ifdef HAVE_SYS_STAT_H
17 # include <sys/stat.h>
18 #endif
19 #ifdef HAVE_SYS_TYPES_H
20 # include <sys/types.h>
21 #endif
22 #include <fcntl.h>
23 #ifdef HAVE_UNISTD_H
24 # include <unistd.h>
25 #endif
26 #ifdef HAVE_DIRECT_H
27 # include <direct.h>
28 #endif
29 #ifdef _WIN32
30 # include <windows.h>
31 #endif
32
33 namespace lyx {
34 namespace support {
35
36
37 int mkdir(FileName const & pathname, unsigned long int mode)
38 {
39         // FIXME: why don't we have mode_t in lyx::mkdir prototype ??
40 #if HAVE_MKDIR
41 # if MKDIR_TAKES_ONE_ARG
42         // MinGW32
43         return ::mkdir(pathname.toFilesystemEncoding().c_str());
44 #  ifdef WITH_WARNINGS
45 #   warning "Permissions of created directories are ignored on this system."
46 #  endif
47 # else
48         // POSIX
49         return ::mkdir(pathname.toFilesystemEncoding().c_str(), mode_t(mode));
50 # endif
51 #elif defined(_WIN32)
52         // plain Windows 32
53         return CreateDirectory(pathname.toFilesystemEncoding().c_str(), 0) != 0 ? 0 : -1;
54 # ifdef WITH_WARNINGS
55 #  warning "Permissions of created directories are ignored on this system."
56 # endif
57 #elif HAVE__MKDIR
58         return ::_mkdir(pathname.toFilesystemEncoding().c_str());
59 # ifdef WITH_WARNINGS
60 #  warning "Permissions of created directories are ignored on this system."
61 # endif
62 #else
63 #   error "Don't know how to create a directory on this system."
64 #endif
65 }
66
67
68 } // namespace support
69 } // namespace lyx