Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
unit_test.cc
Go to the documentation of this file.
1// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
6
7#include "platform/syslog.h"
8#include "vm/globals.h"
9
10namespace dart {
11namespace compiler {
12namespace ffi {
13
14#if defined(DART_TARGET_OS_WINDOWS)
15const char* kOs = "win";
16#else
17const char* kOs = kTargetOperatingSystemName;
18#endif
19
20void WriteToFile(char* path, const char* contents) {
21 FILE* file;
22 file = fopen(path, "w");
23 if (file != nullptr) {
24 fprintf(file, "%s", contents);
25 } else {
26 Syslog::Print("Error %d \n", errno);
27 }
28 fclose(file);
29}
30
31void ReadFromFile(char* path, char** buffer_pointer) {
32 FILE* file = fopen(path, "rb");
33 if (file == nullptr) {
34 Syslog::Print("Error %d \n", errno);
35 return;
36 }
37
38 fseek(file, 0, SEEK_END);
39 size_t size = ftell(file);
40 rewind(file);
41
42 char* buffer = reinterpret_cast<char*>(malloc(sizeof(char) * (size + 1)));
43
44 fread(buffer, 1, size, file);
45 buffer[size] = 0;
46
47 fclose(file);
48 *buffer_pointer = buffer;
49}
50
51} // namespace ffi
52} // namespace compiler
53} // namespace dart
static bool rewind(EdgeList *activeEdges, Vertex **current, Vertex *dst, const Comparator &c)
static void Print(const char *format,...) PRINTF_ATTRIBUTE(1
static const uint8_t buffer[]
void WriteToFile(char *path, const char *contents)
Definition unit_test.cc:20
void ReadFromFile(char *path, char **buffer_pointer)
Definition unit_test.cc:31
const char * kOs
Definition unit_test.cc:17
void * malloc(size_t size)
Definition allocation.cc:19