Моя цель - записать файл на диск
Если я использую gio для создания файла
GError *error;
char path[strlen(dirpath)];
sprintf(path, "%s", dirpath); // Create path to the file by copying from another variable
zip_file_t *contentfile = zip_fopen_index(book, index, ZIP_RDONLY);
zip_stat_index(book, index, ZIP_CHECKCONS, &fileinfo);
GFile *gfile = g_file_new_for_path(strcat(path, fileinfo.name));
GFileOutputStream *file = g_file_create(gfile, G_FILE_CREATE_NONE, g_cancellable_new(), &error);
if (error)
printf("Error :%i\n", error->code);
else
zip_fread(contentfile, file, fileinfo.size);
g_error_free(error);
Я не могу ничего вставить в файл. Это просто файл, созданный с 0 байтами. Я извлекаю все файлы из архива с помощью loo. Отсюда индекс в zip_file_t *contentfile = zip_fopen_index(book, index, ZIP_RDONLY);
. Я получаю segfault: GError устанавливается поверх предыдущей GError или неинициализированной памяти.
Если я использую ФАЙЛ
char path[strlen(dirpath)];
sprintf(path, "%s", dirpath); // Create path to the file by copying from another variable
zip_file_t *contentfile = zip_fopen_index(book, index, ZIP_RDONLY);
zip_stat_index(book, index, ZIP_CHECKCONS, &fileinfo);
FILE *file = fopen(strcat(path, fileinfo.name), "wb");
zip_fread(contentfile, file, fileinfo.size);
Это дает ошибку сегментации: двойное освобождение или повреждение (out)
Как правильно записать содержимое zip_read( в файл на диске?
path
: измените ее наchar path[strlen(dirpath) + strlen(fileinfo.name) + 1];
и переместите после вызововzip_stat_index
. - person MikeCAT   schedule 03.09.2020