make check can now run in parallel
parent
f63eb1d9c5
commit
03feeb7ef2
@ -1,8 +1,34 @@
|
|||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
|
|
||||||
void buffer_seek(buffer* b,size_t len) {
|
ssize_t buffer_seek(buffer* b,size_t len) {
|
||||||
size_t n=b->p+len;
|
size_t leftinbuf = b->n - b->p;
|
||||||
if (n<b->p) n=b->p;
|
ssize_t r;
|
||||||
if (n>b->n) n=b->n;
|
|
||||||
b->p=n;
|
if ((ssize_t)len < 0) return -1; // can't signal back how much we read, so error out
|
||||||
|
r = (ssize_t)len;
|
||||||
|
|
||||||
|
if (len <= leftinbuf) {
|
||||||
|
b->p += len;
|
||||||
|
return len;
|
||||||
|
} else {
|
||||||
|
// want to skip more than there was in the buffer
|
||||||
|
len -= leftinbuf;
|
||||||
|
b->p = 0; // clear buffer
|
||||||
|
b->n = 0;
|
||||||
|
/* change position in underlying file */
|
||||||
|
if (b->fd != -1 &&
|
||||||
|
lseek(b->fd, len, SEEK_CUR) != -1) return len;
|
||||||
|
// either we have no fd or input is not seekable
|
||||||
|
// call read repeatedly
|
||||||
|
while (len > 0) {
|
||||||
|
ssize_t r = buffer_feed(b);
|
||||||
|
if (r < 0) return -1;
|
||||||
|
if ((size_t)r > len) r = len; // can't happen
|
||||||
|
len -= r;
|
||||||
|
b->p = b->n = 0;
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue