2 * Copyright 2017 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SKSL_FILEOUTPUTSTREAM
9 #define SKSL_FILEOUTPUTSTREAM
11 #include "src/sksl/SkSLOutputStream.h"
12 #include "src/sksl/SkSLUtil.h"
17 class FileOutputStream : public OutputStream {
19 FileOutputStream(const char* name) {
20 fFile = fopen(name, "wb");
23 ~FileOutputStream() override {
29 bool isValid() const override {
30 return nullptr != fFile;
33 void write8(uint8_t b) override {
36 if (EOF == fputc(b, fFile)) {
42 void writeText(const char* s) override {
45 if (EOF == fputs(s, fFile)) {
51 void write(const void* s, size_t size) override {
53 size_t written = fwrite(s, 1, size, fFile);
54 if (written != size) {
62 if (isValid() && fclose(fFile)) {
73 using INHERITED = OutputStream;