diff --git a/userspace/falco/CMakeLists.txt b/userspace/falco/CMakeLists.txt index 7b018446..adcd6168 100644 --- a/userspace/falco/CMakeLists.txt +++ b/userspace/falco/CMakeLists.txt @@ -42,6 +42,7 @@ add_executable(falco grpc_context.cpp grpc_server_impl.cpp grpc_server.cpp + utils.cpp ${CMAKE_CURRENT_BINARY_DIR}/falco_output.grpc.pb.cc ${CMAKE_CURRENT_BINARY_DIR}/falco_output.pb.cc) diff --git a/userspace/falco/utils.cpp b/userspace/falco/utils.cpp new file mode 100644 index 00000000..344539cb --- /dev/null +++ b/userspace/falco/utils.cpp @@ -0,0 +1,36 @@ +/* +Copyright (C) 2016-2019 The Falco Authors + +This file is part of falco. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include "utils.h" + +void falco::utils::read(const std::string& filename, std::string& data) +{ + std::ifstream file(filename.c_str(), std::ios::in); + + if(file.is_open()) + { + std::stringstream ss; + ss << file.rdbuf(); + + file.close(); + + data = ss.str(); + } + + return; +} diff --git a/userspace/falco/utils.h b/userspace/falco/utils.h new file mode 100644 index 00000000..cf466cd1 --- /dev/null +++ b/userspace/falco/utils.h @@ -0,0 +1,32 @@ +/* +Copyright (C) 2016-2019 The Falco Authors + +This file is part of falco. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#pragma once + +#include +#include +#include +#include + +namespace falco +{ +namespace utils +{ +void read(const std::string& filename, std::string& data); +} // namespace utils +} // namespace falco