Esempio n. 1
0
/** start writing to the magic zzip_savefile   also: zzip_creat, zzip_write
 * 
 * open a zip archive for writing via the magic zzip_savefile macro
 * variable. The name and mode are given to => zzip_createdir and
 * the result is stored into => zzip_savefile - if the => zzip_savefile
 * did already have a zzip_dir handle then it is automatically 
 * finalized with => zzip_sync and the handle closed and the
 * zzip_savefile variable reused for the new zip archive just started
 * with this call. - This function is really a preprocessor macro 
 * or preferably an inline function around => zzip_dir_create, there 
 * is no such symbol generated into the library.
 #ifndef zzip_savefile
 #define zzip_savefile 0
 #endif
 #define zzip_start(name,mode,ext) \ -
       { if (zzip_savefile) zzip_closedir(zzip_savefile); \ -
          zzip_savefile = zzip_createdir(name,mode,ext); }
 * This function returns null on error or a zzip_dir handle on
 * success. It is perfectly okay to continue with a null in the
 * zzip_savefile variable since it makes subsequent calls to
 * => zzip_creat and => zzip_mkdir to run as => creat(2) / => mkdir(2) 
 * on the real filesystem.
 */
void inline
zzip_mkfifo(zzip_char_t * name, int o_mode)
{
    if (zzip_savefile)
        zzip_closedir(zzip_savefile);
    zzip_savefile = zzip_createdir(name, o_mode);
}
Esempio n. 2
0
int main(int argc, const char *argv[])
{
    if (argc < 2) {
        fprintf(stderr, "usage: %s <file>\n", argv[0]);
        return -1;
    }
    const char* innerFile = "";
    if (argc == 3) innerFile = argv[2];

    zzip_error_t errcode;
    ZZIP_DIR* dir = zzip_dir_open(argv[1], &errcode);
    if (dir == NULL) {
        fprintf(stderr, "zzip_operdir failed: %s\n", zzip_strerror(errcode));
        return -1;
    }

    // scan files
    ZZIP_DIRENT* dirent = zzip_readdir(dir);
    while (dirent) {
        printf("%s, compression %d, size %d/%d\n",
            dirent->d_name, dirent->d_compr, dirent->d_csize, dirent->st_size);

        checkFile(dir, dirent, innerFile);
        dirent = zzip_readdir(dir);
    }

    int err = zzip_closedir(dir);
    if (err != 0) {
        fprintf(stderr, "zzip_closedir failed: %s\n", zzip_strerror_of(dir));
        return -1;
    }

    return 0;
}
Esempio n. 3
0
/** => zzip_mkfifo                        also: zzip_closedir, sync(2)
 * 
 * finalize a zip archive thereby writing the central directory to
 * the end of the file. If it was a real directory then we do just
 * nothing - even that the prototype of the call itself is modelled 
 * to be similar to the posix => sync(2) call. This function is 
 * really a preprocessor macro or preferably an inline function
 * around => zzip_closedir, there is no such symbol generated 
 * into the library.
 #ifndef zzip_savefile
 #define zzip_savefile 0
 #endif
 #define zzip_sync(name,mode) \ -
       { zzip_closedir(zzip_savefile); zzip_savefile = 0; }
 *
 */
void inline
zzip_sync(void)
{
    zzip_closedir(zzip_savefile);
    zzip_savefile = 0;
}