diff options
author | David 'Digit' Turner <digit@android.com> | 2010-05-10 23:26:01 -0700 |
---|---|---|
committer | David 'Digit' Turner <digit@android.com> | 2010-05-11 17:56:30 -0700 |
commit | 9251866320b5f8329a043bb56b3a794f78d12849 (patch) | |
tree | ca005574fbc5833f93d55ce72881780aa7e78aaf /cutils.c | |
parent | 1da50d3beb2a75f619fa56278cb195703361e261 (diff) | |
download | external_qemu-9251866320b5f8329a043bb56b3a794f78d12849.zip external_qemu-9251866320b5f8329a043bb56b3a794f78d12849.tar.gz external_qemu-9251866320b5f8329a043bb56b3a794f78d12849.tar.bz2 |
Upstream: integrate various misc. minor changes
Change-Id: I7d3eca1350f980d93f9f3198fa5250fb776de729
Diffstat (limited to 'cutils.c')
-rw-r--r-- | cutils.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -83,6 +83,19 @@ int stristart(const char *str, const char *val, const char **ptr) return 1; } +/* XXX: use host strnlen if available ? */ +int qemu_strnlen(const char *s, int max_len) +{ + int i; + + for(i = 0; i < max_len; i++) { + if (s[i] == '\0') { + break; + } + } + return i; +} + time_t mktimegm(struct tm *tm) { time_t t; @@ -138,6 +151,31 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len) ++qiov->niov; } +/* + * Copies iovecs from src to the end dst until src is completely copied or the + * total size of the copied iovec reaches size. The size of the last copied + * iovec is changed in order to fit the specified total size if it isn't a + * perfect fit already. + */ +void qemu_iovec_concat(QEMUIOVector *dst, QEMUIOVector *src, size_t size) +{ + int i; + size_t done; + + assert(dst->nalloc != -1); + + done = 0; + for (i = 0; (i < src->niov) && (done != size); i++) { + if (done + src->iov[i].iov_len > size) { + qemu_iovec_add(dst, src->iov[i].iov_base, size - done); + break; + } else { + qemu_iovec_add(dst, src->iov[i].iov_base, src->iov[i].iov_len); + } + done += src->iov[i].iov_len; + } +} + void qemu_iovec_destroy(QEMUIOVector *qiov) { assert(qiov->nalloc != -1); |