• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
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  */
15 
16 #include "mkdtemp_core.h"
17 
18 #include "file_utils.h"
19 #include "filemgmt_libhilog.h"
20 
21 namespace OHOS {
22 namespace FileManagement {
23 namespace ModuleFileIO {
24 using namespace std;
25 
DoMkdtemp(const string & path)26 FsResult<string> MkdtempCore::DoMkdtemp(const string &path)
27 {
28     unique_ptr<uv_fs_t, decltype(FsUtils::FsReqCleanup) *> mkdtempReq = { new uv_fs_t, FsUtils::FsReqCleanup };
29     if (!mkdtempReq) {
30         HILOGE("Failed to request heap memory.");
31         return FsResult<string>::Error(ENOMEM);
32     }
33     int ret = uv_fs_mkdtemp(nullptr, mkdtempReq.get(), const_cast<char *>(path.c_str()), nullptr);
34     if (ret < 0) {
35         HILOGE("Failed to create a temporary directory with path");
36         return FsResult<string>::Error(ret);
37     }
38 
39     return FsResult<string>::Success(move(mkdtempReq->path));
40 }
41 
42 } // namespace ModuleFileIO
43 } // namespace FileManagement
44 } // namespace OHOS
45