From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S87NX-0003dS-3G for qemu-devel@nongnu.org; Thu, 15 Mar 2012 05:54:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S87NV-0006h0-2n for qemu-devel@nongnu.org; Thu, 15 Mar 2012 05:53:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S87NU-0006gL-RN for qemu-devel@nongnu.org; Thu, 15 Mar 2012 05:53:49 -0400 Message-ID: <4F61BC1A.8020207@redhat.com> Date: Thu, 15 Mar 2012 10:53:30 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1331802150-12183-1-git-send-email-dmitry.fleytman@ravellosystems.com> <1331802150-12183-2-git-send-email-dmitry.fleytman@ravellosystems.com> In-Reply-To: <1331802150-12183-2-git-send-email-dmitry.fleytman@ravellosystems.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/5] Utility function strpadcpy() added List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Dmitry Fleytman Cc: Anthony Liguori , Alex Fishman , "Michael S. Tsirkin" , yvugenfi@redhat.com, Izik Eidus , qemu-devel@nongnu.org, Yan Vugenfirer , Dmitry Fleytman Il 15/03/2012 10:02, Dmitry Fleytman ha scritto: > Signed-off-by: Dmitry Fleytman > Signed-off-by: Yan Vugenfirer > --- > 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; > + } No parentheses around simple if conditions, this is not Pascal. :) But since you're at it, why not the simpler: 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; > 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);