]> Git Repo - qemu.git/blobdiff - cutils.c
usb-ohci: Change casts to DO_UPCAST() for OHCIPCIState
[qemu.git] / cutils.c
index 1090aa4c77d4590ff55d22d8b992e8bb33774840..bd9a01950a7a298b1b223f774d82f7bd5b97da88 100644 (file)
--- a/cutils.c
+++ b/cutils.c
@@ -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;
@@ -112,8 +125,22 @@ void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
     qiov->size = 0;
 }
 
+void qemu_iovec_init_external(QEMUIOVector *qiov, struct iovec *iov, int niov)
+{
+    int i;
+
+    qiov->iov = iov;
+    qiov->niov = niov;
+    qiov->nalloc = -1;
+    qiov->size = 0;
+    for (i = 0; i < niov; i++)
+        qiov->size += iov[i].iov_len;
+}
+
 void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
 {
+    assert(qiov->nalloc != -1);
+
     if (qiov->niov == qiov->nalloc) {
         qiov->nalloc = 2 * qiov->nalloc + 1;
         qiov->iov = qemu_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec));
@@ -126,9 +153,19 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t len)
 
 void qemu_iovec_destroy(QEMUIOVector *qiov)
 {
+    assert(qiov->nalloc != -1);
+
     qemu_free(qiov->iov);
 }
 
+void qemu_iovec_reset(QEMUIOVector *qiov)
+{
+    assert(qiov->nalloc != -1);
+
+    qiov->niov = 0;
+    qiov->size = 0;
+}
+
 void qemu_iovec_to_buffer(QEMUIOVector *qiov, void *buf)
 {
     uint8_t *p = (uint8_t *)buf;
This page took 0.024226 seconds and 4 git commands to generate.