1  
//
1  
//
2  
// Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/cppalliance/http
7  
// Official repository: https://github.com/cppalliance/http
8  
//
8  
//
9  

9  

10  
#ifndef BOOST_HTTP_DETAIL_FILE_STDIO_HPP
10  
#ifndef BOOST_HTTP_DETAIL_FILE_STDIO_HPP
11  
#define BOOST_HTTP_DETAIL_FILE_STDIO_HPP
11  
#define BOOST_HTTP_DETAIL_FILE_STDIO_HPP
12  

12  

13  
#include <boost/http/detail/config.hpp>
13  
#include <boost/http/detail/config.hpp>
14  
#include <boost/http/error.hpp>
14  
#include <boost/http/error.hpp>
15  
#include <boost/http/file_mode.hpp>
15  
#include <boost/http/file_mode.hpp>
16  
#include <cstdio>
16  
#include <cstdio>
17  
#include <cstdint>
17  
#include <cstdint>
18  

18  

19  
namespace boost {
19  
namespace boost {
20  
namespace http {
20  
namespace http {
21  
namespace detail {
21  
namespace detail {
22  

22  

23  
// Implementation of File which uses cstdio.
23  
// Implementation of File which uses cstdio.
24  
class file_stdio
24  
class file_stdio
25  
{
25  
{
26  
    std::FILE* f_ = nullptr;
26  
    std::FILE* f_ = nullptr;
27  

27  

28  
public:
28  
public:
29  
    using native_handle_type = std::FILE*;
29  
    using native_handle_type = std::FILE*;
30  

30  

31  
    BOOST_HTTP_DECL
31  
    BOOST_HTTP_DECL
32  
    ~file_stdio();
32  
    ~file_stdio();
33  

33  

34  
    file_stdio() = default;
34  
    file_stdio() = default;
35  

35  

36  
    BOOST_HTTP_DECL
36  
    BOOST_HTTP_DECL
37  
    file_stdio(file_stdio&& other) noexcept;
37  
    file_stdio(file_stdio&& other) noexcept;
38  

38  

39  
    BOOST_HTTP_DECL
39  
    BOOST_HTTP_DECL
40  
    file_stdio&
40  
    file_stdio&
41  
    operator=(file_stdio&& other) noexcept;
41  
    operator=(file_stdio&& other) noexcept;
42  

42  

43  
    std::FILE*
43  
    std::FILE*
44  
    native_handle() const
44  
    native_handle() const
45  
    {
45  
    {
46  
        return f_;
46  
        return f_;
47  
    }
47  
    }
48  

48  

49  
    BOOST_HTTP_DECL
49  
    BOOST_HTTP_DECL
50  
    void
50  
    void
51  
    native_handle(std::FILE* f);
51  
    native_handle(std::FILE* f);
52  

52  

53  
    bool
53  
    bool
54  
    is_open() const
54  
    is_open() const
55  
    {
55  
    {
56  
        return f_ != nullptr;
56  
        return f_ != nullptr;
57  
    }
57  
    }
58  

58  

59  
    BOOST_HTTP_DECL
59  
    BOOST_HTTP_DECL
60  
    void
60  
    void
61  
    close(system::error_code& ec);
61  
    close(system::error_code& ec);
62  

62  

63  
    BOOST_HTTP_DECL
63  
    BOOST_HTTP_DECL
64  
    void
64  
    void
65  
    open(char const* path, file_mode mode, system::error_code& ec);
65  
    open(char const* path, file_mode mode, system::error_code& ec);
66  

66  

67  
    BOOST_HTTP_DECL
67  
    BOOST_HTTP_DECL
68  
    std::uint64_t
68  
    std::uint64_t
69  
    size(system::error_code& ec) const;
69  
    size(system::error_code& ec) const;
70  

70  

71  
    BOOST_HTTP_DECL
71  
    BOOST_HTTP_DECL
72  
    std::uint64_t
72  
    std::uint64_t
73  
    pos(system::error_code& ec) const;
73  
    pos(system::error_code& ec) const;
74  

74  

75  
    BOOST_HTTP_DECL
75  
    BOOST_HTTP_DECL
76  
    void
76  
    void
77  
    seek(std::uint64_t offset, system::error_code& ec);
77  
    seek(std::uint64_t offset, system::error_code& ec);
78  

78  

79  
    BOOST_HTTP_DECL
79  
    BOOST_HTTP_DECL
80  
    std::size_t
80  
    std::size_t
81  
    read(void* buffer, std::size_t n, system::error_code& ec);
81  
    read(void* buffer, std::size_t n, system::error_code& ec);
82  

82  

83  
    BOOST_HTTP_DECL
83  
    BOOST_HTTP_DECL
84  
    std::size_t
84  
    std::size_t
85  
    write(void const* buffer, std::size_t n, system::error_code& ec);
85  
    write(void const* buffer, std::size_t n, system::error_code& ec);
86  
};
86  
};
87  

87  

88  
} // detail
88  
} // detail
89  
} // http
89  
} // http
90  
} // boost
90  
} // boost
91  

91  

92  
#endif
92  
#endif