• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "thermal_protector_util.h"
17 
18 #include <cstdio>
19 #include <cstdint>
20 #include <iosfwd>
21 #include <unistd.h>
22 #include "errors.h"
23 #include "thermal_log.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
WriteFile(std::string path,std::string buf,size_t size)27 int32_t ThermalProtectorUtil::WriteFile(std::string path, std::string buf, size_t size)
28 {
29     FILE *stream = fopen(path.c_str(), "w+");
30     if (stream == nullptr) {
31         return ERR_INVALID_VALUE;
32     }
33     size_t ret = fwrite(buf.c_str(), strlen(buf.c_str()), 1, stream);
34     if (ret == ERR_OK) {
35         THERMAL_HILOGE(FEATURE_PROTECTOR, "ret=%{public}zu", ret);
36     }
37     int32_t state = fseek(stream, 0, SEEK_SET);
38     if (state != ERR_OK) {
39         fclose(stream);
40         return state;
41     }
42     state = fclose(stream);
43     if (state != ERR_OK) {
44         return state;
45     }
46     return ERR_OK;
47 }
48 } // namespace PowerMgr
49 } // namespace OHOS
50