Skip to content

Commit 1d84a5a

Browse files
committed
Add fs.cpp/h
backports bitcoin/bitcoin@19e36bb
1 parent 73d26f2 commit 1d84a5a

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ set(UTIL_SOURCES
505505
./src/compat/glibcxx_sanity.cpp
506506
./src/chainparamsbase.cpp
507507
./src/clientversion.cpp
508+
./src/fs.cpp
508509
./src/logging.cpp
509510
./src/random.cpp
510511
./src/rpc/protocol.cpp

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ BITCOIN_CORE_H = \
114114
addressbook.h \
115115
denomination_functions.h \
116116
wallet/db.h \
117+
fs.h \
117118
hash.h \
118119
httprpc.h \
119120
httpserver.h \
@@ -423,6 +424,7 @@ libbitcoin_util_a_SOURCES = \
423424
compat/glibc_sanity.cpp \
424425
compat/glibcxx_sanity.cpp \
425426
compat/strnlen.cpp \
427+
fs.cpp \
426428
logging.cpp \
427429
random.cpp \
428430
rpc/protocol.cpp \

src/fs.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) 2017-2020 The Bitcoin Core developers
2+
// Copyright (c) 2020 The PIVX developers
3+
// Distributed under the MIT/X11 software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#include "fs.h"
7+
8+
#include <boost/filesystem.hpp>
9+
10+
namespace fsbridge {
11+
12+
FILE *fopen(const fs::path& p, const char *mode)
13+
{
14+
return ::fopen(p.string().c_str(), mode);
15+
}
16+
17+
FILE *freopen(const fs::path& p, const char *mode, FILE *stream)
18+
{
19+
return ::freopen(p.string().c_str(), mode, stream);
20+
}
21+
22+
} // fsbridge

src/fs.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2017-2020 The Bitcoin Core developers
2+
// Copyright (c) 2020 The PIVX developers
3+
// Distributed under the MIT/X11 software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#ifndef BITCOIN_FS_H
7+
#define BITCOIN_FS_H
8+
9+
#include <stdio.h>
10+
#include <string>
11+
12+
#include <boost/filesystem.hpp>
13+
#include <boost/filesystem/fstream.hpp>
14+
#include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
15+
16+
/** Filesystem operations and types */
17+
namespace fs = boost::filesystem;
18+
19+
/** Bridge operations to C stdio */
20+
namespace fsbridge {
21+
FILE *fopen(const fs::path& p, const char *mode);
22+
FILE *freopen(const fs::path& p, const char *mode, FILE *stream);
23+
};
24+
25+
#endif

0 commit comments

Comments
 (0)