]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
extended use of strerror(errno)
authorYann Collet <yann.collet.73@gmail.com>
Sat, 2 Jul 2016 09:14:30 +0000 (11:14 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Sat, 2 Jul 2016 19:01:54 +0000 (21:01 +0200)
programs/datagen.c
programs/datagencli.c
programs/fileio.c

index ec118f5d1b8ce1af9d9ed5e76cfabae02f689960..389b5dbc7c1245d59cce2d970a18efb3df6421c6 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdlib.h>    /* malloc */
 #include <stdio.h>     /* FILE, fwrite, fprintf */
 #include <string.h>    /* memcpy */
+#include <errno.h>     /* errno */
 #include "mem.h"       /* U32 */
 
 
@@ -104,7 +105,7 @@ static BYTE RDG_genChar(U32* seed, const BYTE* ldt)
     U32 const id = RDG_rand(seed) & LTMASK;
     //TRACE(" %u : \n", id);
     //TRACE(" %4u [%4u] ; val : %4u \n", id, id&255, ldt[id]);
-    return (ldt[id]);  /* memory-sanitizer fails here, stating "uninitialized value" when table initialized with 0.0. Checked : table is fully initialized */
+    return ldt[id];  /* memory-sanitizer fails here, stating "uninitialized value" when table initialized with P==0.0. Checked : table is fully initialized */
 }
 
 
@@ -115,8 +116,7 @@ static U32 RDG_rand15Bits (unsigned* seedPtr)
 
 static U32 RDG_randLength(unsigned* seedPtr)
 {
-    if (RDG_rand(seedPtr) & 7)
-        return (RDG_rand(seedPtr) & 0xF);
+    if (RDG_rand(seedPtr) & 7) return (RDG_rand(seedPtr) & 0xF);   /* small length */
     return (RDG_rand(seedPtr) & 0x1FF) + 0xF;
 }
 
@@ -185,10 +185,10 @@ void RDG_genStdout(unsigned long long size, double matchProba, double litProba,
     size_t const stdDictSize = 32 KB;
     BYTE* const buff = (BYTE*)malloc(stdDictSize + stdBlockSize);
     U64 total = 0;
-    BYTE ldt[LTSIZE];
+    BYTE ldt[LTSIZE];   /* literals distribution table */
 
     /* init */
-    if (buff==NULL) { fprintf(stdout, "not enough memory\n"); exit(1); }
+    if (buff==NULL) { fprintf(stderr, "datagen: error: %s \n", strerror(errno)); exit(1); }
     if (litProba<=0.0) litProba = matchProba / 4.5;
     memset(ldt, '0', sizeof(ldt));
     RDG_fillLiteralDistrib(ldt, litProba);
index d437d5cb3b0134395d34cdb9777cef200b4375d4..ecca7015fb010553e37d79d65a3ed81c6f024adb 100644 (file)
@@ -27,8 +27,8 @@
 /*-************************************
 *  Includes
 **************************************/
-#include "util.h"      /* Compiler options */
 #include <stdio.h>     /* fprintf, stderr */
+#include "util.h"      /* Compiler options */
 #include "datagen.h"   /* RDG_generate */
 
 
index d6a42d5b348682938f6bfc78d17ba91cf69b1b92..20fc82dba2460b71c62ee13b8c9ceea16df4f248 100644 (file)
@@ -240,7 +240,7 @@ static size_t FIO_loadFile(void** bufferPtr, const char* fileName)
         fileSize = MAX_DICT_SIZE;
     }
     *bufferPtr = malloc((size_t)fileSize);
-    if (*bufferPtr==NULL) EXM_THROW(34, "Allocation error : not enough memory for dictBuffer");
+    if (*bufferPtr==NULL) EXM_THROW(34, "zstd: %s", strerror(errno));
     { size_t const readSize = fread(*bufferPtr, 1, (size_t)fileSize, fileHandle);
       if (readSize!=fileSize) EXM_THROW(35, "Error reading dictionary file %s", fileName); }
     fclose(fileHandle);
@@ -269,14 +269,14 @@ static cRess_t FIO_createCResources(const char* dictFileName)
     cRess_t ress;
 
     ress.ctx = ZBUFF_createCCtx();
-    if (ress.ctx == NULL) EXM_THROW(30, "Allocation error : can't create ZBUFF context");
+    if (ress.ctx == NULL) EXM_THROW(30, "zstd: allocation error : can't create ZBUFF context");
 
     /* Allocate Memory */
     ress.srcBufferSize = ZBUFF_recommendedCInSize();
     ress.srcBuffer = malloc(ress.srcBufferSize);
     ress.dstBufferSize = ZBUFF_recommendedCOutSize();
     ress.dstBuffer = malloc(ress.dstBufferSize);
-    if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory");
+    if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "zstd: allocation error : not enough memory");
 
     /* dictionary */
     ress.dictBufferSize = FIO_loadFile(&(ress.dictBuffer), dictFileName);
@@ -291,7 +291,7 @@ static void FIO_freeCResources(cRess_t ress)
     free(ress.dstBuffer);
     free(ress.dictBuffer);
     errorCode = ZBUFF_freeCCtx(ress.ctx);
-    if (ZBUFF_isError(errorCode)) EXM_THROW(38, "Error : can't release ZBUFF context resource : %s", ZBUFF_getErrorName(errorCode));
+    if (ZBUFF_isError(errorCode)) EXM_THROW(38, "zstd: error : can't release ZBUFF context resource : %s", ZBUFF_getErrorName(errorCode));
 }