• 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_ani.h"
17 
18 #include <string>
19 
20 #include "error_handler.h"
21 #include "filemgmt_libhilog.h"
22 #include "mkdtemp_core.h"
23 #include "type_converter.h"
24 
25 namespace OHOS {
26 namespace FileManagement {
27 namespace ModuleFileIO {
28 namespace ANI {
29 
MkdtempSync(ani_env * env,ani_class clazz,ani_string prefix)30 ani_string MkdtempAni::MkdtempSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string prefix)
31 {
32     auto [succPath, prefixPath] = TypeConverter::ToUTF8String(env, prefix);
33     if (!succPath) {
34         HILOGE("Invalid path");
35         ErrorHandler::Throw(env, EINVAL);
36         return nullptr;
37     }
38 
39     auto ret = MkdtempCore::DoMkdtemp(prefixPath);
40     if (!ret.IsSuccess()) {
41         HILOGE("Mkdtemp failed");
42         const auto &err = ret.GetError();
43         ErrorHandler::Throw(env, err);
44         return nullptr;
45     }
46 
47     const auto &res = ret.GetData().value();
48     auto [succ, result] = TypeConverter::ToAniString(env, res);
49     if (!succ) {
50         HILOGE("Create ani_string error");
51         ErrorHandler::Throw(env, UNKNOWN_ERR);
52         return nullptr;
53     }
54     return result;
55 }
56 
57 } // namespace ANI
58 } // namespace ModuleFileIO
59 } // namespace FileManagement
60 } // namespace OHOS
61