2012-05-28 14:49:29 +00:00
|
|
|
/*
|
|
|
|
* This file is a part of Pcompress, a chunked parallel multi-
|
|
|
|
* algorithm lossless compression and decompression program.
|
|
|
|
*
|
2013-03-07 14:56:48 +00:00
|
|
|
* Copyright (C) 2012-2013 Moinak Ghosh. All rights reserved.
|
2012-05-28 14:49:29 +00:00
|
|
|
* Use is subject to license terms.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2012-07-07 16:48:29 +00:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2012-05-28 14:49:29 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
2013-03-07 14:56:48 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2012-05-28 14:49:29 +00:00
|
|
|
* moinakg@belenix.org, http://moinakg.wordpress.com/
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _UTILS_H
|
|
|
|
#define _UTILS_H
|
|
|
|
|
|
|
|
#include <arpa/nameser_compat.h>
|
2012-12-27 17:36:48 +00:00
|
|
|
#include <arpa/inet.h>
|
2012-05-28 14:49:29 +00:00
|
|
|
#include <sys/types.h>
|
2012-12-27 17:36:48 +00:00
|
|
|
|
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
|
|
|
#define __STDC_FORMAT_MACROS 1
|
|
|
|
#endif
|
|
|
|
|
2012-10-21 15:33:07 +00:00
|
|
|
#include <inttypes.h>
|
2013-10-20 18:24:27 +00:00
|
|
|
#include <sys/param.h>
|
2012-12-27 17:36:48 +00:00
|
|
|
#include <stdint.h>
|
2012-12-28 16:42:38 +00:00
|
|
|
#include <assert.h>
|
2013-11-28 17:12:51 +00:00
|
|
|
#include <string.h>
|
2014-05-04 06:24:33 +00:00
|
|
|
#include <sys/time.h>
|
2014-05-04 15:41:31 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <semaphore.h>
|
2013-01-26 10:09:10 +00:00
|
|
|
#include <cpuid.h>
|
2014-04-27 18:42:51 +00:00
|
|
|
#if defined(sun) || defined(__sun)
|
|
|
|
#include <sys/byteorder.h>
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#include <libkern/OSByteOrder.h>
|
|
|
|
#else
|
|
|
|
#include <byteswap.h>
|
|
|
|
#endif
|
2012-05-28 14:49:29 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-07-10 14:44:23 +00:00
|
|
|
#define DATA_TEXT 1
|
|
|
|
#define DATA_BINARY 2
|
2013-01-14 07:50:07 +00:00
|
|
|
#define EIGHTM (8UL * 1024UL * 1024UL)
|
|
|
|
#define FOURM (4UL * 1024UL * 1024UL)
|
2012-07-10 14:44:23 +00:00
|
|
|
|
2013-03-21 16:30:38 +00:00
|
|
|
#define ONE_PB (1125899906842624ULL)
|
|
|
|
#define ONE_TB (1099511627776ULL)
|
2014-04-27 18:42:51 +00:00
|
|
|
#define ONE_GB (1024UL * 1024UL * 1024UL)
|
2013-04-21 12:41:16 +00:00
|
|
|
#define TWO_MB (2UL * 1024UL * 1024UL)
|
2013-03-21 16:30:38 +00:00
|
|
|
#define FOUR_MB FOURM
|
|
|
|
#define EIGHT_MB EIGHTM
|
|
|
|
#define EIGHT_GB (8589934592ULL)
|
|
|
|
#define SIXTEEN_GB (EIGHT_GB * 2)
|
|
|
|
|
2012-05-31 12:31:34 +00:00
|
|
|
#if !defined(sun) && !defined(__sun)
|
2013-10-20 18:24:27 +00:00
|
|
|
typedef unsigned char uchar_t ;
|
2012-05-31 12:31:34 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
#if ULONG_MAX == 4294967295UL
|
|
|
|
# ifndef UINT64_C
|
|
|
|
# define UINT64_C(n) n ## ULL
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# ifndef UINT64_C
|
|
|
|
# define UINT64_C(n) n ## UL
|
|
|
|
# endif
|
|
|
|
#endif
|
2013-03-04 18:18:12 +00:00
|
|
|
|
|
|
|
#ifndef UINT64_MAX
|
|
|
|
#define UINT64_MAX (18446744073709551615ULL)
|
|
|
|
#endif
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
typedef unsigned long uintptr_t;
|
2013-01-13 16:34:59 +00:00
|
|
|
typedef int32_t bsize_t;
|
2012-05-28 14:49:29 +00:00
|
|
|
|
|
|
|
#undef WORDS_BIGENDIAN
|
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
|
|
|
# define WORDS_BIGENDIAN
|
|
|
|
# ifndef htonll
|
|
|
|
# define htonll(x) (x)
|
|
|
|
# endif
|
|
|
|
# ifndef ntonll
|
|
|
|
# define ntohll(x) (x)
|
|
|
|
# endif
|
2012-05-31 12:31:34 +00:00
|
|
|
# if !defined(sun) && !defined (__sun)
|
2014-04-27 18:42:51 +00:00
|
|
|
# if defined(__APPLE__)
|
|
|
|
# define LE64(x) OSSwapInt64(x)
|
|
|
|
# define LE32(x) OSSwapInt32(x)
|
|
|
|
# define LE16(x) OSSwapInt16(x)
|
|
|
|
# else
|
|
|
|
# define LE64(x) __bswap_64(x)
|
|
|
|
# define LE32(x) __bswap_32(x)
|
|
|
|
# define LE16(x) __bswap_16(x)
|
|
|
|
# endif
|
2012-12-28 16:42:38 +00:00
|
|
|
# else
|
|
|
|
# define LE64(x) BSWAP_64(x)
|
2013-02-12 16:23:04 +00:00
|
|
|
# define LE32(x) BSWAP_32(x)
|
2013-11-22 15:14:26 +00:00
|
|
|
# define LE16(x) BSWAP_16(x)
|
2012-05-28 14:49:29 +00:00
|
|
|
# endif
|
2012-12-28 16:42:38 +00:00
|
|
|
#else
|
|
|
|
# if !defined(sun) && !defined (__sun)
|
2014-04-27 18:42:51 +00:00
|
|
|
# if defined(__APPLE__)
|
|
|
|
# ifndef htonll
|
|
|
|
# define htonll(x) OSSwapInt64(x)
|
|
|
|
# endif
|
|
|
|
# ifndef ntohll
|
|
|
|
# define ntohll(x) OSSwapInt64(x)
|
|
|
|
# endif
|
|
|
|
# else
|
|
|
|
# ifndef htonll
|
|
|
|
# define htonll(x) __bswap_64(x)
|
|
|
|
# endif
|
|
|
|
# ifndef ntohll
|
|
|
|
# define ntohll(x) __bswap_64(x)
|
|
|
|
# endif
|
2012-12-28 16:42:38 +00:00
|
|
|
# endif
|
2012-05-31 12:31:34 +00:00
|
|
|
# endif
|
2012-12-28 16:42:38 +00:00
|
|
|
# define LE64(x) (x)
|
2013-02-12 16:23:04 +00:00
|
|
|
# define LE32(x) (x)
|
2013-11-22 15:14:26 +00:00
|
|
|
# define LE16(x) (x)
|
2012-05-28 14:49:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// These allow helping the compiler in some often-executed branches, whose
|
|
|
|
// result is almost always the same.
|
|
|
|
#ifdef __GNUC__
|
2013-01-24 18:40:12 +00:00
|
|
|
# define likely(expr) __builtin_expect(expr, 1)
|
|
|
|
# define unlikely(expr) __builtin_expect(expr, 0)
|
|
|
|
# define ATOMIC_ADD(var, val) __sync_fetch_and_add(&var, val)
|
|
|
|
# define ATOMIC_SUB(var, val) __sync_fetch_and_sub(&var, val)
|
|
|
|
# define PREFETCH_WRITE(x, n) __builtin_prefetch((x), 1, (n))
|
|
|
|
# define PREFETCH_READ(x, n) __builtin_prefetch((x), 0, (n))
|
2013-05-01 13:57:43 +00:00
|
|
|
# define NOINLINE_ATTR __attribute__((noinline))
|
2012-05-28 14:49:29 +00:00
|
|
|
#else
|
|
|
|
# define likely(expr) (expr)
|
|
|
|
# define unlikely(expr) (expr)
|
2013-01-24 18:40:12 +00:00
|
|
|
# define PREFETCH_WRITE(x, n)
|
|
|
|
# define PREFETCH_READ(x, n)
|
2013-05-01 13:57:43 +00:00
|
|
|
# define NOINLINE_ATTR
|
2012-05-28 14:49:29 +00:00
|
|
|
# if defined(sun) || defined (__sun)
|
|
|
|
# include <atomic.h>
|
|
|
|
# define ATOMIC_ADD(var, val) atomic_add_int(&var, val)
|
|
|
|
# define ATOMIC_SUB(var, val) atomic_add_int(&var, -val)
|
|
|
|
# else
|
|
|
|
// Dunno what to do
|
|
|
|
# define ATOMIC_ADD(var, val) var += val
|
|
|
|
# define ATOMIC_SUB(var, val) var -= val
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2013-06-03 15:21:00 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define DLL_EXPORT __attribute__ ((visibility ("default")))
|
|
|
|
#define DLL_LOCAL __attribute__ ((visibility ("hidden")))
|
|
|
|
#else
|
|
|
|
#define DLL_EXPORT
|
|
|
|
#define DLL_LOCAL
|
|
|
|
#endif
|
|
|
|
|
2012-07-10 14:44:23 +00:00
|
|
|
#define ISP2(x) ((x != 0) && ((x & (~x + 1)) == x))
|
|
|
|
|
2012-08-15 14:43:40 +00:00
|
|
|
#ifdef DEBUG_STATS
|
|
|
|
#define DEBUG_STAT_EN(...) __VA_ARGS__;
|
|
|
|
#else
|
|
|
|
#define DEBUG_STAT_EN(...)
|
|
|
|
#endif
|
|
|
|
|
2013-11-07 16:18:54 +00:00
|
|
|
#define PATHSEP_CHAR '/'
|
2012-12-22 19:14:56 +00:00
|
|
|
#define BYTES_TO_MB(x) ((x) / (1024 * 1024))
|
2013-09-22 14:41:15 +00:00
|
|
|
#define U64_P(x) *((uint64_t *)(x))
|
|
|
|
#define U32_P(x) *((uint32_t *)(x))
|
|
|
|
#define U16_P(x) *((uint16_t *)(x))
|
|
|
|
#define I64_P(x) *((int64_t *)(x))
|
|
|
|
#define I32_P(x) *((int32_t *)(x))
|
|
|
|
#define I16_P(x) *((int16_t *)(x))
|
2012-12-22 19:14:56 +00:00
|
|
|
|
2014-04-27 18:42:51 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#define CLOCK_MONOTONIC 0
|
|
|
|
#define CLOCK_REALTIME 1
|
|
|
|
#endif
|
|
|
|
|
2013-03-20 17:17:03 +00:00
|
|
|
/*
|
|
|
|
* Public checksum properties. CKSUM_MAX_BYTES must be updated if a
|
|
|
|
* newer larger checksum is added to the list.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
CKSUM_CRC64 = 0x100,
|
|
|
|
CKSUM_BLAKE256 = 0x200,
|
|
|
|
CKSUM_BLAKE512 = 0x300,
|
|
|
|
CKSUM_SHA256 = 0x400,
|
|
|
|
CKSUM_SHA512 = 0x500,
|
|
|
|
CKSUM_KECCAK256 = 0x600,
|
|
|
|
CKSUM_KECCAK512 = 0x700,
|
|
|
|
/*
|
|
|
|
* Backwards compatibility options. SKEIN in release 1.2 was replaced with
|
|
|
|
* Blake2 from 1.3 onwards (for sheer speed of Blake2). We want to be able
|
|
|
|
* to decode archives created with 1.2. New archives do not use SKEIN.
|
2013-05-04 10:29:29 +00:00
|
|
|
*
|
|
|
|
* However SKEIN can be used as a chunk/block hash for Global Deduplication.
|
|
|
|
* So it will not be removed.
|
2013-03-20 17:17:03 +00:00
|
|
|
*/
|
|
|
|
CKSUM_SKEIN256 = 0x800,
|
|
|
|
CKSUM_SKEIN512 = 0x900,
|
|
|
|
CKSUM_INVALID = 0
|
|
|
|
} cksum_t;
|
|
|
|
|
2013-02-12 16:23:04 +00:00
|
|
|
typedef enum {
|
|
|
|
COMPRESS_NONE = 0,
|
|
|
|
COMPRESS_LZFX,
|
|
|
|
COMPRESS_LZ4,
|
|
|
|
COMPRESS_ZLIB,
|
|
|
|
COMPRESS_BZIP2,
|
2013-02-17 15:35:40 +00:00
|
|
|
COMPRESS_LZMA,
|
|
|
|
COMPRESS_INVALID
|
2013-02-12 16:23:04 +00:00
|
|
|
} compress_algo_t;
|
|
|
|
|
2012-08-18 04:50:52 +00:00
|
|
|
typedef struct {
|
|
|
|
uint32_t buf_extra;
|
|
|
|
int compress_mt_capable;
|
|
|
|
int decompress_mt_capable;
|
2012-08-27 16:21:55 +00:00
|
|
|
int single_chunk_mt_capable;
|
|
|
|
int is_single_chunk;
|
2012-08-18 04:50:52 +00:00
|
|
|
int nthreads;
|
|
|
|
int c_max_threads;
|
|
|
|
int d_max_threads;
|
2012-12-13 15:48:16 +00:00
|
|
|
int delta2_span;
|
2013-01-14 07:50:07 +00:00
|
|
|
int deltac_min_distance;
|
2013-03-20 17:17:03 +00:00
|
|
|
cksum_t cksum;
|
2012-08-18 04:50:52 +00:00
|
|
|
} algo_props_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
COMPRESS_THREADS = 1,
|
|
|
|
DECOMPRESS_THREADS
|
|
|
|
} algo_threads_type_t;
|
|
|
|
|
2013-03-20 17:17:03 +00:00
|
|
|
typedef struct{
|
|
|
|
int64_t totalram;
|
|
|
|
int64_t freeram;
|
|
|
|
int64_t totalswap;
|
|
|
|
int64_t freeswap;
|
|
|
|
int64_t mem_unit;
|
2013-09-05 15:42:37 +00:00
|
|
|
int64_t sharedram;
|
2013-03-20 17:17:03 +00:00
|
|
|
} my_sysinfo;
|
|
|
|
|
2013-10-27 15:06:48 +00:00
|
|
|
struct fn_list {
|
|
|
|
char *filename;
|
|
|
|
struct fn_list *next;
|
|
|
|
};
|
|
|
|
|
2013-11-08 18:20:28 +00:00
|
|
|
/*
|
|
|
|
* Enumerated type constants for file type identification in pc_archive.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
2013-11-09 11:16:19 +00:00
|
|
|
/*
|
|
|
|
* Primary Types.
|
|
|
|
*/
|
2013-11-08 18:20:28 +00:00
|
|
|
TYPE_UNKNOWN = 0,
|
|
|
|
TYPE_TEXT = 1,
|
|
|
|
TYPE_BINARY = 2,
|
|
|
|
TYPE_COMPRESSED = 4,
|
2013-11-09 11:16:19 +00:00
|
|
|
/*
|
|
|
|
* Sub-types.
|
|
|
|
*/
|
2013-12-30 17:54:37 +00:00
|
|
|
#define NUM_SUB_TYPES 28
|
2013-11-24 14:15:58 +00:00
|
|
|
TYPE_EXE32 = 8,
|
2013-11-13 17:58:01 +00:00
|
|
|
TYPE_JPEG = 16,
|
2013-11-09 11:16:19 +00:00
|
|
|
TYPE_MARKUP = 24,
|
|
|
|
TYPE_COMPRESSED_GZ = 32,
|
|
|
|
TYPE_COMPRESSED_LZW = 40,
|
|
|
|
TYPE_COMPRESSED_BZ2 = 48,
|
|
|
|
TYPE_COMPRESSED_ZIP = 56,
|
|
|
|
TYPE_COMPRESSED_ARJ = 64,
|
|
|
|
TYPE_COMPRESSED_ARC = 72,
|
2013-12-18 17:30:39 +00:00
|
|
|
TYPE_ARCHIVE_AR = 80,
|
2013-11-09 11:16:19 +00:00
|
|
|
TYPE_COMPRESSED_LZMA = 88,
|
|
|
|
TYPE_COMPRESSED_LZO = 96,
|
2013-12-04 14:37:52 +00:00
|
|
|
TYPE_AVI = 104,
|
2013-12-03 16:26:07 +00:00
|
|
|
TYPE_MP4 = 112,
|
|
|
|
TYPE_FLAC = 120,
|
2013-11-09 11:16:19 +00:00
|
|
|
TYPE_COMPRESSED_RAR = 128,
|
|
|
|
TYPE_COMPRESSED_LZ = 136,
|
|
|
|
TYPE_COMPRESSED_PPMD = 144,
|
2013-11-13 17:58:01 +00:00
|
|
|
TYPE_COMPRESSED_ZPAQ = 152,
|
2013-11-22 15:14:26 +00:00
|
|
|
TYPE_PACKJPG = 160,
|
|
|
|
TYPE_DNA_SEQ = 168,
|
|
|
|
TYPE_MJPEG = 176,
|
2013-11-24 14:15:58 +00:00
|
|
|
TYPE_AUDIO_COMPRESSED = 184,
|
2013-11-28 17:12:51 +00:00
|
|
|
TYPE_EXE64 = 192,
|
2013-11-29 14:17:57 +00:00
|
|
|
TYPE_BMP = 200,
|
2013-12-30 17:54:37 +00:00
|
|
|
TYPE_TIFF = 208,
|
|
|
|
TYPE_PDF = 216,
|
2014-01-01 14:14:58 +00:00
|
|
|
TYPE_ARCHIVE_TAR = 224,
|
|
|
|
TYPE_DICOM = 232
|
2013-11-08 18:20:28 +00:00
|
|
|
} data_type_t;
|
|
|
|
|
2013-11-09 11:16:19 +00:00
|
|
|
/*
|
|
|
|
* Type identifier is an int with the following format.
|
|
|
|
*
|
|
|
|
* Sub Type Primary Type
|
|
|
|
* (Numeric Value) (Bit Positions - Flags)
|
|
|
|
* _____________|_____________ ___|___
|
|
|
|
* | | | |
|
|
|
|
* .---------------------------------------.
|
|
|
|
* | | | | | | | | | | |
|
|
|
|
* Bit 10 Bit 0
|
|
|
|
*/
|
|
|
|
#define PC_TYPE_MASK 0x7
|
|
|
|
#define PC_SUBTYPE_MASK 0x7f8
|
|
|
|
#define PC_SUBTYPE(x) ((x) & PC_SUBTYPE_MASK)
|
|
|
|
#define PC_TYPE(x) ((x) & PC_TYPE_MASK)
|
|
|
|
|
2013-01-24 18:40:12 +00:00
|
|
|
#ifndef _IN_UTILS_
|
2014-04-27 18:42:51 +00:00
|
|
|
extern processor_cap_t proc_info;
|
2013-01-24 18:40:12 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
extern void err_exit(int show_errno, const char *format, ...);
|
2013-06-02 15:24:33 +00:00
|
|
|
extern void err_print(int show_errno, const char *format, ...);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern const char *get_execname(const char *);
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int parse_numeric(int64_t *val, const char *str);
|
2012-05-31 16:06:33 +00:00
|
|
|
extern char *bytes_to_size(uint64_t bytes);
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int64_t Read(int fd, void *buf, uint64_t count);
|
|
|
|
extern int64_t Read_Adjusted(int fd, uchar_t *buf, uint64_t count,
|
2013-11-02 18:13:59 +00:00
|
|
|
int64_t *rabin_count, void *ctx, void *pctx);
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int64_t Write(int fd, const void *buf, uint64_t count);
|
2012-08-18 04:50:52 +00:00
|
|
|
extern void set_threadcounts(algo_props_t *props, int *nthreads, int nprocs,
|
|
|
|
algo_threads_type_t typ);
|
2012-10-17 18:02:35 +00:00
|
|
|
extern uint64_t get_total_ram();
|
2012-12-22 19:14:56 +00:00
|
|
|
extern double get_wtime_millis(void);
|
|
|
|
extern double get_mb_s(uint64_t bytes, double strt, double en);
|
2013-04-09 16:53:51 +00:00
|
|
|
extern void get_sys_limits(my_sysinfo *msys_info);
|
2013-04-22 17:27:31 +00:00
|
|
|
extern int chk_dir(char *dir);
|
2012-12-27 17:36:48 +00:00
|
|
|
extern void init_algo_props(algo_props_t *props);
|
2013-01-24 18:40:12 +00:00
|
|
|
extern void init_pcompress();
|
2013-10-20 18:24:27 +00:00
|
|
|
extern char *get_temp_dir();
|
2014-05-24 18:22:30 +00:00
|
|
|
extern int file_exists(char *path);
|
2012-07-01 16:14:02 +00:00
|
|
|
|
|
|
|
/* Pointer type for compress and decompress functions. */
|
2012-12-09 04:45:06 +00:00
|
|
|
typedef int (*compress_func_ptr)(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *destlen, int level, uchar_t chdr, int btype, void *data);
|
2012-07-01 16:14:02 +00:00
|
|
|
|
2012-11-22 15:32:50 +00:00
|
|
|
typedef enum {
|
|
|
|
COMPRESS,
|
|
|
|
DECOMPRESS
|
|
|
|
} compress_op_t;
|
|
|
|
|
2012-07-01 16:14:02 +00:00
|
|
|
/* Pointer type for algo specific init/deinit/stats functions. */
|
2012-12-27 17:36:48 +00:00
|
|
|
typedef int (*init_func_ptr)(void **data, int *level, int nthreads, uint64_t chunksize,
|
2012-11-22 15:32:50 +00:00
|
|
|
int file_version, compress_op_t op);
|
2012-07-01 16:14:02 +00:00
|
|
|
typedef int (*deinit_func_ptr)(void **data);
|
|
|
|
typedef void (*stats_func_ptr)(int show);
|
2012-12-27 17:36:48 +00:00
|
|
|
typedef void (*props_func_ptr)(algo_props_t *data, int level, uint64_t chunksize);
|
2012-07-01 16:14:02 +00:00
|
|
|
|
2013-10-02 15:15:33 +00:00
|
|
|
/*
|
|
|
|
* Logging definitions.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
LOG_OUTPUT,
|
|
|
|
LOG_FILE,
|
|
|
|
LOG_CALLBACK
|
|
|
|
} log_dest_type_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LOG_ERR,
|
|
|
|
LOG_WARN,
|
|
|
|
LOG_INFO
|
|
|
|
} log_level_t;
|
|
|
|
|
|
|
|
typedef void (*log_callback_ptr)(char *msg);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
log_dest_type_t type;
|
|
|
|
int fd;
|
|
|
|
log_callback_ptr cb;
|
|
|
|
} log_dest_t;
|
|
|
|
|
|
|
|
void set_log_dest(log_dest_t *dest);
|
|
|
|
void set_log_level(int level);
|
|
|
|
void log_msg(log_level_t log_level, int show_errno, const char *format, ...);
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2013-10-20 18:24:27 +00:00
|
|
|
/*
|
|
|
|
* Tempfile cleanup handlers and tempfile registration routines.
|
|
|
|
*/
|
|
|
|
void Int_Handler(int signo);
|
|
|
|
void handle_signals();
|
|
|
|
void add_fname(char *fn);
|
|
|
|
void rm_fname(char *fn);
|
|
|
|
|
2013-11-15 15:36:23 +00:00
|
|
|
/*
|
|
|
|
* Some types (like Jpeg) are totally incompressible.
|
|
|
|
*/
|
|
|
|
int is_incompressible(int type);
|
|
|
|
|
2014-05-04 06:24:33 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
int clock_gettime(int clk_id, struct timespec *ts);
|
|
|
|
#endif
|
|
|
|
|
2014-05-04 15:41:31 +00:00
|
|
|
/*
|
|
|
|
* Routines to handle compatibility.
|
|
|
|
*/
|
|
|
|
typedef struct _compat_sem {
|
|
|
|
char name[15];
|
|
|
|
sem_t sem, *sem1;
|
|
|
|
} Sem_t;
|
|
|
|
|
|
|
|
int Sem_Init(Sem_t *sem, int pshared, int value);
|
|
|
|
int Sem_Destroy(Sem_t *sem);
|
|
|
|
int Sem_Post(Sem_t *sem);
|
|
|
|
int Sem_Wait(Sem_t *sem);
|
|
|
|
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
/*
|
|
|
|
* Roundup v to the nearest power of 2. From Bit Twiddling Hacks:
|
|
|
|
* http://graphics.stanford.edu/~seander/bithacks.html
|
|
|
|
*/
|
|
|
|
static inline unsigned int
|
|
|
|
roundup_pow_two(unsigned int v) {
|
|
|
|
v--;
|
|
|
|
v |= v >> 1;
|
|
|
|
v |= v >> 2;
|
|
|
|
v |= v >> 4;
|
|
|
|
v |= v >> 8;
|
|
|
|
v |= v >> 16;
|
|
|
|
v++;
|
|
|
|
return (v);
|
|
|
|
}
|
|
|
|
|
2013-11-28 17:12:51 +00:00
|
|
|
static inline int
|
|
|
|
endswith(char *haystack, char *needle) {
|
|
|
|
size_t len = strlen(haystack);
|
|
|
|
size_t nlen = strlen(needle);
|
|
|
|
if (nlen > len)
|
|
|
|
return (0);
|
|
|
|
size_t pos = len - nlen;
|
|
|
|
if (memcmp(&haystack[pos], needle, nlen) != 0)
|
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|