qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/5] Utility function strpadcpy() added


From: Dmitry Fleytman
Subject: [Qemu-devel] [PATCH 1/5] Utility function strpadcpy() added
Date: Thu, 15 Mar 2012 11:02:26 +0200

Signed-off-by: Dmitry Fleytman <address@hidden>
Signed-off-by: Yan Vugenfirer <address@hidden>
---
 cutils.c      |   13 +++++++++++++
 qemu-common.h |    1 +
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/cutils.c b/cutils.c
index af308cd..0df7fdf 100644
--- a/cutils.c
+++ b/cutils.c
@@ -27,6 +27,19 @@
 
 #include "qemu_socket.h"
 
+void strpadcpy(char *buf, int buf_size, const char *str, char pad)
+{
+    int i;
+    int has_src_data = TRUE;
+
+    for (i = 0; i < buf_size; i++) {
+        if ((has_src_data) && (0 == str[i])) {
+            has_src_data = FALSE;
+        }
+      buf[i] = has_src_data ? str[i] : pad;
+    }
+}
+
 void pstrcpy(char *buf, int buf_size, const char *str)
 {
     int c;
diff --git a/qemu-common.h b/qemu-common.h
index b0fdf5c..fdd3d17 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -134,6 +134,7 @@ int qemu_timedate_diff(struct tm *tm);
 
 /* cutils.c */
 void pstrcpy(char *buf, int buf_size, const char *str);
+void strpadcpy(char *buf, int buf_size, const char *str, char pad);
 char *pstrcat(char *buf, int buf_size, const char *s);
 int strstart(const char *str, const char *val, const char **ptr);
 int stristart(const char *str, const char *val, const char **ptr);
-- 
1.7.7.6




reply via email to

[Prev in Thread] Current Thread [Next in Thread]