diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-01-17 12:40:45 +0100 |
commit | 3e45412327a2654a77944249962b3652e6142299 (patch) | |
tree | bc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/libbio | |
parent | c533680039762cacbc37db8dc7eed074c3e497be (diff) | |
download | golang-3e45412327a2654a77944249962b3652e6142299.tar.gz |
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/libbio')
-rw-r--r-- | src/libbio/Makefile | 20 | ||||
-rw-r--r-- | src/libbio/bprint.c | 70 | ||||
-rw-r--r-- | src/libbio/bseek.c | 2 |
3 files changed, 53 insertions, 39 deletions
diff --git a/src/libbio/Makefile b/src/libbio/Makefile index 32fdedd91..4340b0eae 100644 --- a/src/libbio/Makefile +++ b/src/libbio/Makefile @@ -22,7 +22,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -include ../Make.conf +include ../Make.inc +O:=$(HOST_O) LIB=libbio.a @@ -47,19 +48,4 @@ OFILES=\ HFILES=\ ../../include/bio.h -install: $(LIB) - cp $(LIB) ../../lib - -$(LIB): $(OFILES) - ar rsc $(LIB) $(OFILES) - -$(OFILES): $(HFILES) - -y.tab.c: $(YFILES) - yacc $(YFLAGS) $(YFILES) - -clean: - rm -f $(OFILES) *.6 6.out $(LIB) - -nuke: clean - rm -f ../../lib/$(LIB) +include ../Make.clib diff --git a/src/libbio/bprint.c b/src/libbio/bprint.c index 2e3867ae6..b5d3e9ece 100644 --- a/src/libbio/bprint.c +++ b/src/libbio/bprint.c @@ -3,6 +3,7 @@ http://code.google.com/p/inferno-os/source/browse/libbio/bprint.c Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. Revisions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved. + Revisions Copyright © 2010 Google Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -30,25 +31,52 @@ THE SOFTWARE. int Bprint(Biobuf *bp, char *fmt, ...) { - va_list ap; - char *ip, *ep, *out; - int n; - - ep = (char*)bp->ebuf; - ip = ep + bp->ocount; - va_start(ap, fmt); - out = vseprint(ip, ep, fmt, ap); - va_end(ap); - if(out == nil || out >= ep-5) { - Bflush(bp); - ip = ep + bp->ocount; - va_start(ap, fmt); - out = vseprint(ip, ep, fmt, ap); - va_end(ap); - if(out >= ep-5) - return Beof; - } - n = out-ip; - bp->ocount += n; - return n; + int n; + va_list arg; + + va_start(arg, fmt); + n = Bvprint(bp, fmt, arg); + va_end(arg); + return n; +} + +static int +bflush(Fmt *f) +{ + Biobuf *bp; + + if(f->stop == nil) + return 0; + + bp = f->farg; + bp->ocount = (char*)f->to - (char*)f->stop; + if(Bflush(bp) < 0) { + f->stop = nil; + f->to = nil; + return 0; + } + f->to = (char*)f->stop + bp->ocount; + + return 1; +} + +int +Bvprint(Biobuf *bp, char *fmt, va_list arg) +{ + int n; + Fmt f; + + memset(&f, 0, sizeof f); + fmtlocaleinit(&f, nil, nil, nil); + f.stop = bp->ebuf; + f.to = (char*)f.stop + bp->ocount; + f.flush = bflush; + f.farg = bp; + + n = fmtvprint(&f, fmt, arg); + + if(f.stop != nil) + bp->ocount = (char*)f.to - (char*)f.stop; + + return n; } diff --git a/src/libbio/bseek.c b/src/libbio/bseek.c index be00ab1a7..291498108 100644 --- a/src/libbio/bseek.c +++ b/src/libbio/bseek.c @@ -33,7 +33,7 @@ Bseek(Biobuf *bp, vlong offset, int base) vlong n, d; int bufsz; -#ifndef __MINGW32__ +#ifndef _WIN32 if(sizeof(offset) != sizeof(off_t)) { fprint(2, "Bseek: libbio compiled with %d-byte offset\n", sizeof(off_t)); abort(); |