allow File::write() to take a Span

This commit is contained in:
Josh Holtrop 2016-07-26 22:40:04 -04:00
parent 382d155e40
commit 26f8fb355e
2 changed files with 7 additions and 4 deletions

View File

@ -88,8 +88,7 @@ bool Buffer::write_to_file(const char * filename)
bytes_written += pd->length; bytes_written += pd->length;
if (pd->eol()) if (pd->eol())
{ {
if (!file.write(LineEndings::spans[m_line_endings].start, if (!file.write(LineEndings::spans[m_line_endings]))
LineEndings::spans[m_line_endings].length))
{ {
return false; return false;
} }
@ -99,8 +98,7 @@ bool Buffer::write_to_file(const char * filename)
if (m_eol_at_eof && bytes_written > 0u) if (m_eol_at_eof && bytes_written > 0u)
{ {
if (!file.write(LineEndings::spans[m_line_endings].start, if (!file.write(LineEndings::spans[m_line_endings]))
LineEndings::spans[m_line_endings].length))
{ {
return false; return false;
} }

View File

@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include "Span.h"
class File class File
{ {
@ -14,6 +15,10 @@ public:
size_t get_size(); size_t get_size();
bool read(uint8_t * buf, size_t size); bool read(uint8_t * buf, size_t size);
bool write(const uint8_t * buf, size_t size); bool write(const uint8_t * buf, size_t size);
bool write(const Span & span)
{
return write(span.start, span.length);
}
protected: protected:
int m_fd; int m_fd;