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
};
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 */
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.