| 1879 | } dRess_t; |
| 1880 | |
| 1881 | static dRess_t FIO_createDResources(FIO_prefs_t* const prefs, const char* dictFileName) |
| 1882 | { |
| 1883 | dRess_t ress; |
| 1884 | memset(&ress, 0, sizeof(ress)); |
| 1885 | |
| 1886 | if (prefs->patchFromMode) |
| 1887 | FIO_adjustMemLimitForPatchFromMode(prefs, UTIL_getFileSize(dictFileName), 0 /* just use the dict size */); |
| 1888 | |
| 1889 | /* Allocation */ |
| 1890 | ress.dctx = ZSTD_createDStream(); |
| 1891 | if (ress.dctx==NULL) |
| 1892 | EXM_THROW(60, "Error: %s : can't create ZSTD_DStream", strerror(errno)); |
| 1893 | CHECK( ZSTD_DCtx_setMaxWindowSize(ress.dctx, prefs->memLimit) ); |
| 1894 | CHECK( ZSTD_DCtx_setParameter(ress.dctx, ZSTD_d_forceIgnoreChecksum, !prefs->checksumFlag)); |
| 1895 | |
| 1896 | ress.srcBufferSize = ZSTD_DStreamInSize(); |
| 1897 | ress.srcBuffer = malloc(ress.srcBufferSize); |
| 1898 | ress.dstBufferSize = ZSTD_DStreamOutSize(); |
| 1899 | ress.dstBuffer = malloc(ress.dstBufferSize); |
| 1900 | if (!ress.srcBuffer || !ress.dstBuffer) |
| 1901 | EXM_THROW(61, "Allocation error : not enough memory"); |
| 1902 | |
| 1903 | /* dictionary */ |
| 1904 | { void* dictBuffer; |
| 1905 | size_t const dictBufferSize = FIO_createDictBuffer(&dictBuffer, dictFileName, prefs); |
| 1906 | CHECK( ZSTD_initDStream_usingDict(ress.dctx, dictBuffer, dictBufferSize) ); |
| 1907 | free(dictBuffer); |
| 1908 | } |
| 1909 | |
| 1910 | return ress; |
| 1911 | } |
| 1912 | |
| 1913 | static void FIO_freeDResources(dRess_t ress) |
| 1914 | { |
no test coverage detected