On Tue, Jul 17, 2012 at 1:44 PM, Andrei Gherzan <[email protected]> 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.

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

Reply via email to