1// Copyright 2017 The Fuchsia Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "fidl/source_manager.h" 6 7#include <utility> 8 9namespace fidl { 10 11bool SourceManager::CreateSource(StringView filename) { 12 FILE* file = fopen(filename.data(), "rb"); 13 if (!file) 14 return false; 15 16 // The lexer requires zero terminated data. 17 std::string data; 18 fseek(file, 0, SEEK_END); 19 auto filesize = ftell(file); 20 data.resize(filesize + 1); 21 rewind(file); 22 fread(&data[0], 1, filesize, file); 23 data[filesize] = 0; 24 fclose(file); 25 26 AddSourceFile(std::make_unique<SourceFile>(filename, std::move(data))); 27 return true; 28} 29 30void SourceManager::AddSourceFile(std::unique_ptr<SourceFile> file) { 31 sources_.push_back(std::move(file)); 32} 33 34} // namespace fidl 35