1 /*
2 Copyright 2019-2020 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
7 */
8 #ifndef BOOST_IO_DETAIL_BUFFER_FILL_HPP
9 #define BOOST_IO_DETAIL_BUFFER_FILL_HPP
10
11 #include <iosfwd>
12 #include <cstddef>
13
14 namespace boost {
15 namespace io {
16 namespace detail {
17
18 template<class charT, class traits>
19 inline bool
buffer_fill(std::basic_streambuf<charT,traits> & buf,charT ch,std::size_t size)20 buffer_fill(std::basic_streambuf<charT, traits>& buf, charT ch,
21 std::size_t size)
22 {
23 charT fill[] = { ch, ch, ch, ch, ch, ch, ch, ch };
24 enum {
25 chunk = sizeof fill / sizeof(charT)
26 };
27 for (; size > chunk; size -= chunk) {
28 if (static_cast<std::size_t>(buf.sputn(fill, chunk)) != chunk) {
29 return false;
30 }
31 }
32 return static_cast<std::size_t>(buf.sputn(fill, size)) == size;
33 }
34
35 } /* detail */
36 } /* io */
37 } /* boost */
38
39 #endif
40