Exemplo n.º 1
0
//// Check if the given file is a real directory or a Zip-archive
static void b_zzip_dir_real(task *tsk, pntr *argstack)
{
	char *fileName;
	int badtype;
	pntr p = argstack[0];
	int dirtype;
	
	CHECK_ARG(0, CELL_CONS);
	if((badtype = array_to_string(p, &fileName)) >= 0){
		set_error(tsk, "error1: argument is not a string (contains non-char: %s)", cell_types[badtype]);
		return;
	}
	
	//// the file to be ckecked exists, then we check it
	static const char* ext[] = { "", ".exe", ".EXE", 0 };
	ZZIP_DIR* dir = zzip_opendir_ext_io (fileName, ZZIP_PREFERZIP, ext, 0);

    if(dir){
    	if(zzip_dir_real(dir)){
    		dirtype = 1;
//	   		printf("%s is a directory.\n", fileName);
    	}else{
    		dirtype = 0;
//    		printf("%s is a zip-archive.\n", fileName);
    	}
//    	zzip_dir_close(dir);
    }else{
    	//// file failed to be open
    	dirtype = -1;
    }
	setnumber(&argstack[0], dirtype);
	
	return;
}
Exemplo n.º 2
0
/**
 * This function is the equivalent of => opendir(3) for a realdir or zipfile.
 * 
 * This function has some magic - if the given argument-path
 * is a directory, it will wrap a real => opendir(3) into the ZZIP_DIR
 * structure. Otherwise it will divert to => zzip_dir_open which 
 * can also attach a ".zip" extension if needed to find the archive.
 * 
 * the error-code is mapped to => errno(3).
 */
ZZIP_DIR *
zzip_opendir(zzip_char_t * filename)
{
    return zzip_opendir_ext_io(filename, 0, 0, 0);
}