[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 1/5] Utility function strpadcpy() added
From: |
Dmitry Fleytman |
Subject: |
Re: [Qemu-devel] [PATCH 1/5] Utility function strpadcpy() added |
Date: |
Sun, 18 Mar 2012 11:22:17 +0200 |
Wow! Someone still remembers Pascal.
It was a long time I didn't hear about it.
I think I still have some code I wrote for old DOS TurboPascal with TurboVision,
maybe I'll publish it somewhere :)
Anyway, I believe that difference is rather minor, but let it be...
My implementation replaced with your one.
On Thu, Mar 15, 2012 at 11:53 AM, Paolo Bonzini <address@hidden> wrote:
> Il 15/03/2012 10:02, Dmitry Fleytman ha scritto:
>> 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;
>> + }
>
> 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);
>
- [Qemu-devel] [PATCH 0/5] VMWare PVSCSI paravirtual device implementation, Dmitry Fleytman, 2012/03/15
- [Qemu-devel] [PATCH 1/5] Utility function strpadcpy() added, Dmitry Fleytman, 2012/03/15
- [Qemu-devel] [PATCH 5/5] PVSCSI paravirtualized device integration Bus type "pvscsi" added., Dmitry Fleytman, 2012/03/15
- [Qemu-devel] [PATCH 3/5] Header with various utility functions shared by VMWARE SCSI and network devices, Dmitry Fleytman, 2012/03/15
- [Qemu-devel] [PATCH 2/5] Vendor name and product name parameters for SCSI devices Options "vendor_name" and "product_name" added for SCSI disks., Dmitry Fleytman, 2012/03/15
- [Qemu-devel] [PATCH 4/5] PVCSI paravirtualized device implementation, Dmitry Fleytman, 2012/03/15