Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of fc/io/fstream.hpp #2047

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions libraries/plugins/witness/witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ void witness_plugin::plugin_initialize(const boost::program_options::variables_m
{
if (fc::exists(key_id_to_wif_pair_file))
{
std::ifstream file_content_as_stream( key_id_to_wif_pair_file.string() );
FC_ASSERT( !file_content_as_stream.fail() && !file_content_as_stream.bad(),
"Failed to open file '${f}'", ("f",key_id_to_wif_pair_file.string()) );
std::ifstream file_content_as_stream( key_id_to_wif_pair_file.string() );
FC_ASSERT( !file_content_as_stream.fail() && !file_content_as_stream.bad(),
"Failed to open file '${f}'", ("f",key_id_to_wif_pair_file.string()) );

std::string line; // key_id_to_wif_pair_string
while (std::getline(file_content_as_stream, line))
Expand Down
2 changes: 1 addition & 1 deletion libraries/utilities/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <fc/exception/exception.hpp>

#include <ios>
#include <istream>
#include <fstream>

namespace graphene { namespace utilities {

Expand Down
10 changes: 7 additions & 3 deletions libraries/utilities/include/graphene/utilities/file_util.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma once

/*
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
*
Expand All @@ -23,12 +21,18 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once

#include <fstream>
#include <string>

namespace graphene { namespace utilities {

/**
* @brief Reads the file at the given path and returns the full contents in a string. Note that the result
* will contain non-printable characters if the file does.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I saw "non-printable characters", '\0' didn't come to my mind. I don't know whether it's only me though. Perhaps better if we explicitly mention '\0'? Callers need to be careful when using this function, since functions like c_str() are heavily used in the code base, a strcpy() or strlen() call on the result of c_str() may return unexpected results.

* @param path the pathname of the file to read
* @return the file contents as a string
*/
std::string read_file_contents( const std::string& path );

} } // graphene::utilities