1/*
2 * Copyright (c) 2015, PHILIPPE TILLET. All rights reserved.
3 *
4 * This file is part of ISAAC.
5 *
6 * ISAAC is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#ifndef TDL_TOOLS_SYS_MKDIR_HPP
23#define TDL_TOOLS_SYS_MKDIR_HPP
24
25#include <cstring>
26#include <string>
27#include <cstdlib>
28#include <sys/stat.h>
29#include <errno.h>
30#if defined(_WIN32)
31 #include <direct.h>
32#endif
33
34namespace triton
35{
36
37namespace tools
38{
39
40 inline int mkdir(std::string const & path)
41 {
42 #if defined(_WIN32)
43 return _mkdir(path.c_str());
44 #else
45 return ::mkdir(path.c_str(), 0777);
46 #endif
47 }
48
49 inline int mkpath(std::string const & path)
50 {
51 int status = 0;
52 size_t pp = 0;
53 size_t sp;
54 while ((sp = path.find('/', pp)) != std::string::npos)
55 {
56 if (sp != pp){
57 status = mkdir(path.substr(0, sp));
58 }
59 pp = sp + 1;
60 }
61 return (status==0 || errno==EEXIST)?0:-1;
62 }
63
64 inline int mtime(std::string const & path)
65 {
66 struct stat st;
67 if(stat(path.c_str(), &st) != 0)
68 return 0;
69 return st.st_mtime;
70 }
71
72}
73
74}
75
76#endif
77