diff mbox series

[v2,02/12] cutils: add qemu_pstrcmp

Message ID 20180907075948.26917-3-marcandre.lureau@redhat.com
State New
Headers show
Series Various qemu command line options help improvements | expand

Commit Message

Marc-André Lureau Sept. 7, 2018, 7:59 a.m. UTC
A char** variant of strcmp().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/qemu/cutils.h | 12 ++++++++++++
 util/cutils.c         |  5 +++++
 2 files changed, 17 insertions(+)

Comments

Thomas Huth Sept. 7, 2018, 8:25 a.m. UTC | #1
On 2018-09-07 09:59, Marc-André Lureau wrote:
> A char** variant of strcmp().
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  include/qemu/cutils.h | 12 ++++++++++++
>  util/cutils.c         |  5 +++++
>  2 files changed, 17 insertions(+)
> 
> diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
> index 47aaa3b0b9..0941639f36 100644
> --- a/include/qemu/cutils.h
> +++ b/include/qemu/cutils.h
> @@ -169,4 +169,16 @@ bool test_buffer_is_zero_next_accel(void);
>  int uleb128_encode_small(uint8_t *out, uint32_t n);
>  int uleb128_decode_small(const uint8_t *in, uint32_t *n);
>  
> +/**
> + * qemu_pstrcmp:
> + * @str1: a pointer to a C string
> + * @str2: a pointer to a C string
> + *
> + * Compares *str1 and *str2 with g_strcmp0().
> + *
> + * Returns: an integer less than, equal to, or greater than zero, if
> + * *str1 is <, == or > than *str2 .
> + */

Maybe add a comment that str1 or str2 can also be NULL?

Reviewed-by: Thomas Huth <thuth@redhat.com>
Marc-André Lureau Sept. 7, 2018, 8:29 a.m. UTC | #2
Hi

On Fri, Sep 7, 2018 at 12:26 PM Thomas Huth <thuth@redhat.com> wrote:
>
> On 2018-09-07 09:59, Marc-André Lureau wrote:
> > A char** variant of strcmp().
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  include/qemu/cutils.h | 12 ++++++++++++
> >  util/cutils.c         |  5 +++++
> >  2 files changed, 17 insertions(+)
> >
> > diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
> > index 47aaa3b0b9..0941639f36 100644
> > --- a/include/qemu/cutils.h
> > +++ b/include/qemu/cutils.h
> > @@ -169,4 +169,16 @@ bool test_buffer_is_zero_next_accel(void);
> >  int uleb128_encode_small(uint8_t *out, uint32_t n);
> >  int uleb128_decode_small(const uint8_t *in, uint32_t *n);
> >
> > +/**
> > + * qemu_pstrcmp:
> > + * @str1: a pointer to a C string
> > + * @str2: a pointer to a C string
> > + *
> > + * Compares *str1 and *str2 with g_strcmp0().
> > + *
> > + * Returns: an integer less than, equal to, or greater than zero, if
> > + * *str1 is <, == or > than *str2 .
> > + */
>
> Maybe add a comment that str1 or str2 can also be NULL?

*str1 or *str2 (not str1 or str2). ok

>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
>
Thomas Huth Sept. 7, 2018, 8:34 a.m. UTC | #3
On 2018-09-07 10:29, Marc-André Lureau wrote:
> Hi
> 
> On Fri, Sep 7, 2018 at 12:26 PM Thomas Huth <thuth@redhat.com> wrote:
>>
>> On 2018-09-07 09:59, Marc-André Lureau wrote:
>>> A char** variant of strcmp().
>>>
>>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>>> ---
>>>  include/qemu/cutils.h | 12 ++++++++++++
>>>  util/cutils.c         |  5 +++++
>>>  2 files changed, 17 insertions(+)
>>>
>>> diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
>>> index 47aaa3b0b9..0941639f36 100644
>>> --- a/include/qemu/cutils.h
>>> +++ b/include/qemu/cutils.h
>>> @@ -169,4 +169,16 @@ bool test_buffer_is_zero_next_accel(void);
>>>  int uleb128_encode_small(uint8_t *out, uint32_t n);
>>>  int uleb128_decode_small(const uint8_t *in, uint32_t *n);
>>>
>>> +/**
>>> + * qemu_pstrcmp:
>>> + * @str1: a pointer to a C string
>>> + * @str2: a pointer to a C string
>>> + *
>>> + * Compares *str1 and *str2 with g_strcmp0().
>>> + *
>>> + * Returns: an integer less than, equal to, or greater than zero, if
>>> + * *str1 is <, == or > than *str2 .
>>> + */
>>
>> Maybe add a comment that str1 or str2 can also be NULL?
> 
> *str1 or *str2 (not str1 or str2). ok

Ah, right, that's what I meant. Maybe clarify both conditions in the
comment ;-)

 Thomas
diff mbox series

Patch

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 47aaa3b0b9..0941639f36 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -169,4 +169,16 @@  bool test_buffer_is_zero_next_accel(void);
 int uleb128_encode_small(uint8_t *out, uint32_t n);
 int uleb128_decode_small(const uint8_t *in, uint32_t *n);
 
+/**
+ * qemu_pstrcmp:
+ * @str1: a pointer to a C string
+ * @str2: a pointer to a C string
+ *
+ * Compares *str1 and *str2 with g_strcmp0().
+ *
+ * Returns: an integer less than, equal to, or greater than zero, if
+ * *str1 is <, == or > than *str2 .
+ */
+int qemu_pstrcmp(const char **str1, const char **str2);
+
 #endif
diff --git a/util/cutils.c b/util/cutils.c
index 9205e09031..e2abc64278 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -769,3 +769,8 @@  char *size_to_str(uint64_t val)
 
     return g_strdup_printf("%0.3g %sB", (double)val / div, suffixes[i]);
 }
+
+int qemu_pstrcmp(const char **str1, const char **str2)
+{
+    return g_strcmp0(*str1, *str2);
+}