fix building on Ubuntu Bionic (18.04LTS)

[GB.COMPRESS.ZSTD]
* NEW: Fix building with Ubuntu Bionic (18.04LTS) (zstd > 1.3.2)
This commit is contained in:
Laurent Carlier 2021-04-09 18:35:13 +02:00
parent f54c267548
commit c3811e003d
No known key found for this signature in database
GPG key ID: 06096A6AD1CEDDAC
3 changed files with 76 additions and 8 deletions

View file

@ -171,7 +171,7 @@ build:ubuntu-bionic:
script:
- ./reconf-all
- GAMBAS_CONFIG_FAILURE=1 ./configure -C --disable-keyring --disable-zstd
- GAMBAS_CONFIG_FAILURE=1 ./configure -C --disable-keyring
- make -j$(nproc)
- make install

View file

@ -11,7 +11,7 @@ dnl ---- zstd compression driver
GB_COMPONENT_PKG_CONFIG(
zstd, ZSTD, gb.compress.zstd, [src],
'libzstd >= 1.3.8')
'libzstd >= 1.3.3')
dnl ---- Create makefiles

View file

@ -92,7 +92,11 @@ static int ZSTD_max_compression(void)
static int ZSTD_min_compression(void)
{
#if ZSTD_VERSION_NUMBER < 10308 // ubuntu 18.04 LTS - zstd v1.3.3 / debian stable is v1.3.8
return 1;
#else
return ZSTD_minCLevel();
#endif
}
static int ZSTD_default_compression(void)
@ -158,16 +162,73 @@ static void ZSTD_c_File(char *source,char *target,int level)
GB.Error("Error while compressing file: ZSTD_createCCtx() failed!");
goto error_cfile;
}
#if ZSTD_VERSION_NUMBER < 10308 // ubuntu 18.04 LTS - zstd v1.3.3 / debian stable is v1.3.8
size_t const retValue = ZSTD_initCStream(cctx, level);
if (ZSTD_isError(retValue))
{
GB.Error("Error while compressing file, ZSTD_initCStream() failed: &1", ZSTD_getErrorName(retValue));
goto error_cfile;
}
while(!feof(f_src))
{
size_t len = fread(buffIn, 1, buffInSize, f_src);
if (len < buffInSize)
{
if (ferror(f_src))
{
GB.Error("Error while reading data: &1", strerror(errno));
goto error_cfile;
}
}
if (len > 0)
{
ZSTD_inBuffer input = { buffIn, len, 0 };
int finished;
do {
ZSTD_outBuffer output = { buffOut, buffOutSize, 0 };
size_t const remaining = ZSTD_compressStream(cctx, &output , &input);
if (ZSTD_isError(remaining))
{
GB.Error("Error while compressing file: &1", ZSTD_getErrorName(remaining));
goto error_cfile;
}
if (fwrite(buffOut, 1, output.pos, f_dst) != output.pos)
{
GB.Error("Error while writing data: &1", strerror(errno));
goto error_cfile;
}
finished = remaining;
} while (!finished);
ZSTD_outBuffer output = { buffOut, buffOutSize, 0 };
size_t const remaining = ZSTD_endStream(cctx, &output);
if (remaining)
{
GB.Error("Error while compressing file: not fully flushed!");
goto error_cfile;
}
if (fwrite(buffOut, 1, output.pos, f_dst) != output.pos)
{
GB.Error("Error while writing flushed data: &1", strerror(errno));
goto error_cfile;
}
}
}
#else
// TODO: check errors ?
ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, level);
ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1);
ZSTD_EndDirective mode = ZSTD_e_continue;
while(!feof(f_src))
{
size_t len = fread(buffIn, 1, buffInSize, f_src);
size_t len = fread(buffIn, 1, buffInSize, f_src);
if (len < buffInSize)
{
if (ferror(f_src))
@ -177,7 +238,6 @@ static void ZSTD_c_File(char *source,char *target,int level)
}
mode = ZSTD_e_end;
}
if (len > 0)
{
ZSTD_inBuffer input = { buffIn, len, 0 };
@ -196,12 +256,12 @@ static void ZSTD_c_File(char *source,char *target,int level)
GB.Error("Error while writing data: &1", strerror(errno));
goto error_cfile;
}
finished = (len < buffInSize) ? (remaining == 0) : (input.pos == input.size);
} while (!finished);
}
}
#endif /* ZSTD_VERSION_NUMBER < 10308 */
error_cfile:
if (cctx != NULL)
ZSTD_freeCCtx(cctx);
@ -288,6 +348,14 @@ static void ZSTD_u_File(char *source,char *target)
goto error_ufile;
}
#if ZSTD_VERSION_NUMBER < 10308 // ubuntu 18.04 LTS - zstd v1.3.3 / debian stable is v1.3.8
size_t const retValue = ZSTD_initDStream(dctx);
if (ZSTD_isError(retValue))
{
GB.Error("Error while decompressing file, ZSTD_initDStream() failed: &1", ZSTD_getErrorName(retValue));
goto error_ufile;
}
#endif /* ZSTD_VERSION_NUMBER < 10308 */
while(!feof(f_src))
{
size_t len = fread(buffIn, 1, buffInSize, f_src);