transmission/libtransmission/file.cc

35 lines
896 B
C++
Raw Normal View History

// This file Copyright © 2013-2023 Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
2014-09-21 18:08:56 +00:00
#include <algorithm>
#include <string_view>
2014-09-21 18:08:56 +00:00
#include "transmission.h"
#include "error.h"
2014-09-21 18:08:56 +00:00
#include "file.h"
#include "tr-assert.h"
2014-09-21 18:08:56 +00:00
using namespace std::literals;
#ifdef _WIN32
static auto constexpr NativeEol = "\r\n"sv;
#else
static auto constexpr NativeEol = "\n"sv;
#endif
bool tr_sys_file_write_line(tr_sys_file_t handle, std::string_view buffer, tr_error** error)
2014-09-21 18:08:56 +00:00
{
TR_ASSERT(handle != TR_BAD_SYS_FILE);
2014-09-21 18:08:56 +00:00
bool ret = tr_sys_file_write(handle, std::data(buffer), std::size(buffer), nullptr, error);
2014-09-21 18:08:56 +00:00
if (ret)
{
ret = tr_sys_file_write(handle, std::data(NativeEol), std::size(NativeEol), nullptr, error);
}
2014-09-21 18:08:56 +00:00
return ret;
2014-09-21 18:08:56 +00:00
}