blob: f9f126868d462e6716178c2055c4421b1ba4609a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/* Copyright 2012 The Native Client Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can
* be found in the LICENSE file.
*/
#include "llvm/Wrap/file_wrapper_output.h"
#include <stdlib.h>
FileWrapperOutput::FileWrapperOutput(const std::string& name)
: _name(name) {
_file = fopen(name.c_str(), "wb");
if (NULL == _file) {
fprintf(stderr, "Unable to open: %s\n", name.c_str());
exit(1);
}
}
FileWrapperOutput::~FileWrapperOutput() {
fclose(_file);
}
bool FileWrapperOutput::Write(uint8_t byte) {
return EOF != fputc(byte, _file);
}
bool FileWrapperOutput::Write(const uint8_t* buffer, size_t buffer_size) {
if (!buffer) {
return false;
}
if (buffer_size > 0) {
return buffer_size == fwrite(buffer, 1, buffer_size, _file);
} else {
return true;
}
}
|