On Tue, Sep 24, 2013 at 11:03 AM, Lucas De Marchi
<lucas.demar...@profusion.mobi> wrote:
> On Tue, Sep 24, 2013 at 3:29 AM, Cedric BAIL <cedric.b...@free.fr> wrote:
>> On Tue, Sep 24, 2013 at 2:14 PM, Lucas De Marchi
>> <lucas.demar...@profusion.mobi> wrote:
>>> On Tue, Sep 24, 2013 at 12:20 AM, Jorge Zapata
>>> <jorgeluis.zap...@gmail.com> wrote:
>>>> cedric pushed a commit to branch master.
>>>>
>>>> http://git.enlightenment.org/core/efl.git/commit/?id=b5fce696c743c50ea0a049c4f879756b5ed231d4
>>>>
>>>> commit b5fce696c743c50ea0a049c4f879756b5ed231d4
>>>> Author: Jorge Zapata <jorgeluis.zap...@gmail.com>
>>>> Date:   Mon Sep 23 21:13:18 2013 +0200
>>>>
>>>>     eina: add functions to alloc strings from a printf fmt
>>>> ---
>>>>  src/lib/eina/eina_str.c | 41 +++++++++++++++++++++++++++++++++++++++++
>>>>  src/lib/eina/eina_str.h | 33 +++++++++++++++++++++++++++++++++
>>>>  2 files changed, 74 insertions(+)
>>>>
>>>> diff --git a/src/lib/eina/eina_str.c b/src/lib/eina/eina_str.c
>>>> index 11fef3c..283476b 100644
>>>> --- a/src/lib/eina/eina_str.c
>>>> +++ b/src/lib/eina/eina_str.c
>>>> @@ -652,3 +652,44 @@ eina_str_toupper(char **str)
>>>>     for (p = *str; (*p); p++)
>>>>        *p = toupper((unsigned char)(*p));
>>>>  }
>>>> +
>>>> +EAPI size_t
>>>> +eina_str_vprintf_length(const char *format, va_list args)
>>>> +{
>>>> +    char c;
>>>> +    size_t len;
>>>> +
>>>> +    len = vsnprintf(&c, 1, format, args) + 1;
>>>> +    return len;
>>>
>>> this is wrong if
>>>
>>> 1) vsnprintf returns an error  (for example if there's a wrong format 
>>> string)
>>> 2) format is "" - return value value should be 0, but will be 1
>>>
>>> If you change the return value to ssize_t it's better and simpler if you do:
>>>
>>> "return vsnprintf(NULL, 0, format, args);"
>>>
>>> If you prefer to ignore the error and continue with an unsigned type,
>>> then you should check the return value for < 0 before returning.
>>>
>>>> +}
>>>> +
>>>> +EAPI char *
>>>> +eina_str_vprintf_dup(const char *format, va_list args)
>>>> +{
>>>> +    size_t length;
>>>> +    char *ret;
>>>> +    va_list copy;
>>>> +
>>>> +    /* be sure to use a copy or the printf implementation will
>>>> +     * step into the args
>>>> +     */
>>>> +    va_copy(copy, args);
>>>> +    length = eina_str_vprintf_length(format, copy);
>>>> +    va_end(copy);
>>>> +
>>>> +    ret = calloc(length, sizeof(char));
>>>
>>> malloc instead? you are replacing all the chars below
>>>
>>>> +    vsprintf(ret, format, args);
>>>> +    return ret;
>>>> +}
>>>> +
>>>> +EAPI char *
>>>> +eina_str_printf_dup(const char *format, ...)
>>>> +{
>>>> +    char *ret;
>>>> +    va_list args;
>>>> +
>>>> +    va_start(args, format);
>>>> +    ret = eina_str_vprintf_dup(format, args);
>>>> +    va_end(args);
>>>> +    return ret;
>>>> +}
>>>
>>> why these instead of plain (v)asprintf?
>>
>> "These functions are GNU extensions, not in C or POSIX.", straight
>> from the man page...
>
> sure... and they are available everywhere.

I just committed some fixes and related changes, please take a look:
devs/lucas/fix-eina-newfuncs

Why is there only eina_str_vprintf_length() and not eina_str_printf_length()?

As I said above IMO we could remove the check for asprintf since it's
in general available on everywhere... we use asprintf() in some other
places already and the only platform that doesn't have it have the
impl in evil_printf.h.

I still think there isn't much point in adding these APIs....
otherwise let's at least let their implementation correct.

Lucas De Marchi

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to