/** => 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; ____;____; }
/** helper functions for (fseeko) zip access api * * This functions returns the seekval offset of the data portion of the * file referenced by the given zzip_entry. It requires an intermediate * check of the file_header structure (i.e. it reads it from disk). After * this call, the contained diskfile readposition is already set to the * data_offset returned here. On error -1 is returned. */ zzip_off_t zzip_entry_data_offset(ZZIP_ENTRY* entry) { struct zzip_file_header file_header; if (! entry) return -1; ___ zzip_off_t offset = zzip_entry_fread_file_header (entry, & file_header); if (! offset) return -1; offset += zzip_file_header_sizeof_tails (& file_header); fseeko (entry->diskfile, offset, SEEK_SET); return offset; ____; }
/** => 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; ____; ____; }