我的目标是将文件写入磁盘
如果我使用 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);
. 我收到一个段错误: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);
这给出了一个分段错误:double free or corruption (out)
如何正确地将 zip_read( 内容写入磁盘上的文件?