]> git.proxmox.com Git - qemu.git/blobdiff - cutils.c
Add cache handling functions
[qemu.git] / cutils.c
index e2bc1b89df1ebab2e4cc0bd77e1d8a43f35be9f2..35e2e2bf44889e564d445a4d39810d6f96d7f141 100644 (file)
--- a/cutils.c
+++ b/cutils.c
 #include "qemu_socket.h"
 #include "iov.h"
 
+void strpadcpy(char *buf, int buf_size, const char *str, char pad)
+{
+    int len = qemu_strnlen(str, buf_size);
+    memcpy(buf, str, len);
+    memset(buf + len, pad, buf_size - len);
+}
+
 void pstrcpy(char *buf, int buf_size, const char *str)
 {
     int c;
@@ -375,3 +382,12 @@ int qemu_parse_fd(const char *param)
     }
     return fd;
 }
+
+/* round down to the nearest power of 2*/
+int64_t pow2floor(int64_t value)
+{
+    if (!is_power_of_2(value)) {
+        value = 0x8000000000000000ULL >> clz64(value);
+    }
+    return value;
+}