RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 05-Jun-2017 02:56:36 Branch: rpm-5_4 Handle: 2017060500563600 Modified files: (Branch: rpm-5_4) rpm/rpmio rpmzstd.c Log: - rpmzstd: turn on zlib/lz4/lzma and pthreads. Summary: Revision Changes Path 1.1.2.5 +61 -33 rpm/rpmio/rpmzstd.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/rpmio/rpmzstd.c ============================================================================ $ cvs diff -u -r1.1.2.4 -r1.1.2.5 rpmzstd.c --- rpm/rpmio/rpmzstd.c 4 Jun 2017 23:09:45 -0000 1.1.2.4 +++ rpm/rpmio/rpmzstd.c 5 Jun 2017 00:56:36 -0000 1.1.2.5 @@ -8,8 +8,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#define ZSTD_NOBENCH -#define ZSTD_NODICT +#define ZSTD_NOBENCH 1 +#define ZSTD_NODICT 1 #undef POPTIO_OPTIONS /* XXX NOTYET: <poptIO.h> option/arg processing. */ #define USE_RPMIO @@ -17,8 +17,28 @@ #include "system.h" +#if defined(WITH_PTHREAD) +#define ZSTD_MULTITHREAD 1 +#endif + +#if defined(WITH_LZ4) +#define ZSTD_LZ4COMPRESS 1 +#define ZSTD_LZ4DECOMPRESS 1 +#endif + +#if defined(WITH_ZLIB) +#define ZSTD_GZCOMPRESS 1 +#define ZSTD_GZDECOMPRESS 1 +#endif + +#if defined(WITH_XZ) +#define ZSTD_LZMACOMPRESS 1 +#define ZSTD_LZMADECOMPRESS 1 +#endif + #if defined(USE_RPMIO) #include <rpmio_internal.h> +#include <rpmdir.h> #else typedef FILE * FD_t; #define Fopen fopen @@ -29,6 +49,13 @@ #define Ferror ferror #define Stat stat #define Lstat lstat +#define Unlink remove +#define Chmod chmod +#define Chown chown +#define Utime utime +#define Opendir opendir +#define Readdir readdir +#define Closedir closedir #endif #include <rpmmacro.h> @@ -1142,13 +1169,13 @@ timebuf.actime = time(NULL); timebuf.modtime = st->st_mtime; - res += utime(filename, &timebuf); /* set access and modification times */ + res += Utime(filename, &timebuf); /* set access and modification times */ #if !defined(_WIN32) - res += chown(filename, st->st_uid, st->st_gid); /* Copy ownership */ + res += Chown(filename, st->st_uid, st->st_gid); /* Copy ownership */ #endif - res += chmod(filename, st->st_mode & 07777); /* Copy file permissions */ + res += Chmod(filename, st->st_mode & 07777); /* Copy file permissions */ errno = 0; return -res; /* number of errors is returned */ @@ -1330,19 +1357,19 @@ int pathLength; int nbFiles = 0; - if (!(dir = opendir(dirName))) { + if (!(dir = Opendir(dirName))) { fprintf(stderr, "Cannot open directory '%s': %s\n", dirName, strerror(errno)); return 0; } dirLength = (int)strlen(dirName); errno = 0; - while ((entry = readdir(dir)) != NULL) { + while ((entry = Readdir(dir)) != NULL) { if (strcmp (entry->d_name, "..") == 0 || strcmp (entry->d_name, ".") == 0) continue; fnameLength = (int)strlen(entry->d_name); path = (char *) malloc(dirLength + fnameLength + 2); - if (!path) { closedir(dir); return 0; } + if (!path) { Closedir(dir); return 0; } memcpy(path, dirName, dirLength); path[dirLength] = '/'; @@ -1357,13 +1384,13 @@ if (UTIL_isDirectory(path)) { nbFiles += UTIL_prepareFileList(path, bufStart, pos, bufEnd, followLinks); /* Recursively call "UTIL_prepareFileList" with the new path. */ - if (*bufStart == NULL) { free(path); closedir(dir); return 0; } + if (*bufStart == NULL) { free(path); Closedir(dir); return 0; } } else { if (*bufStart + *pos + pathLength >= *bufEnd) { ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE; *bufStart = (char *)UTIL_realloc(*bufStart, newListSize); *bufEnd = *bufStart + newListSize; - if (*bufStart == NULL) { free(path); closedir(dir); return 0; } + if (*bufStart == NULL) { free(path); Closedir(dir); return 0; } } if (*bufStart + *pos + pathLength < *bufEnd) { strncpy(*bufStart + *pos, path, *bufEnd - (*bufStart + *pos)); @@ -1380,7 +1407,7 @@ free(*bufStart); *bufStart = NULL; } - closedir(dir); + Closedir(dir); return nbFiles; } @@ -1577,7 +1604,7 @@ /* try to determine if there's hyperthreading */ { - FILE * const cpuinfo = fopen("/proc/cpuinfo", "r"); + FD_t fd = Fopen("/proc/cpuinfo", "r.fpio"); #define BUF_SIZE 80 char buff[BUF_SIZE]; @@ -1585,15 +1612,16 @@ int cpu_cores = 0; int ratio = 1; - if (cpuinfo == NULL) { + if (fd == NULL) { /* fall back on the sysconf value */ return numPhysicalCores; } + FILE * fp = fdGetFILE(fd); /* assume the cpu cores/siblings values will be constant across all * present processors */ - while (!feof(cpuinfo)) { - if (fgets(buff, BUF_SIZE, cpuinfo) != NULL) { + while (!feof(fp)) { + if (fgets(buff, BUF_SIZE, fp) != NULL) { if (strncmp(buff, "siblings", 8) == 0) { const char * const sep = strchr(buff, ':'); if (*sep == '\0') { @@ -1612,7 +1640,7 @@ cpu_cores = atoi(sep + 1); } - } else if (ferror(cpuinfo)) { + } else if (ferror(fp)) { /* fall back on the sysconf value */ goto failed; } @@ -1621,7 +1649,7 @@ ratio = siblings / cpu_cores; } failed: - fclose(cpuinfo); + Fclose(fd); return numPhysicalCores = numPhysicalCores / ratio; } } @@ -2432,14 +2460,14 @@ size_t totalSize = 0; size_t pos = 0; for (unsigned n = 0; n < ac; n++) { - FILE * fp; + FD_t fd; U64 fileSize = UTIL_getFileSize(av[n]); if (UTIL_isDirectory(av[n])) { DISPLAYLEVEL(2, "Ignoring %s directory... \n", av[n]); fileSizes[n] = 0; continue; } - fp = fopen(av[n], "rb"); + fd = Fopen(av[n], "rb"); if (fp == NULL) EXM_THROW(10, "impossible to open file %s", av[n]); DISPLAYUPDATE(2, "Loading %s... \r", av[n]); /* buffer too small - stop after this file */ @@ -2447,12 +2475,12 @@ fileSize = bufferSize-pos; ac = n; } - { size_t const readSize = fread(((char *)buffer)+pos, 1, (size_t)fileSize, fp); + { size_t const readSize = Fread(((char *)buffer)+pos, 1, (size_t)fileSize, fd); if (readSize != (size_t)fileSize) EXM_THROW(11, "could not read %s", av[n]); pos += readSize; } fileSizes[n] = (size_t)fileSize; totalSize += (size_t)fileSize; - fclose(fp); + Fclose(fd); } if (totalSize == 0) EXM_THROW(12, "no data to bench"); @@ -2639,14 +2667,14 @@ size_t const fileSize = (size_t) MIN(fs64, SAMPLESIZE_MAX); if (fileSize > *bufferSizePtr-pos) break; { - FILE * const fp = fopen(fn, "rb"); + FD_t fd = Fopen(fn, "rb"); if (fp == NULL) EXM_THROW(10, "zstd: dictBuilder: %s %s ", fn, strerror(errno)); DISPLAYUPDATE(2, "Loading %s... \r", fn); - { size_t const readSize = fread(buff+pos, 1, fileSize, fp); + { size_t const readSize = Fread(buff+pos, 1, fileSize, fd); if (readSize != fileSize) EXM_THROW(11, "Pb reading %s", fn); pos += readSize; } fileSizes[n] = fileSize; - fclose(fp); + Fclose(fd); } } DISPLAYLEVEL(2, "\r%79s\r", ""); *bufferSizePtr = pos; @@ -2724,14 +2752,14 @@ static void DiB_saveDict(const char * dfn, const void * buff, size_t buffSize) { -SPEW("-->\t%s()\n", __FUNCTION__); - FILE * const fp = fopen(dfn, "wb"); - if (fp == NULL) EXM_THROW(3, "cannot open %s ", dfn); +SPEW("-->\t%s(%s, %p[%zu])\n", __FUNCTION__, dfn, buff, buffSize); + FD_t fd = Fopen(dfn, "wb"); + if (fd == NULL) EXM_THROW(3, "cannot open %s ", dfn); - { size_t const n = fwrite(buff, 1, buffSize, fp); + { size_t const n = Fwrite(buff, 1, buffSize, fd); if (n!=buffSize) EXM_THROW(4, "%s : write error", dfn) } - { size_t const n = (size_t)fclose(fp); + { size_t const n = (size_t)Fclose(fd); if (n!=0) EXM_THROW(5, "%s : flush error", dfn) } } @@ -3033,9 +3061,9 @@ #if defined(_WIN32) || defined(WIN32) /* windows doesn't allow remove read-only files, * so try to make it writable first */ - chmod(path, _S_IWRITE); + Chmod(path, _S_IWRITE); #endif - rc = remove(path); + rc = Unlink(path); SPEW("<--\t%s(%s) rc %d\n", __FUNCTION__, path, rc); return rc; } @@ -3294,7 +3322,7 @@ EXM_THROW(72, "zstd: %s: deflate error %d \n", srcfn, ret); { size_t const decompBytes = ress->dstBufferSize - strm.avail_out; if (decompBytes) { - if (fwrite(ress->dstBuffer, 1, decompBytes, ress->dstfd) != decompBytes) + if (Fwrite(ress->dstBuffer, 1, decompBytes, ress->dstfd) != decompBytes) EXM_THROW(73, "Write error : cannot write to output file"); outFileSize += decompBytes; strm.next_out = (Bytef*)ress->dstBuffer; @@ -4223,7 +4251,7 @@ if (!nextToLoad) break; } } - /* can be out because readSize == 0, which could be an fread() error */ + /* can be out because readSize == 0, which could be an Fread() error */ if (Ferror(srcfd)) EXM_THROW(67, "zstd: %s: read error", srcfn); if (nextToLoad!=0) EXM_THROW(68, "zstd: %s: unfinished stream", srcfn); @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org