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 "create_stream_core.h" 17 18 #include <memory> 19 20 #include "file_utils.h" 21 #include "filemgmt_libhilog.h" 22 #include "fs_utils.h" 23 #include "stream_instantiator.h" 24 #include "stream_entity.h" 25 26 namespace OHOS { 27 namespace FileManagement { 28 namespace ModuleFileIO { 29 using namespace std; 30 DoCreateStream(const std::string & path,const std::string & mode)31FsResult<FsStream *> CreateStreamCore::DoCreateStream(const std::string &path, const std::string &mode) 32 { 33 FILE *file = fopen(path.c_str(), mode.c_str()); 34 if (!file) { 35 HILOGE("Failed to fopen file by path"); 36 return FsResult<FsStream *>::Error(errno); 37 } 38 39 return StreamInstantiator::InstantiateStream(move(file)); 40 } 41 42 } // namespace ModuleFileIO 43 } // namespace FileManagement 44 } // namespace OHOS