On Wednesday, July 18, 2012, Andrei Gherzan wrote:

> On Wed, Jul 18, 2012 at 3:08 PM, Daniel Wagner 
> <[email protected]<javascript:_e({}, 'cvml', '[email protected]');>
> > wrote:
>
>> On 18.07.2012 13:58, Gustavo Sverzut Barbieri wrote:
>>
>>> the entire code above should be common to "case DT_DIR". An idea to
>>>>> clean this up:
>>>>>
>>>>> Add "case DT_UNKOWN" before "case DT_DIR" and let it fall-through
>>>>> without a break statement if it's a dir.
>>>>>
>>>>
>>>> meh... of course this doesn't work. But you should put together the
>>>> common part nonetheless. Maybe using a flag isdir and if/else it's
>>>> easier
>>>>
>>>
>>>
>>> I wonder why fstatat() then stat(). He should just do the fstatat() on
>>> the
>>> final name, then concatenate the 2 path components.
>>>
>>>
> This makes sense. I can assume that STORAGEDIR/d->d_name is a dir and just
> fstatat/stat on "settings". If it fails, this could be
> that STORAGEDIR/d->d_name is not a dir a dir or there is no settings file
> inside. So it will "continue". I can patch this.
>
>
>> And god, you know the size of path prefix, just join the strings wisely
>>> and
>>> not sprintf it :-/
>>>
>>
>>
> I don't get it here. Would you please detail it a little. I don't
> understand why a string concat would be better than a sprinf...
>

snprintf is stupid, it cant know the size to allocate, the amount to copy...

If you know sizeof(STORAGEDIR) and strlen() you can malloc and memcpy(),
much faster.

If it's a loop, the prefix/directory can be strlen() and memcpy() only
once, just changing the variant part (filename) while you do the invariant
only once


-- 
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: [email protected]
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to