- if (!lte)
- goto out_close;
-
- /* Hack alert: WriteEncryptedFileRaw() requires the callback function
- * to work with a buffer whose size we cannot control. This doesn't
- * play well with our read_resource_prefix() function, which itself uses
- * a callback function to extract WIM_CHUNK_SIZE chunks of data. We
- * work around this problem by calling WriteEncryptedFileRaw() in a
- * different thread and feeding it the data as needed. */
- ctx.file_ctx = file_ctx;
- ctx.buf_filled = 0;
- ctx.done = false;
- ctx.wimlib_err_code = 0;
- if (pthread_mutex_init(&ctx.mutex, NULL)) {
- ERROR_WITH_ERRNO("Can't create mutex");
- ret = WIMLIB_ERR_NOMEM;
- goto out_close;
- }
- if (pthread_cond_init(&ctx.cond, NULL)) {
- ERROR_WITH_ERRNO("Can't create condition variable");
- ret = WIMLIB_ERR_NOMEM;
- goto out_pthread_mutex_destroy;
- }
- ret = pthread_create(&import_thread, NULL,
- win32_encrypted_import_proc, &ctx);
- if (ret) {
- errno = ret;
- ERROR_WITH_ERRNO("Failed to create thread");
- ret = WIMLIB_ERR_FORK;
- goto out_pthread_cond_destroy;
- }