openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/nbd/3.19-r0/nbd-3.19/nbd-server.c
GArray* do_cfile_dir(gchar* dir, struct generic_conf* const genconf, GError** e)
{
    DIR* dirh = opendir(dir);
    struct dirent* de;
    gchar* fname;
    GArray* retval = NULL;
    GArray* tmp;
    struct stat stbuf;

    if (!dirh)
    {
        g_set_error(e, NBDS_ERR, NBDS_ERR_CFILE_DIR_UNKNOWN,
                    "Invalid directory specified: %s", strerror(errno));
        return NULL;
    }
    errno = 0;
    while ((de = readdir(dirh)))
    {
        int saved_errno = errno;
        fname = g_build_filename(dir, de->d_name, NULL);
        switch (NBD_D_TYPE)
        {
            case DT_UNKNOWN:
                /* Filesystem doesn't return type of
                 * file through readdir. Run stat() on
                 * the file instead */
                if (stat(fname, &stbuf))
                {
                    perror("stat");
                    goto err_out;
                }
                if (!S_ISREG(stbuf.st_mode))
                {
                    goto next;
                }
            case DT_REG:
                /* Skip unless the name ends with '.conf' */
                if (strcmp((de->d_name + strlen(de->d_name) - 5), ".conf"))
                {
                    goto next;
                }
                tmp = parse_cfile(fname, genconf, false, e);
                errno = saved_errno;
                if (*e)
                {
                    goto err_out;
                }
                if (!retval)
                    retval = g_array_new(FALSE, TRUE, sizeof(SERVER));
                retval = g_array_append_vals(retval, tmp->data, tmp->len);
                g_array_free(tmp, TRUE);
            default:
                break;
        }
    next:
        g_free(fname);
    }
    if (errno)
    {
        g_set_error(e, NBDS_ERR, NBDS_ERR_CFILE_READDIR_ERR,
                    "Error trying to read directory: %s", strerror(errno));
    err_out:
        if (retval)
            g_array_free(retval, TRUE);
        retval = NULL;
    }
    if (dirh)
        closedir(dirh);
    return retval;
}
/**
 * Parse config file snippets in a directory. Uses readdir() and friends
 * to find files and open them, then passes them on to parse_cfile
 * with have_global set false
 **/
Parse config file snippets in a directory. Uses readdir() and friends
to find files and open them, then passes them on to parse_cfile
with have_global set false
Parse config file snippets in a directory . Uses readdir () and friends to find files and open them then passes them on to parse_cfile with have_global set false
GArray* do_cfile_dir(gchar* dir, struct generic_conf* const genconf, GError** e)
{
    DIR* dirh = opendir(dir);
    struct dirent* de;
    gchar* fname;
    GArray* retval = NULL;
    GArray* tmp;
    struct stat stbuf;
    if (!dirh)
    {
        g_set_error(e, NBDS_ERR, NBDS_ERR_CFILE_DIR_UNKNOWN,
                    "Invalid directory specified: %s", strerror(errno));
        return NULL;
    }
    errno = 0;
    while ((de = readdir(dirh)))
    {
        int saved_errno = errno;
        fname = g_build_filename(dir, de->d_name, NULL);
        switch (NBD_D_TYPE)
        {
            case DT_UNKNOWN:
                if (stat(fname, &stbuf))
                {
                    perror("stat");
                    goto err_out;
                }
                if (!S_ISREG(stbuf.st_mode))
                {
                    goto next;
                }
            case DT_REG:
                if (strcmp((de->d_name + strlen(de->d_name) - 5), ".conf"))
                {
                    goto next;
                }
                tmp = parse_cfile(fname, genconf, false, e);
                errno = saved_errno;
                if (*e)
                {
                    goto err_out;
                }
                if (!retval)
                    retval = g_array_new(FALSE, TRUE, sizeof(SERVER));
                retval = g_array_append_vals(retval, tmp->data, tmp->len);
                g_array_free(tmp, TRUE);
            default:
                break;
        }
    next:
        g_free(fname);
    }
    if (errno)
    {
        g_set_error(e, NBDS_ERR, NBDS_ERR_CFILE_READDIR_ERR,
                    "Error trying to read directory: %s", strerror(errno));
    err_out:
        if (retval)
            g_array_free(retval, TRUE);
        retval = NULL;
    }
    if (dirh)
        closedir(dirh);
    return retval;
}
GArray * do_cfile_dir ( gchar * dir , struct generic_conf * const genconf , GError * * e ) { DIR * dirh = opendir ( dir ) ; struct dirent * de ; gchar * fname ; GArray * retval = NULL ; GArray * tmp ; struct stat stbuf ; if ( ! dirh ) { g_set_error ( e , NBDS_ERR , NBDS_ERR_CFILE_DIR_UNKNOWN , " " , strerror ( errno ) ) ; return NULL ; } errno = 0 ; while ( ( de = readdir ( dirh ) ) ) { int saved_errno = errno ; fname = g_build_filename ( dir , de -> d_name , NULL ) ; switch ( NBD_D_TYPE ) { case DT_UNKNOWN : if ( stat ( fname , & stbuf ) ) { perror ( " " ) ; goto err_out ; } if ( ! S_ISREG ( stbuf . st_mode ) ) { goto next ; } case DT_REG : if ( strcmp ( ( de -> d_name + strlen ( de -> d_name ) - 5 ) , " " ) ) { goto next ; } tmp = parse_cfile ( fname , genconf , false , e ) ; errno = saved_errno ; if ( * e ) { goto err_out ; } if ( ! retval ) retval = g_array_new ( FALSE , TRUE , sizeof ( SERVER ) ) ; retval = g_array_append_vals ( retval , tmp -> data , tmp -> len ) ; g_array_free ( tmp , TRUE ) ; default : break ; } next : g_free ( fname ) ; } if ( errno ) { g_set_error ( e , NBDS_ERR , NBDS_ERR_CFILE_READDIR_ERR , " " , strerror ( errno ) ) ; err_out : if ( retval ) g_array_free ( retval , TRUE ) ; retval = NULL ; } if ( dirh ) closedir ( dirh ) ; return retval ; }
Parse config file snippets in a directory.
Parse config file snippets in a directory .
/* Filesystem doesn't return type of
                 * file through readdir. Run stat() on
                 * the file instead */ /* Skip unless the name ends with '.conf' */