Beispiel #1
0
/** => zzip_entry_data_offset
 * This function is a big helper despite its little name: in a zip file the
 * encoded filenames are usually NOT zero-terminated but for common usage
 * with libc we need it that way. Secondly, the filename SHOULD be present
 * in the zip central directory but if not then we fallback to the filename
 * given in the file_header of each compressed data portion.
 */
char* _zzip_restrict
zzip_entry_strdup_name(ZZIP_ENTRY* entry)
{
    if (! entry) return 0;

    ___ zzip_size_t len;
    if ((len = zzip_disk_entry_namlen (disk_(entry))))
    {
	char* name = malloc (len+1);
	if (! name) return 0;
	memcpy (name, entry->tail, len);
	name[len] = '\0';
	return name;
    }
    ___ auto struct zzip_file_header header;
    if (zzip_entry_fread_file_header (entry, &header) &&
	(( len = zzip_file_header_namlen(&header) )))
    {
	char* name = malloc (len+1);
	if (! name) return 0;
	fread (name, 1, len, entry->diskfile);
	name[len] = '\0';
	return name;
    }
    return 0;
    ____;____;
}
Beispiel #2
0
/** => zzip_entry_data_offset
 * This function is a big helper despite its little name: in a zip file the
 * encoded filenames are usually NOT zero-terminated but for common usage
 * with libc we need it that way. Secondly, the filename SHOULD be present
 * in the zip central directory but if not then we fallback to the filename
 * given in the file_header of each compressed data portion.
 */
zzip__new__ char *
zzip_entry_strdup_name(ZZIP_ENTRY * entry)
{
    if (! entry)
        return 0;

    ___ zzip_size_t len;
    if ((len = zzip_disk_entry_namlen(disk_(entry))))
    {
        char *name = malloc(len + 1);
        if (! name)
            return 0;
        memcpy(name, entry->tail, len);
        name[len] = '\0';
        return name;
    }
    ___ auto struct zzip_file_header header;
    if (zzip_entry_fread_file_header(entry, &header)
        && (len = zzip_file_header_namlen(&header)))
    {
        char *name = malloc(len + 1);
        if (! name) {
            return 0;
        } else {
            zzip_size_t n = fread(name, 1, len, entry->diskfile);
            if (n != len) {
                free (name);
                return 0;
            }
            name[n] = '\0';
            return name;
        }
    }
    return 0;
    ____;
    ____;
}