From 64d2a7c8945ba05af859901f5e248f1befdd8621 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 3 Dec 2013 09:43:15 +0100 Subject: Imported Upstream version 1.2 --- src/libbio/bflush.c | 2 +- src/libbio/bgetc.c | 24 ++++++++++++++++++++++-- src/libbio/bgetd.c | 2 +- src/libbio/bgetrune.c | 8 ++++---- src/libbio/bprint.c | 4 ++-- src/libbio/bputc.c | 16 +++++++++++++++- src/libbio/bputrune.c | 4 ++-- src/libbio/brdline.c | 16 ++++++++-------- src/libbio/brdstr.c | 4 ++-- src/libbio/bread.c | 8 ++++---- src/libbio/bseek.c | 4 ++-- src/libbio/bwrite.c | 6 +++--- 12 files changed, 66 insertions(+), 32 deletions(-) (limited to 'src/libbio') diff --git a/src/libbio/bflush.c b/src/libbio/bflush.c index 8a071cb5c..ea7ae2c62 100644 --- a/src/libbio/bflush.c +++ b/src/libbio/bflush.c @@ -37,7 +37,7 @@ Bflush(Biobuf *bp) n = bp->bsize+bp->ocount; if(n == 0) return 0; - c = write(bp->fid, bp->bbuf, n); + c = (int)write(bp->fid, bp->bbuf, (size_t)n); if(n == c) { bp->offset += n; bp->ocount = -bp->bsize; diff --git a/src/libbio/bgetc.c b/src/libbio/bgetc.c index 52ed241f9..3399fb16b 100644 --- a/src/libbio/bgetc.c +++ b/src/libbio/bgetc.c @@ -49,7 +49,7 @@ loop: * buffer to allow that many ungets. */ memmove(bp->bbuf-Bungetsize, bp->ebuf-Bungetsize, Bungetsize); - i = read(bp->fid, bp->bbuf, bp->bsize); + i = (int)read(bp->fid, bp->bbuf, (size_t)bp->bsize); bp->gbuf = bp->bbuf; if(i <= 0) { bp->state = Bracteof; @@ -58,7 +58,7 @@ loop: return Beof; } if(i < bp->bsize) { - memmove(bp->ebuf-i-Bungetsize, bp->bbuf-Bungetsize, i+Bungetsize); + memmove(bp->ebuf-i-Bungetsize, bp->bbuf-Bungetsize, (size_t)(i+Bungetsize)); bp->gbuf = bp->ebuf-i; } bp->icount = -i; @@ -66,6 +66,26 @@ loop: goto loop; } +int +Bgetle2(Biobuf *bp) +{ + int l, h; + + l = Bgetc(bp); + h = Bgetc(bp); + return l|(h<<8); +} + +int +Bgetle4(Biobuf *bp) +{ + int l, h; + + l = Bgetle2(bp); + h = Bgetle2(bp); + return l|((uint32)h<<16); +} + int Bungetc(Biobuf *bp) { diff --git a/src/libbio/bgetd.c b/src/libbio/bgetd.c index cf76a755a..12d2c5b37 100644 --- a/src/libbio/bgetd.c +++ b/src/libbio/bgetd.c @@ -39,7 +39,7 @@ Bgetdf(void *vp) int c; struct bgetd *bg = vp; - c = Bgetc(bg->b); + c = BGETC(bg->b); if(c == Beof) bg->eof = 1; return c; diff --git a/src/libbio/bgetrune.c b/src/libbio/bgetrune.c index 1538f3ea7..441c07991 100644 --- a/src/libbio/bgetrune.c +++ b/src/libbio/bgetrune.c @@ -35,18 +35,18 @@ Bgetrune(Biobuf *bp) Rune rune; char str[UTFmax]; - c = Bgetc(bp); + c = BGETC(bp); if(c < Runeself) { /* one char */ bp->runesize = 1; return c; } - str[0] = c; + str[0] = (char)c; for(i=1;;) { - c = Bgetc(bp); + c = BGETC(bp); if(c < 0) return c; - str[i++] = c; + str[i++] = (char)c; if(fullrune(str, i)) { bp->runesize = chartorune(&rune, str); diff --git a/src/libbio/bprint.c b/src/libbio/bprint.c index b5d3e9ece..301dc0c7f 100644 --- a/src/libbio/bprint.c +++ b/src/libbio/bprint.c @@ -49,7 +49,7 @@ bflush(Fmt *f) return 0; bp = f->farg; - bp->ocount = (char*)f->to - (char*)f->stop; + bp->ocount = (int)((char*)f->to - (char*)f->stop); if(Bflush(bp) < 0) { f->stop = nil; f->to = nil; @@ -76,7 +76,7 @@ Bvprint(Biobuf *bp, char *fmt, va_list arg) n = fmtvprint(&f, fmt, arg); if(f.stop != nil) - bp->ocount = (char*)f.to - (char*)f.stop; + bp->ocount = (int)((char*)f.to - (char*)f.stop); return n; } diff --git a/src/libbio/bputc.c b/src/libbio/bputc.c index 4cdbe8f7a..07b4789b7 100644 --- a/src/libbio/bputc.c +++ b/src/libbio/bputc.c @@ -35,7 +35,7 @@ Bputc(Biobuf *bp, int c) for(;;) { i = bp->ocount; if(i) { - bp->ebuf[i++] = c; + bp->ebuf[i++] = (unsigned char)c; bp->ocount = i; return 0; } @@ -44,3 +44,17 @@ Bputc(Biobuf *bp, int c) } return Beof; } + +int +Bputle2(Biobuf *bp, int c) +{ + Bputc(bp, c); + return Bputc(bp, c>>8); +} + +int +Bputle4(Biobuf *bp, int c) +{ + Bputle2(bp, c); + return Bputle2(bp, c>>16); +} diff --git a/src/libbio/bputrune.c b/src/libbio/bputrune.c index e46f3c710..7fe0e6569 100644 --- a/src/libbio/bputrune.c +++ b/src/libbio/bputrune.c @@ -35,9 +35,9 @@ Bputrune(Biobuf *bp, long c) char str[UTFmax]; int n; - rune = c; + rune = (Rune)c; if(rune < Runeself) { - Bputc(bp, rune); + BPUTC(bp, (int)rune); return 1; } n = runetochar(str, &rune); diff --git a/src/libbio/brdline.c b/src/libbio/brdline.c index a02bf106d..1c3093ecf 100644 --- a/src/libbio/brdline.c +++ b/src/libbio/brdline.c @@ -51,9 +51,9 @@ Brdline(Biobuf *bp, int delim) * first try in remainder of buffer (gbuf doesn't change) */ ip = (char*)bp->ebuf - i; - ep = memchr(ip, delim, i); + ep = memchr(ip, delim, (size_t)i); if(ep) { - j = (ep - ip) + 1; + j = (int)((ep - ip) + 1); bp->rdline = j; bp->icount += j; return ip; @@ -63,7 +63,7 @@ Brdline(Biobuf *bp, int delim) * copy data to beginning of buffer */ if(i < bp->bsize) - memmove(bp->bbuf, ip, i); + memmove(bp->bbuf, ip, (size_t)i); bp->gbuf = bp->bbuf; /* @@ -71,12 +71,12 @@ Brdline(Biobuf *bp, int delim) */ ip = (char*)bp->bbuf + i; while(i < bp->bsize) { - j = read(bp->fid, ip, bp->bsize-i); + j = (int)read(bp->fid, ip, (size_t)(bp->bsize-i)); if(j <= 0) { /* * end of file with no delim */ - memmove(bp->ebuf-i, bp->bbuf, i); + memmove(bp->ebuf-i, bp->bbuf, (size_t)i); bp->rdline = i; bp->icount = -i; bp->gbuf = bp->ebuf-i; @@ -84,7 +84,7 @@ Brdline(Biobuf *bp, int delim) } bp->offset += j; i += j; - ep = memchr(ip, delim, j); + ep = memchr(ip, delim, (size_t)j); if(ep) { /* * found in new piece @@ -92,10 +92,10 @@ Brdline(Biobuf *bp, int delim) */ ip = (char*)bp->ebuf - i; if(i < bp->bsize){ - memmove(ip, bp->bbuf, i); + memmove(ip, bp->bbuf, (size_t)i); bp->gbuf = (unsigned char*)ip; } - j = (ep - (char*)bp->bbuf) + 1; + j = (int)((ep - (char*)bp->bbuf) + 1); bp->rdline = j; bp->icount = j - i; return ip; diff --git a/src/libbio/brdstr.c b/src/libbio/brdstr.c index 0398ab07b..6a90cf69b 100644 --- a/src/libbio/brdstr.c +++ b/src/libbio/brdstr.c @@ -37,14 +37,14 @@ Brdstr(Biobuf *bp, int delim, int nulldelim) linelen = Blinelen(bp); if(n == 0 && linelen == 0) return nil; - nq = realloc(q, n+linelen+1); + nq = realloc(q, (size_t)(n+linelen+1)); if(nq == nil) { free(q); return nil; } q = nq; if(p != nil) { - memmove(q+n, p, linelen); + memmove(q+n, p, (size_t)linelen); n += linelen; if(nulldelim) q[n-1] = '\0'; diff --git a/src/libbio/bread.c b/src/libbio/bread.c index 5cf9a05c8..343a0bf29 100644 --- a/src/libbio/bread.c +++ b/src/libbio/bread.c @@ -41,11 +41,11 @@ Bread(Biobuf *bp, void *ap, long count) while(c > 0) { n = -ic; if(n > c) - n = c; + n = (int)c; if(n == 0) { if(bp->state != Bractive) break; - i = read(bp->fid, bp->bbuf, bp->bsize); + i = (int)read(bp->fid, bp->bbuf, (size_t)bp->bsize); if(i <= 0) { bp->state = Bracteof; if(i < 0) @@ -55,13 +55,13 @@ Bread(Biobuf *bp, void *ap, long count) bp->gbuf = bp->bbuf; bp->offset += i; if(i < bp->bsize) { - memmove(bp->ebuf-i, bp->bbuf, i); + memmove(bp->ebuf-i, bp->bbuf, (size_t)i); bp->gbuf = bp->ebuf-i; } ic = -i; continue; } - memmove(p, bp->ebuf+ic, n); + memmove(p, bp->ebuf+ic, (size_t)n); c -= n; ic += n; p += n; diff --git a/src/libbio/bseek.c b/src/libbio/bseek.c index 291498108..eb426ccfc 100644 --- a/src/libbio/bseek.c +++ b/src/libbio/bseek.c @@ -62,9 +62,9 @@ Bseek(Biobuf *bp, vlong offset, int base) */ if(base == 0) { d = n - Boffset(bp); - bufsz = bp->ebuf - bp->gbuf; + bufsz = (int)(bp->ebuf - bp->gbuf); if(-bufsz <= d && d <= bufsz){ - bp->icount += d; + bp->icount += (int)d; if(d >= 0) { if(bp->icount <= 0) return n; diff --git a/src/libbio/bwrite.c b/src/libbio/bwrite.c index daed161cb..8b9943ab0 100644 --- a/src/libbio/bwrite.c +++ b/src/libbio/bwrite.c @@ -41,11 +41,11 @@ Bwrite(Biobuf *bp, void *ap, long count) while(c > 0) { n = -oc; if(n > c) - n = c; + n = (int)c; if(n == 0) { if(bp->state != Bwactive) return Beof; - i = write(bp->fid, bp->bbuf, bp->bsize); + i = (int)write(bp->fid, bp->bbuf, (size_t)bp->bsize); if(i != bp->bsize) { bp->state = Binactive; return Beof; @@ -54,7 +54,7 @@ Bwrite(Biobuf *bp, void *ap, long count) oc = -bp->bsize; continue; } - memmove(bp->ebuf+oc, p, n); + memmove(bp->ebuf+oc, p, (size_t)n); oc += n; c -= n; p += n; -- cgit v1.2.3