summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2015-12-27 15:35:51 +0100
committerJulian Andres Klode <jak@debian.org>2015-12-27 15:43:13 +0100
commitc368b3abe198f59d5bd4d715a801e1b187b698a7 (patch)
tree93a40439aaa9a1c7408ff55f9ee0f74da0bf87ba /apt-pkg/contrib
parentea58d39ee3b71b02ddfd134412adc99e7b09605d (diff)
fileutl: simple_buffer: Add write() and full() methods
These can be used to implement write buffering Gbp-Dch: ignore
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/fileutl.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 38ae0246e..99c0a3417 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -928,6 +928,7 @@ struct APT_HIDDEN simple_buffer { /*{{{*/
const char *get() const { return buffer + bufferstart; }
char *get() { return buffer + bufferstart; }
bool empty() const { return bufferend <= bufferstart; }
+ bool full() const { return bufferend == buffersize_max; }
unsigned long long size() const { return bufferend-bufferstart; }
void reset() { bufferend = bufferstart = 0; }
ssize_t read(void *to, unsigned long long requested_size) APT_MUSTCHECK
@@ -940,6 +941,16 @@ struct APT_HIDDEN simple_buffer { /*{{{*/
bufferstart = bufferend = 0;
return requested_size;
}
+ ssize_t write(const void *from, unsigned long long requested_size) APT_MUSTCHECK
+ {
+ if (buffersize_max - size() < requested_size)
+ requested_size = buffersize_max - size();
+ memcpy(buffer + bufferend, from, requested_size);
+ bufferend += requested_size;
+ if (bufferstart == bufferend)
+ bufferstart = bufferend = 0;
+ return requested_size;
+ }
};
/*}}}*/