- break;
- case RESOURCE_IN_STAGING_FILE:
- case RESOURCE_IN_FILE_ON_DISK:
- /* The resource is in some file on the external filesystem and
- * needs to be read uncompressed */
- wimlib_assert(lte->file_on_disk != NULL);
- BUILD_BUG_ON(<e->file_on_disk != <e->staging_file_name);
- /* Use existing file pointer if available; otherwise open one
- * temporarily */
- if (lte->file_on_disk_fp) {
- fp = lte->file_on_disk_fp;
- } else {
- fp = tfopen(lte->file_on_disk, T("rb"));
- if (!fp) {
- ERROR_WITH_ERRNO("Failed to open the file "
- "`%"TS"'", lte->file_on_disk);
- ret = WIMLIB_ERR_OPEN;
- break;
- }
- }
- ret = read_uncompressed_resource(fp, offset, size, buf);
- if (fp != lte->file_on_disk_fp)
- fclose(fp);
- break;
-#ifdef __WIN32__
- case RESOURCE_WIN32:
- wimlib_assert(lte->win32_file_on_disk_fp != INVALID_HANDLE_VALUE);
- ret = win32_read_file(lte->file_on_disk,
- lte->win32_file_on_disk_fp, offset,
- size, buf);
- break;
-#endif
- case RESOURCE_IN_ATTACHED_BUFFER:
- /* The resource is directly attached uncompressed in an
- * in-memory buffer. */
- wimlib_assert(lte->attached_buffer != NULL);
- memcpy(buf, lte->attached_buffer + offset, size);
- break;
-#ifdef WITH_NTFS_3G
- case RESOURCE_IN_NTFS_VOLUME:
- wimlib_assert(lte->ntfs_loc != NULL);
- wimlib_assert(lte->attr != NULL);
- if (lte->ntfs_loc->is_reparse_point)
- offset += 8;
- if (ntfs_attr_pread(lte->attr, offset, size, buf) != size) {
- ERROR_WITH_ERRNO("Error reading NTFS attribute "
- "at `%"TS"'",
- lte->ntfs_loc->path);
- ret = WIMLIB_ERR_NTFS_3G;
- }
- break;
-#endif
- default:
- wimlib_assert(0);
- ret = -1;
- break;
- }
- return ret;
+ #ifdef WITH_NTFS_3G
+ [RESOURCE_IN_NTFS_VOLUME] = read_ntfs_file_prefix,
+ #endif
+ #ifdef __WIN32__
+ [RESOURCE_WIN32] = read_win32_file_prefix,
+ [RESOURCE_WIN32_ENCRYPTED] = read_win32_encrypted_file_prefix,
+ #endif
+ };
+ wimlib_assert(lte->resource_location < ARRAY_LEN(handlers)
+ && handlers[lte->resource_location] != NULL);
+ return handlers[lte->resource_location](lte, size, cb, ctx_or_buf, flags);