Debian Codegraph @

src/helper/sysctl/sysfswriter.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/helper/sysctl/sysfswriter.cpp`/
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "sysfswriter.h"cxx . . $ `<file>/src/helper/sysctl/sysfswriter.h`/
5
6 #include "common/fileutils.h"cxx . . $ `<file>/src/common/fileutils.h`/
7 #include <exception>
8 #include <fstream>
9 #include <spdlog/spdlog.h>
10
11 void SysfsWritercxx . . $ SysfsWriter#::writecxx . . $ SysfsWriter#write(b03b73af961d2abd).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const &sysfsEntry,
12 stdcxx . . $ std/::stringcxx . . $ std/string# const &value)
13 {
14 if (!Utilscxx . . $ Utils/::Filecxx . . $ Utils/File/::isFilePathValidcxx . . $ Utils/File/isFilePathValid(c53a6ef3278968b1).(sysfsEntry)) {
15 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Invalid file path {}", sysfsEntry.c_str());
16 return;
17 }
18
19 if (!isSysfsPathcxx . . $ SysfsWriter#isSysfsPath(ff86b37421e90a61).(sysfsEntry)) {
20 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("{} is not a sysfs path. Value {} wont be written.",
21 sysfsEntry.c_str(), value);
22 return;
23 }
24
25 stdcxx . . $ std/::ofstreamcxx . . $ std/ofstream# filecxx . . $ std/basic_ofstream#basic_ofstream(fbe7c9ddfb647a62).(sysfsEntry);
26 if (!file.is_opencxx . . $ std/basic_ofstream#is_open(c9857a73d68e59ba).()) {
27 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!("Cannot write {} to file {}", value, sysfsEntry.c_str());
28 return;
29 }
30
31 file <<cxx . . $ std/`operator<<`(88df5bef833f7f83). value <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).;
32 }
33
34 bool SysfsWritercxx . . $ SysfsWriter#::isSysfsPathcxx . . $ SysfsWriter#isSysfsPath(ff86b37421e90a61).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const &path) const
35 {
36 try {
37 // check whether canonical path starts with '/sys'
38 return stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::canonicalcxx . . $ std/filesystem/canonical(4ac62a867fe4334a).(path).stringcxx . . $ std/filesystem/__cxx11/path#string(219584694fe2b248).().comparecxx . . $ std/__cxx11/basic_string#compare(f138d8d51614b466).(
39 0, sysfsPathcxx . . $ SysfsWriter#sysfsPath..lengthcxx . . $ std/basic_string_view#length(c9b1e749b64d5edc).(), sysfsPathcxx . . $ SysfsWriter#sysfsPath.) == 0;
40 }
41 catch (stdcxx . . $ std/::exception const &e) {
42 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!(e.what());
43 }
44 return false;
45 }