MYNT EYE D SDK  1.7.1
http://www.myntai.com/mynteye/depth
files.h
1 // Copyright 2018 Slightech Co., Ltd. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #ifndef MYNTEYE_UTILS_FILES_H_
15 #define MYNTEYE_UTILS_FILES_H_
16 
17 #include "mynteyed/stubs/global.h"
18 #include "mynteyed/util/strings.h"
19 
20 #if defined(MYNTEYE_OS_WIN) && !defined(MYNTEYE_OS_MINGW) \
21  && !defined(MYNTEYE_OS_CYGWIN)
22 #include <direct.h>
23 #else
24 #include <sys/stat.h>
25 #endif
26 
27 #include <string>
28 
29 MYNTEYE_BEGIN_NAMESPACE
30 
31 namespace files {
32 
33 bool _mkdir(const std::string &path) {
34 #if defined(MYNTEYE_OS_MINGW) || defined(MYNTEYE_OS_CYGWIN)
35  const int status = ::mkdir(path.c_str());
36 #elif defined(MYNTEYE_OS_WIN)
37  const int status = ::_mkdir(path.c_str());
38 #else
39  const int status =
40  mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
41 #endif
42 
43  if (status != 0 && errno != EEXIST) {
44  // std::cout << "Create directory failed (status " << status
45  // << "), path: " << path << std::endl;
46  return false;
47  }
48  if (errno == EEXIST) {
49  // std::cout << "Create directory needless" <<
50  // "(already exist), path: " << path << std::endl;
51  return true;
52  } else {
53  // std::cout << "Create directory success, path: " <<
54  // path << std::endl;
55  return true;
56  }
57 }
58 
59 bool mkdir(const std::string &path) {
60  auto &&dirs = strings::split(path, MYNTEYE_OS_SEP);
61  auto &&size = dirs.size();
62  if (size <= 0)
63  return false;
64  std::string p{dirs[0]};
65  if (!_mkdir(p))
66  return false;
67  for (std::size_t i = 1; i < size; i++) {
68  p.append(MYNTEYE_OS_SEP).append(dirs[i]);
69  if (!_mkdir(p))
70  return false;
71  }
72  return true;
73 }
74 
75 } // namespace files
76 
77 MYNTEYE_END_NAMESPACE
78 
79 #endif // MYNTEYE_UTILS_FILES_H_