On Tuesday, July 17, 2012, Lucas De Marchi wrote:

> On Tue, Jul 17, 2012 at 2:05 PM, Lucas De Marchi
> <[email protected] <javascript:;>> wrote:
> > On Tue, Jul 17, 2012 at 1:44 PM, Andrei Gherzan 
> > <[email protected]<javascript:;>>
> wrote:
> >> This is useful for filesystems where d_type is always DT_UNKNOWN.
> >> In this case use fstatat() function.
> >> ---
> >>  src/storage.c |   19 +++++++++++++++++++
> >>  1 file changed, 19 insertions(+)
> >>
> >> diff --git a/src/storage.c b/src/storage.c
> >> index 47bd0cb..0491a52 100644
> >> --- a/src/storage.c
> >> +++ b/src/storage.c
> >> @@ -206,6 +206,25 @@ gchar **connman_storage_get_services()
> >>
> >>                         g_string_append_printf(result, "%s/",
> d->d_name);
> >>                         break;
> >> +               case DT_UNKNOWN:
> >> +                       /*
> >> +                        * If there is no d_type support use stat()
> >> +                        * to check if directory
> >> +                        */
> >> +                       ret = fstatat(dirfd(dir), d->d_name, &buf, 0);
> >> +                       if (ret < 0)
> >> +                               continue;
> >> +                       if (!(buf.st_mode & S_IFDIR))
> >> +                               continue;
> >
> > too many parenthesis here? You could use:
> >
> > if (!S_ISDIR(buf.st_mode))
> >
> > btw, a nitpick... struct stat on stack is more commonly named "st"
> > rather than buf.
> >
> >
> >> +                       str = g_strdup_printf("%s/%s/settings",
> STORAGEDIR,
> >> +                                                       d->d_name);
> >> +                       ret = stat(str, &buf);
> >> +                       g_free(str);
> >> +                       if (ret < 0)
> >> +                               continue;
> >> +
> >> +                       g_string_append_printf(result, "%s/",
> d->d_name);
> >> +                       break;
> >
> > 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.

And god, you know the size of path prefix, just join the strings wisely and
not sprintf it :-/


>
>
> Lucas De Marchi
> _______________________________________________
> connman mailing list
> [email protected] <javascript:;>
> http://lists.connman.net/listinfo/connman
>


-- 
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