Mercurial > hg > dmlib
diff src/dmres.c @ 2586:9807ae37ad69
Require stdbool.h, we require C11 now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 08 Dec 2022 15:59:22 +0200 |
parents | 92b93a12c014 |
children |
line wrap: on
line diff
--- a/src/dmres.c Thu Dec 08 15:56:36 2022 +0200 +++ b/src/dmres.c Thu Dec 08 15:59:22 2022 +0200 @@ -252,7 +252,7 @@ } -static BOOL dm_stdio_feof(DMResource *fh) +static bool dm_stdio_feof(DMResource *fh) { return feof(fh->fh); } @@ -375,7 +375,7 @@ int ret = DMERR_OK, zret, cdataLeft; Uint8 * cbuffer = NULL; z_stream zstr; - BOOL zinit = FALSE; + bool zinit = false; // Allocate a structures and buffers if ((cbuffer = dmMalloc(DMRES_TMPBUF_SIZE)) == NULL) @@ -396,7 +396,7 @@ "Could not initialize zlib stream decompression.\n"); goto out; } - zinit = TRUE; + zinit = true; // Uncompress the data while (cdataLeft > 0 && zstr.avail_out > 0 && zret == Z_OK) @@ -451,10 +451,10 @@ zctx.inBufferEnd = inBuf + node->csize; zctx.outBuffer = zctx.outBufferStart = handle->memData; zctx.outBufferEnd = handle->memData + node->size; - zctx.expandable = FALSE; + zctx.expandable = false; // Attempt decompression - if ((ret = dmZLibParseHeader(&zctx, TRUE)) != DMERR_OK) + if ((ret = dmZLibParseHeader(&zctx, true)) != DMERR_OK) goto out; if ((ret = dmZLibInflate(&zctx)) != DMERR_OK) @@ -566,7 +566,7 @@ #endif -static BOOL dm_mem_realloc(DMResource *ctx, const size_t newSize) +static bool dm_mem_realloc(DMResource *ctx, const size_t newSize) { size_t grow; @@ -574,7 +574,7 @@ if (ctx->maxSize > 0 && newSize > ctx->maxSize) { ctx->status = DMERR_BOUNDS; - return FALSE; + return false; } // New size is smaller than old @@ -589,7 +589,7 @@ if (ctx->maxSize > 0 && ctx->memAlloc + grow >= ctx->maxSize) { ctx->status = DMERR_BOUNDS; - return FALSE; + return false; } // Grow the buffer @@ -597,13 +597,13 @@ if ((ctx->memData = dmRealloc(ctx->memData, ctx->memAlloc)) == NULL) { ctx->status = DMERR_MALLOC; - return FALSE; + return false; } out: ctx->memSize = newSize; - return TRUE; + return true; } @@ -669,7 +669,7 @@ } -static BOOL dm_mem_feof(DMResource *ctx) +static bool dm_mem_feof(DMResource *ctx) { return ((size_t) ctx->memOffset) >= ctx->memSize; } @@ -977,7 +977,7 @@ } -BOOL dmfeof(DMResource *fh) +bool dmfeof(DMResource *fh) { return fh->fops->feof(fh); } @@ -1109,7 +1109,7 @@ int dmResourcesInit(DMResourceLib **plib, const char *filename, const char *path, const int flags, int (*classifier)(DMResource *)) { DMResourceLib *lib; - BOOL initialized = FALSE; + bool initialized = false; // Allocate the resource library structure if ((*plib = lib = dmMalloc0(sizeof(DMResourceLib))) == NULL) @@ -1129,7 +1129,7 @@ lib->packFilename = dm_strdup(filename); // Initialize PACK, open as read-only - ret = dmPackOpen(lib->packFilename, &lib->packFile, TRUE); + ret = dmPackOpen(lib->packFilename, &lib->packFile, true); if (ret != DMERR_OK) { if ((flags & DRF_USE_STDIO) == 0) @@ -1163,7 +1163,7 @@ dmResourceInsert(lib, res); } - initialized = TRUE; + initialized = true; } } #else @@ -1177,7 +1177,7 @@ int ret = dmResourcesLoadDirectory(lib, lib->resPath); if (ret != DMERR_OK) return ret; - initialized = TRUE; + initialized = true; } #endif @@ -1243,7 +1243,7 @@ } -int dmResourcesPreload(DMResourceLib *lib, BOOL start, int *loaded, int *total) +int dmResourcesPreload(DMResourceLib *lib, bool start, int *loaded, int *total) { int ret = DMERR_OK; @@ -1320,13 +1320,13 @@ } -BOOL dmf_read_str(DMResource *fh, void *ptr, const size_t len) +bool dmf_read_str(DMResource *fh, void *ptr, const size_t len) { return dmfread(ptr, len, 1, fh) == 1; } -BOOL dmf_read_byte(DMResource *fh, Uint8 *val) +bool dmf_read_byte(DMResource *fh, Uint8 *val) { int tmp = dmfgetc(fh); *val = tmp; @@ -1335,12 +1335,12 @@ #define DM_DEFINE_FFUNC(xname, xtype, xmacro) \ -BOOL dmf_read_ ## xname (DMResource *fh, xtype *val) { \ +bool dmf_read_ ## xname (DMResource *fh, xtype *val) { \ xtype result; \ if (dmfread(&result, sizeof( xtype ), 1, fh) != 1) \ - return FALSE; \ + return false; \ *val = DM_ ## xmacro ## _TO_NATIVE (result); \ - return TRUE; \ + return true; \ } #include "dmfiletmpl.h"