Opened 9 years ago

#9297 new Bugs

"boost::iostreams::file_descriptor_sink" doesn't support translation of line endings on Windows

Reported by: m.kosch@… Owned by: Jonathan Turkanis
Milestone: To Be Determined Component: iostreams
Version: Boost 1.54.0 Severity: Problem
Keywords: file_descriptor_sink Cc: m.kosch@…

Description

When a Windows file descriptor is opened in text mode, all newline characters written to this file are translated to CRLF. However, if boost::iostreams::file_descriptor_sink is used on such a file descriptor to write newlines to a stream, these newline characters are not translated to CRLF.

The following sample program demonstrates this:

#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <fcntl.h>
#include <io.h>
#include <string>
#include <sys/stat.h>


int main()
{
    static const std::string str1 = "This is a line";
    static const std::string str2 = "This is another line";

    int fd = _open("output.txt", _O_WRONLY | _O_CREAT | _O_TRUNC | _O_TEXT,
            _S_IREAD | _S_IWRITE);
    _write(fd, str1.data(), str1.size());
    _write(fd, "\n", 1);    // This writes "\r\n"

    boost::iostreams::file_descriptor_sink sink(fd, boost::iostreams::close_handle);
    boost::iostreams::stream<boost::iostreams::file_descriptor_sink> stream(sink);
    stream << str2;
    stream << std::endl;    // This only writes "\n"

    return 0;
}

Change History (0)

Note: See TracTickets for help on using tickets.