changed definition of UTIL_createFileList

This commit is contained in:
inikep 2016-05-13 10:52:02 +02:00
parent 37aba8b1d9
commit 0bdb6a8118
3 changed files with 34 additions and 27 deletions

View File

@ -513,7 +513,7 @@ int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
char* buf;
const char** filenameTable;
unsigned i;
nbFiles = UTIL_createFileList(fileNamesTable, nbFiles, &filenameTable, &buf);
filenameTable = UTIL_createFileList(fileNamesTable, nbFiles, &buf, &nbFiles);
if (filenameTable) {
for (i=0; i<nbFiles; i++) DISPLAYLEVEL(3, "%d %s\n", i, filenameTable[i]);
BMK_benchFileTable(filenameTable, nbFiles, dictFileName, cLevel, cLevelLast);

View File

@ -324,18 +324,24 @@ UTIL_STATIC int UTIL_prepareFileList(const char *dirName, char** bufStart, size_
#endif // #ifdef _WIN32
UTIL_STATIC int UTIL_createFileList(const char **inputNames, unsigned nbNames, const char*** filenameTable, char** allocatedBuffer)
/*
* UTIL_createFileList - takes a list of files and directories (params: inputNames, inputNamesNb), scans directories,
* and returns a new list of files (params: return value, allocatedBuffer, allocatedNamesNb).
* After finishing usage of the list the structures should be freed with UTIL_freeFileList(params: return value, allocatedBuffer)
* In case of error UTIL_createFileList returns NULL and UTIL_freeFileList should not be called.
*/
UTIL_STATIC const char** UTIL_createFileList(const char **inputNames, unsigned inputNamesNb, char** allocatedBuffer, unsigned* allocatedNamesNb)
{
size_t pos;
unsigned i, nbFiles = 0;
unsigned i, nbFiles;
char *bufend, *buf;
const char** fileTable;
buf = (char*)malloc(LIST_SIZE_INCREASE);
if (!buf) { *filenameTable = NULL; return 0; }
if (!buf) return NULL;
bufend = buf + LIST_SIZE_INCREASE;
for (i=0, pos=0; i<nbNames; i++) {
for (i=0, pos=0, nbFiles=0; i<inputNamesNb; i++) {
if (UTIL_doesFileExists(inputNames[i])) {
// printf ("UTIL_doesFileExists=[%s]\n", inputNames[i]);
size_t len = strlen(inputNames[i]);
@ -343,7 +349,7 @@ UTIL_STATIC int UTIL_createFileList(const char **inputNames, unsigned nbNames, c
ptrdiff_t newListSize = (bufend - buf) + LIST_SIZE_INCREASE;
buf = (char*)realloc(buf, newListSize);
bufend = buf + newListSize;
if (!buf) { *filenameTable = NULL; return 0; }
if (!buf) return NULL;
}
if (buf + pos + len < bufend) {
strncpy(buf + pos, inputNames[i], bufend - (buf + pos));
@ -354,15 +360,14 @@ UTIL_STATIC int UTIL_createFileList(const char **inputNames, unsigned nbNames, c
else
{
nbFiles += UTIL_prepareFileList(inputNames[i], &buf, &pos, &bufend);
if (buf == NULL) { *filenameTable = NULL; return 0; }
if (buf == NULL) return NULL;
}
}
{ const char** fileTable = (const char**)malloc((nbFiles+1) * sizeof(const char*));
if (!fileTable) { free(buf); *filenameTable = NULL; return 0; }
if (nbFiles == 0) { free(buf); return NULL; }
if (nbFiles == 0)
fileTable[0] = buf;
fileTable = (const char**)malloc((nbFiles+1) * sizeof(const char*));
if (!fileTable) { free(buf); return NULL; }
for (i=0, pos=0; i<nbFiles; i++)
{
@ -370,18 +375,19 @@ UTIL_STATIC int UTIL_createFileList(const char **inputNames, unsigned nbNames, c
pos += strlen(fileTable[i]) + 1;
}
*filenameTable = fileTable;
*allocatedBuffer = buf;
}
if (buf + pos > bufend) { free(buf); free((void*)fileTable); return NULL; }
return nbFiles;
*allocatedBuffer = buf;
*allocatedNamesNb = nbFiles;
return fileTable;
}
UTIL_STATIC void UTIL_freeFileList(const char** filenameTable, char* buf)
UTIL_STATIC void UTIL_freeFileList(const char** filenameTable, char* allocatedBuffer)
{
free(buf);
free((void*)filenameTable);
if (allocatedBuffer) free(allocatedBuffer);
if (filenameTable) free((void*)filenameTable);
}

View File

@ -29,7 +29,7 @@ The linking should be changed to:
```gcc project.o zlib_wrapper.o -lz -lzstd```
#### Using the zstd wrapper with your project
#### Enabling zstd compression within your project
After embedding the zstd wrapper within your project the zstd library is turned off by default.
Your project should work as before with zlib. There are two options to enable zstd compression:
@ -51,8 +51,9 @@ large_inflate(): OK
after inflateSync(): hello, hello!
inflate with dictionary: hello, hello!
```
Then we have compiled the [example.c](examples/example.c) file with ```-DZWRAP_USE_ZSTD=1``` and linked with additional ```zlib_wrapper.o -lzstd```.
We have also turned of the following functions: test_gzio, test_flush, test_sync which use currently unsupported features.
Then we have changed ```#include "zlib.h"``` to ```#include "zstd_zlibwrapper.h"```, compiled the [example.c](examples/example.c) file
with ```-DZWRAP_USE_ZSTD=1``` and linked with additional ```zlib_wrapper.o -lzstd```.
We were forced to turn off the following functions: ```test_gzio```, ```test_flush```, ```test_sync``` which use currently unsupported features.
After running it shows the following results:
```
zlib version 1.2.8 = 0x1280, compile flags = 0x65