forked from VowpalWabbit/vowpal_wabbit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.h
35 lines (29 loc) · 873 Bytes
/
io.h
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
/*
Copyright (c) 2007 Yahoo! Inc. All rights reserved. The copyrights
embodied in the content of this file are licensed under the BSD
(revised) open source license
*/
#ifndef IO_H__
#define IO_H__
#include <iostream.h>
#include <errno.h>
#include "stack.h"
using namespace std;
class io_buf {
public:
v_array<char > space;
int file;
string currentname;
string finalname;
io_buf() {alloc(space, 1 << 16); }
void set(char *p){space.end = p;}
void fill(int n) {alloc(space,
n + read(file, space.begin+n, space.end_array - space.begin -n));}
void flush() {
if (write(file, space.begin, space.index()) != (int) space.index())
cerr << "error, failed to write to cache\n";
space.end = space.begin; fsync(file); }
};
void buf_write(io_buf &o, char* &pointer, int n);
unsigned int buf_read(io_buf &i, char* &pointer, int n);
#endif