github.com/tcnksm/go@v0.0.0-20141208075154-439b32936367/src/lib9/fmt/fmtfd.c (about) 1 /* 2 * The authors of this software are Rob Pike and Ken Thompson, 3 * with contributions from Mike Burrows and Sean Dorward. 4 * 5 * Copyright (c) 2002-2006 by Lucent Technologies. 6 * Portions Copyright (c) 2004 Google Inc. 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose without fee is hereby granted, provided that this entire notice 10 * is included in all copies of any software which is or includes a copy 11 * or modification of this software and in all copies of the supporting 12 * documentation for such software. 13 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 14 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES 15 * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING 16 * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 17 */ 18 19 #include <u.h> 20 #include <libc.h> 21 #include "fmtdef.h" 22 23 /* 24 * public routine for final flush of a formatting buffer 25 * to a file descriptor; returns total char count. 26 */ 27 int 28 fmtfdflush(Fmt *f) 29 { 30 if(__fmtFdFlush(f) <= 0) 31 return -1; 32 return f->nfmt; 33 } 34 35 /* 36 * initialize an output buffer for buffered printing 37 */ 38 int 39 fmtfdinit(Fmt *f, int fd, char *buf, int size) 40 { 41 f->runes = 0; 42 f->start = buf; 43 f->to = buf; 44 f->stop = buf + size; 45 f->flush = __fmtFdFlush; 46 f->farg = (void*)(uintptr)fd; 47 f->flags = 0; 48 f->nfmt = 0; 49 fmtlocaleinit(f, nil, nil, nil); 50 return 0; 51 }