blob: b6829bbf6459e9d167ca9ca835d3ff6fa921190d (
plain)
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
|
#include "internal.h"
static int
flush(fmt·State *io)
{
int fd;
intptr n;
fd = (uintptr)io->file;
n = io->buffer.cur - io->buffer.beg;
if(n && sys·write(fd, n, io->buffer.beg, &n))
return -1;
io->buffer.cur = io->buffer.beg;
return io->n;
}
int
fmt·open(int fd, int len, char *buf, fmt·State *io)
{
io->buffer.beg = buf;
io->buffer.cur = buf;
io->buffer.end = buf+len;
io->flush = flush;
io->file = (void*)(uintptr)fd;
io->flag = 0;
io->n = 0;
/* no heap needed */
io->heap = nil;
io->mem = (mem·Reallocator){ 0 };
fmt·setlocale(io, nil, nil, nil);
return 0;
}
|