コード例 #1
0
ファイル: dir.c プロジェクト: mcodegeeks/OpenKODE-Framework
/** => zzip_opendir
 * This function uses explicit ext and io instead of the internal 
 * defaults, setting them to zero is equivalent to => zzip_opendir
 */
ZZIP_DIR *
zzip_opendir_ext_io(zzip_char_t * filename, int o_modes,
                    zzip_strings_t * ext, zzip_plugin_io_t io)
{
    zzip_error_t e;
    ZZIP_DIR *dir;

#  ifdef ZZIP_HAVE_SYS_STAT_H
    struct stat st;
#  endif

    if (o_modes & (ZZIP_PREFERZIP | ZZIP_ONLYZIP))
        goto try_zzip;
  try_real:

#  ifdef ZZIP_HAVE_SYS_STAT_H
    if (stat(filename, &st) >= 0 && S_ISDIR(st.st_mode))
    {
        if (USE_DIRENT)
        {
            _zzip_DIR *realdir = _zzip_opendir(filename);

            if (realdir)
            {
                if (! (dir = (ZZIP_DIR *) calloc(1, sizeof(*dir))))
                {
                    _zzip_closedir(realdir);
                    return 0;
                } else
                {
                    dir->realdir = realdir;
                    dir->realname = kdStrdup(filename);
                    return dir;
                }
            }
        }
        return 0;
    }
#  endif /* HAVE_SYS_STAT_H */

  try_zzip:
    dir = zzip_dir_open_ext_io(filename, &e, ext, io);
    if (! dir && (o_modes & ZZIP_PREFERZIP))
        goto try_real;
    if (e)
        kdSetError ( zzip_errno(e) );
    return dir;
}
コード例 #2
0
ファイル: zzip-dir.c プロジェクト: gkalab/cb2pgn
/**
 * This function is the equivalent of => closedir(3) for a realdir or zipfile.
 * <p>
 * This function is magic - if the given arg-ZZIP_DIR
 * is a real directory, it will call the real => closedir(3) and then
 * free the wrapping ZZIP_DIR structure. Otherwise it will divert 
 * to => zzip_dir_close which will free the ZZIP_DIR structure.
 */
int
zzip_closedir(ZZIP_DIR* dir)
{
    if (! dir) { errno = EBADF; return -1; }

    if (USE_DIRENT && dir->realdir)
    {
        _zzip_closedir(dir->realdir);
        free(dir->realname);
        free(dir);
        return 0;
    }else
    {
        zzip_dir_close(dir);
        return 0;
    }
}