blob: e8cc507bc690524e99edeac3e501c1ac717d2e75 [file] [log] [blame]
Shinichiro Hamaji2f6078b2015-07-31 14:59:46 +09001// Copyright 2015 Google Inc. All rights reserved
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// +build ignore
16
17#include "io.h"
18
19#include "log.h"
20
21void DumpInt(FILE* fp, int v) {
22 size_t r = fwrite(&v, sizeof(v), 1, fp);
23 CHECK(r == 1);
24}
25
26void DumpString(FILE* fp, StringPiece s) {
27 DumpInt(fp, s.size());
28 size_t r = fwrite(s.data(), 1, s.size(), fp);
29 CHECK(r == s.size());
30}
31
32int LoadInt(FILE* fp) {
33 int v;
34 size_t r = fread(&v, sizeof(v), 1, fp);
35 CHECK(r == 1);
36 return v;
37}
38
39void LoadString(FILE* fp, string* s) {
40 s->resize(LoadInt(fp));
41 size_t r = fread(&(*s)[0], 1, s->size(), fp);
42 CHECK(r == s->size());
43}