Debian Codegraph @

FaCT++.Python/lib/Kernel/dir_util.cpp

raw
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2014-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include <cerrno>
21 #include <sys/stat.h>
22
23 #include "dir_util.h"
24
25 // MinGW GCC up to version 6.2 does not have permissions parameter in mkdir()
26 #if defined(__MINGW32__) || defined(__MINGW64__)
27 # define mkdir(path, permissions) mkdir(path)
28 #endif
29
30 /// create a directory by a path; @return 0 if success, -1 if not
31 int dirCreate ( const char *path )
32 {
33 struct stat st;
34 int status = 0;
35 #ifndef _MSC_VER
36 if (stat(path, &st) != 0)
37 {
38 /* Directory does not exist. EEXIST for race condition */
39 if (mkdir(path, 0777) != 0 && errno != EEXIST)
40 status = -1;
41 }
42 else if (!S_ISDIR(st.st_mode))
43 {
44 errno = ENOTDIR;
45 status = -1;
46 }
47 #endif
48 return status;
49 }
50