xref: /aosp_15_r20/external/executorch/backends/qualcomm/runtime/Utils.cpp (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright (c) Qualcomm Innovation Center, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 #include <executorch/backends/qualcomm/runtime/Logging.h>
9 #include <executorch/backends/qualcomm/runtime/Utils.h>
10 #include <sys/stat.h>
11 namespace executorch {
12 namespace backends {
13 namespace qnn {
14 
CreateDirectory(const std::string & path)15 void CreateDirectory(const std::string& path) {
16   // Create any recursive directory
17   if (path.empty()) {
18     QNN_EXECUTORCH_LOG_ERROR("Create folder shouldn't be empty");
19     return;
20   }
21   std::size_t pos = path.find_last_of('/');
22   std::string subdir = (std::string::npos == pos) ? "" : path.substr(0, pos);
23   if (subdir.empty() || subdir == "." || subdir == "..") {
24     return;
25   }
26   CreateDirectory(subdir);
27   int mkdir_err = mkdir(subdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
28   if (mkdir_err != 0 && errno != EEXIST) {
29     std::string err_msg = "Failed to create " + subdir + " folder\n";
30     QNN_EXECUTORCH_LOG_ERROR(err_msg.c_str());
31   }
32 }
33 
34 } // namespace qnn
35 } // namespace backends
36 } // namespace executorch
37