From: Aurelien DARRAGON Date: Fri, 21 Aug 2026 16:01:40 +0000 (+0200) Subject: IMPORT: slz/uslz: support SLZ_FMT_NONE format and force its value to 0 X-Git-Tag: v3.5-dev6~89 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=50872daa6a857e82afc40b1c5161924aef4172d7;p=haproxy.git IMPORT: slz/uslz: support SLZ_FMT_NONE format and force its value to 0 For library users that rely on SLZ_FMT_* (through uslz_init_fmt()), it is useful to have a default value that does nothing and can be compared against, as users will typically store the fmt in a dedicated variable or within a structure which will be zero-initialized. Having the SLZ_FMT_NONE alias is also useful to compare a stored fmt value against it to know whether or not it was set to an other value than the default one. As a bonus, uslz_init_fmt() also supports the SLZ_FMT_NONE instead of returning an error, this way, uslz_init_fmt() can be used in place of uslz_init() even when no compression is needed, which can help write more generic code for library users where they just need to pass the fmt value as argument and let the library to its job. This is libslz upstream commit 4adc28e64716f3db5df9a1edc6eeb9234a37f6ad --- diff --git a/include/import/slz.h b/include/import/slz.h index 46cd5f4ab..5c2d2e3ef 100644 --- a/include/import/slz.h +++ b/include/import/slz.h @@ -56,6 +56,11 @@ enum slz_state { }; enum { + SLZ_FMT_NONE = 0,/* default value, this way this ensure library users storing the + * the fmt value in a structure that is zero-initialized have no + * FMT by default, plus they have a way to know if a fmt was + * selected or not by comparing it with this value + */ SLZ_FMT_GZIP, /* RFC1952: gzip envelope and crc32 for CRC */ SLZ_FMT_ZLIB, /* RFC1950: zlib envelope and adler-32 for CRC */ SLZ_FMT_DEFLATE, /* RFC1951: raw deflate, and no crc */ diff --git a/src/uslz.c b/src/uslz.c index 5c2ba03ce..84992f7ad 100644 --- a/src/uslz.c +++ b/src/uslz.c @@ -1584,6 +1584,9 @@ int uslz_init_fmt(struct uslz_stream *state, unsigned char *output_buffer, return 0; switch (format) { + case SLZ_FMT_NONE: + /* nothing to do */ + break; case SLZ_FMT_DEFLATE: /* nothing to detect nor to skip, the first bits are already * the first block header.