SET(CR_MAJOR "0")
-SET(CR_MINOR "1")
-SET(CR_PATCH "17")
+SET(CR_MINOR "2")
+SET(CR_PATCH "0")
#include <stdio.h>
#include <magic.h>
#include <assert.h>
+#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <zlib.h>
#include <bzlib.h>
#include <lzma.h>
#include "logging.h"
+#include "error.h"
#include "compression_wrapper.h"
/*
cr_CompressionType
-cr_detect_compression(const char *filename)
+cr_detect_compression(const char *filename, GError **err)
{
cr_CompressionType type = CR_CW_UNKNOWN_COMPRESSION;
+ assert(filename);
+ assert(!err || *err == NULL);
+
if (!g_file_test(filename, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
g_debug("%s: File %s doesn't exists or it's not a regular file",
__func__, filename);
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_NOFILE,
+ "File %s doesn't exists or it's not a regular file.", filename);
return type;
}
// No success? Let's get hardcore... (Use magic bytes)
- //magic_t myt = magic_open(MAGIC_MIME_TYPE);
magic_t myt = magic_open(MAGIC_MIME);
- magic_load(myt, NULL);
+ if (myt == NULL) {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_MAGIC,
+ "magic_open() failed: Cannot allocate the magic cookie");
+ return type;
+ }
+
+ if (magic_load(myt, NULL) == -1) {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_MAGIC,
+ "magic_load() failed: %s", magic_error(myt));
+ return type;
+ }
+
if (magic_check(myt, NULL) == -1) {
- g_critical("%s: magic_check() failed", __func__);
+ g_critical("%s: magic_check() failed: %s", __func__, magic_error(myt));
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_MAGIC,
+ "magic_check() failed: %s", magic_error(myt));
return type;
}
type = CR_CW_NO_COMPRESSION;
}
} else {
- g_debug("%s: Mime type not detected! (%s)", __func__, filename);
+ g_debug("%s: Mime type not detected! (%s): %s", __func__, filename,
+ magic_error(myt));
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_MAGIC,
+ "mime_type() detection failed: %s", magic_error(myt));
}
// Xml detection
if (type == CR_CW_UNKNOWN_COMPRESSION && g_str_has_suffix(filename, ".xml"))
- {
type = CR_CW_NO_COMPRESSION;
- }
magic_close(myt);
}
+static char *
+cr_gz_strerror(gzFile f)
+{
+ char *msg = "";
+ int errnum = Z_ERRNO;
+
+ msg = (char *) gzerror(f, &errnum);
+ if (errnum == Z_ERRNO)
+ msg = strerror(errno);
+ return msg;
+}
+
+
CR_FILE *
-cr_open(const char *filename, cr_OpenMode mode, cr_CompressionType comtype)
+cr_open(const char *filename,
+ cr_OpenMode mode,
+ cr_CompressionType comtype,
+ GError **err)
{
CR_FILE *file = NULL;
- cr_CompressionType type;
+ cr_CompressionType type = comtype;
+ GError *tmp_err = NULL;
+ assert(filename);
+ assert(mode == CR_CW_MODE_READ || mode == CR_CW_MODE_WRITE);
assert(mode < CR_CW_MODE_SENTINEL);
assert(comtype < CR_CW_COMPRESSION_SENTINEL);
-
- if (!filename || (mode != CR_CW_MODE_READ && mode != CR_CW_MODE_WRITE)) {
- g_debug("%s: Filename is NULL or bad mode value", __func__);
- return NULL;
- }
-
-
- // Compression type detection
+ assert(!err || *err == NULL);
if (mode == CR_CW_MODE_WRITE) {
if (comtype == CR_CW_AUTO_DETECT_COMPRESSION) {
g_debug("%s: CR_CW_AUTO_DETECT_COMPRESSION cannot be used if "
"mode is CR_CW_MODE_WRITE", __func__);
- return NULL;
+ assert(0);
}
if (comtype == CR_CW_UNKNOWN_COMPRESSION) {
g_debug("%s: CR_CW_UNKNOWN_COMPRESSION cannot be used if mode"
" is CR_CW_MODE_WRITE", __func__);
- return NULL;
+ assert(0);
}
}
- if (comtype != CR_CW_AUTO_DETECT_COMPRESSION) {
- type = comtype;
- } else {
- type = cr_detect_compression(filename);
+ if (comtype == CR_CW_AUTO_DETECT_COMPRESSION)
+ type = cr_detect_compression(filename, &tmp_err);
+
+ if (tmp_err) {
+ // Error while detection
+ g_propagate_error(err, tmp_err);
+ return NULL;
}
if (type == CR_CW_UNKNOWN_COMPRESSION) {
+ // Detection without error but compression type is unknown
g_debug("%s: Cannot detect compression type", __func__);
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_UNKNOWNCOMPRESSION,
+ "Cannot detect compression type");
return NULL;
}
case (CR_CW_NO_COMPRESSION): // ----------------------------------------
file->type = CR_CW_NO_COMPRESSION;
- if (mode == CR_CW_MODE_WRITE) {
+ if (mode == CR_CW_MODE_WRITE)
file->FILE = (void *) fopen(filename, "w");
- } else {
+ else
file->FILE = (void *) fopen(filename, "r");
- }
+
+ if (!file->FILE)
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_IO,
+ "fopen(): %s", strerror(errno));
+
break;
case (CR_CW_GZ_COMPRESSION): // ----------------------------------------
file->FILE = (void *) gzopen(filename, "rb");
}
+ if (!file->FILE)
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_IO,
+ "fopen(): %s", strerror(errno));
+
if (gzbuffer((gzFile) file->FILE, GZ_BUFFER_SIZE) == -1) {
g_debug("%s: gzbuffer() call failed", __func__);
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_GZ,
+ "gzbuffer() call failed");
}
+
break;
case (CR_CW_BZ2_COMPRESSION): // ---------------------------------------
file->type = CR_CW_BZ2_COMPRESSION;
FILE *f;
+ int bzerror = BZ_OK;
+
if (mode == CR_CW_MODE_WRITE) {
f = fopen(filename, "wb");
if (f) {
- file->FILE = (void *) BZ2_bzWriteOpen(NULL, f,
+ file->FILE = (void *) BZ2_bzWriteOpen(&bzerror,
+ f,
BZ2_BLOCKSIZE100K,
BZ2_VERBOSITY,
BZ2_WORK_FACTOR);
} else {
f = fopen(filename, "rb");
if (f) {
- file->FILE = (void *) BZ2_bzReadOpen(NULL, f,
+ file->FILE = (void *) BZ2_bzReadOpen(&bzerror,
+ f,
BZ2_VERBOSITY,
BZ2_USE_LESS_MEMORY,
NULL, 0);
}
}
+
+ if (!f) {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_IO,
+ "fopen(): %s", strerror(errno));
+ } else if (bzerror != BZ_OK) {
+ const char *err_msg;
+
+ switch (bzerror) {
+ case BZ_CONFIG_ERROR:
+ err_msg = "library has been mis-compiled";
+ break;
+ case BZ_PARAM_ERROR:
+ err_msg = "bad function params";
+ break;
+ case BZ_IO_ERROR:
+ err_msg = "ferror(f) is nonzero";
+ break;
+ case BZ_MEM_ERROR:
+ err_msg = "insufficient memory is available";
+ break;
+ default:
+ err_msg = "other error";
+ }
+
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BZ2,
+ "Bz2 error: %s", err_msg);
+ }
+
break;
case (CR_CW_XZ_COMPRESSION): // ----------------------------------------
XZ_DECODER_FLAGS);
if (ret != LZMA_OK) {
+ const char *err_msg;
+
switch (ret) {
case LZMA_MEM_ERROR:
- g_debug("%s: XZ: Cannot allocate memory",
- __func__);
+ err_msg = "Cannot allocate memory";
break;
case LZMA_OPTIONS_ERROR:
- g_debug("%s: XZ: Unsupported flags (options)",
- __func__);
+ err_msg = "Unsupported flags (options)";
break;
case LZMA_PROG_ERROR:
- g_debug("%s: XZ: One or more of the parameters "
- "have values that will never be valid.",
- __func__);
+ err_msg = "One or more of the parameters "
+ "have values that will never be valid.";
break;
default:
- g_debug("%s: XZ: Unknown error", __func__);
+ err_msg = "Unknown error";
}
+
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_XZ,
+ "XZ error: %s", err_msg);
g_free((void *) xz_file);
break;
}
xz_file->file = fopen(filename, "rb");
if (!(xz_file->file)) {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_XZ,
+ "fopen(): %s", strerror(errno));
+
lzma_end(&(xz_file->stream));
g_free((void *) xz_file);
}
break;
}
-
if (!file->FILE) {
// File is not open -> cleanup
g_free(file);
- file = NULL;
+ if (err && *err == NULL)
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_XZ,
+ "Unknown error while opening: %s", filename);
+ return NULL;
}
+ assert(!err || (!file && *err != NULL) || (file && *err == NULL));
+
return file;
}
int
-cr_close(CR_FILE *cr_file)
+cr_close(CR_FILE *cr_file, GError **err)
{
- if (!cr_file) {
- return CR_CW_ERR;
- }
-
-
int ret;
int cw_ret = CR_CW_ERR;
+ assert(!err || *err == NULL);
+
+ if (!cr_file)
+ return CRE_OK;
+
switch (cr_file->type) {
case (CR_CW_NO_COMPRESSION): // ----------------------------------------
ret = fclose((FILE *) cr_file->FILE);
- if (ret == 0) {
+ if (ret == 0)
cw_ret = CR_CW_OK;
- }
+ else
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_IO,
+ "fclose(): %s", strerror(errno));
+
break;
case (CR_CW_GZ_COMPRESSION): // ----------------------------------------
ret = gzclose((gzFile) cr_file->FILE);
if (ret == Z_OK) {
cw_ret = CR_CW_OK;
+ } else {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_GZ,
+ "gzclose(): %s", cr_gz_strerror((gzFile) cr_file->FILE));
}
break;
case (CR_CW_BZ2_COMPRESSION): // ---------------------------------------
- if (cr_file->mode == CR_CW_MODE_READ) {
+ if (cr_file->mode == CR_CW_MODE_READ)
BZ2_bzReadClose(&ret, (BZFILE *) cr_file->FILE);
- } else {
+ else
BZ2_bzWriteClose(&ret, (BZFILE *) cr_file->FILE,
BZ2_SKIP_FFLUSH, NULL, NULL);
- }
if (ret == BZ_OK) {
cw_ret = CR_CW_OK;
+ } else {
+ const char *err_msg;
+
+ switch (ret) {
+ case BZ_SEQUENCE_ERROR:
+ // This really shoud not happen
+ err_msg = "file was opened with BZ2_bzReadOpen";
+ break;
+ case BZ_IO_ERROR:
+ err_msg = "error writing the compressed file";
+ break;
+ default:
+ err_msg = "other error";
+ }
+
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BZ2,
+ "Bz2 error: %s", err_msg);
}
break;
if(ret != LZMA_OK && ret != LZMA_STREAM_END) {
// Error while coding
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_XZ,
+ "XZ: lzma_code() error");
break;
}
size_t out_len = XZ_BUFFER_SIZE - stream->avail_out;
if(fwrite(xz_file->buffer, 1, out_len, xz_file->file) != out_len) {
// Error while writing
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_XZ,
+ "XZ: fwrite() error: %s", strerror(errno));
break;
}
}
default: // ------------------------------------------------------------
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BADARG,
+ "Bad compressed file type");
break;
}
g_free(cr_file);
+ assert(!err || (cw_ret == CR_CW_ERR && *err != NULL)
+ || (cw_ret != CR_CW_ERR && *err == NULL));
+
return cw_ret;
}
int
-cr_read(CR_FILE *cr_file, void *buffer, unsigned int len)
+cr_read(CR_FILE *cr_file, void *buffer, unsigned int len, GError **err)
{
int bzerror;
int ret;
assert(cr_file);
assert(buffer);
+ assert(!err || *err == NULL);
- if (cr_file->mode != CR_CW_MODE_READ)
+ if (cr_file->mode != CR_CW_MODE_READ) {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BADARG,
+ "File is not opened in read mode");
return CR_CW_ERR;
+ }
switch (cr_file->type) {
ret = fread(buffer, 1, len, (FILE *) cr_file->FILE);
if ((ret != (int) len) && !feof((FILE *) cr_file->FILE)) {
ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_IO,
+ "fread(): %s", strerror(errno));
}
break;
case (CR_CW_GZ_COMPRESSION): // ----------------------------------------
- return gzread((gzFile) cr_file->FILE, buffer, len);
+ ret = gzread((gzFile) cr_file->FILE, buffer, len);
+ if (ret == -1) {
+ ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_GZ,
+ "fread(): %s", cr_gz_strerror((gzFile) cr_file->FILE));
+ }
break;
case (CR_CW_BZ2_COMPRESSION): // ---------------------------------------
if (!ret && bzerror == BZ_SEQUENCE_ERROR)
// Next read after BZ_STREAM_END (EOF)
return 0;
+
if (bzerror != BZ_OK && bzerror != BZ_STREAM_END) {
- return CR_CW_ERR;
+ const char *err_msg;
+ ret = CR_CW_ERR;
+
+ switch (bzerror) {
+ case BZ_PARAM_ERROR:
+ // This shoud not happend
+ err_msg = "bad function params!";
+ break;
+ case BZ_SEQUENCE_ERROR:
+ // This shoud not happend
+ err_msg = "file was opened with BZ2_bzWriteOpen";
+ break;
+ case BZ_IO_ERROR:
+ err_msg = "error while reading from the compressed file";
+ break;
+ case BZ_UNEXPECTED_EOF:
+ err_msg = "the compressed file ended before "
+ "the logical end-of-stream was detected";
+ break;
+ case BZ_DATA_ERROR:
+ err_msg = "data integrity error was detected in "
+ "the compressed stream";
+ break;
+ case BZ_DATA_ERROR_MAGIC:
+ err_msg = "the stream does not begin with "
+ "the requisite header bytes (ie, is not "
+ "a bzip2 data file).";
+ break;
+ case BZ_MEM_ERROR:
+ err_msg = "insufficient memory was available";
+ break;
+ default:
+ err_msg = "other error";
+ }
+
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BZ2,
+ "Bz2 error: %s", err_msg);
}
break;
if (stream->avail_in == 0) {
if ((lret = fread(xz_file->buffer, 1, XZ_BUFFER_SIZE, xz_file->file)) < 0) {
g_debug("%s: XZ: Error while fread", __func__);
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_XZ,
+ "XZ: fread(): %s", strerror(errno));
return CR_CW_ERR; // Error while reading input file
} else if (lret == 0) {
g_debug("%s: EOF", __func__);
lret = lzma_code(stream, LZMA_RUN);
if (lret != LZMA_OK && lret != LZMA_STREAM_END) {
g_debug("%s: XZ: Error while decoding (%d)", __func__, lret);
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_XZ,
+ "XZ: Error while deconding(%d)", lret);
return CR_CW_ERR; // Error while decoding
}
- if (lret == LZMA_STREAM_END) {
+
+ if (lret == LZMA_STREAM_END)
break;
- }
}
ret = len - stream->avail_out;
default: // ------------------------------------------------------------
ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BADARG,
+ "Bad compressed file type");
break;
}
+ assert(!err || (ret == CR_CW_ERR && *err != NULL)
+ || (ret != CR_CW_ERR && *err == NULL));
+
return ret;
}
int
-cr_write(CR_FILE *cr_file, const void *buffer, unsigned int len)
+cr_write(CR_FILE *cr_file, const void *buffer, unsigned int len, GError **err)
{
int bzerror;
int ret = CR_CW_ERR;
assert(cr_file);
assert(buffer);
+ assert(!err || *err == NULL);
- if (cr_file->mode != CR_CW_MODE_WRITE)
+ if (cr_file->mode != CR_CW_MODE_WRITE) {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BADARG,
+ "File is not opened in read mode");
return ret;
+ }
switch (cr_file->type) {
case (CR_CW_NO_COMPRESSION): // ----------------------------------------
if ((ret = (int) fwrite(buffer, 1, len, (FILE *) cr_file->FILE)) != (int) len) {
ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_IO,
+ "fwrite(): %s", strerror(errno));
}
break;
ret = 0;
break;
}
+
if ((ret = gzwrite((gzFile) cr_file->FILE, buffer, len)) == 0) {
ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_GZ,
+ "gzwrite(): %s", cr_gz_strerror((gzFile) cr_file->FILE));
}
break;
if (bzerror == BZ_OK) {
ret = len;
} else {
+ const char *err_msg;
ret = CR_CW_ERR;
+
+ switch (bzerror) {
+ case BZ_PARAM_ERROR:
+ // This shoud not happend
+ err_msg = "bad function params!";
+ break;
+ case BZ_SEQUENCE_ERROR:
+ // This shoud not happend
+ err_msg = "file was opened with BZ2_bzReadOpen";
+ break;
+ case BZ_IO_ERROR:
+ err_msg = "error while reading from the compressed file";
+ break;
+ default:
+ err_msg = "other error";
+ }
+
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BZ2,
+ "Bz2 error: %s", err_msg);
}
break;
lret = lzma_code(stream, LZMA_RUN);
if (lret != LZMA_OK) {
ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_XZ,
+ "XZ: lzma_code() error");
break; // Error while coding
}
size_t out_len = XZ_BUFFER_SIZE - stream->avail_out;
if ((fwrite(xz_file->buffer, 1, out_len, xz_file->file)) != out_len) {
ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_XZ,
+ "XZ: fwrite(): %s", strerror(errno));
break; // Error while writing
}
}
}
default: // ------------------------------------------------------------
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BADARG,
+ "Bad compressed file type");
break;
}
+ assert(!err || (ret == CR_CW_ERR && *err != NULL)
+ || (ret != CR_CW_ERR && *err == NULL));
+
return ret;
}
int
-cr_puts(CR_FILE *cr_file, const char *str)
+cr_puts(CR_FILE *cr_file, const char *str, GError **err)
{
size_t len;
- int bzerror;
int ret = CR_CW_ERR;
assert(cr_file);
+ assert(!err || *err == NULL);
+
+ if (!str)
+ return CR_CW_OK;
- if (!str || cr_file->mode != CR_CW_MODE_WRITE)
+ if (cr_file->mode != CR_CW_MODE_WRITE) {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BADARG,
+ "File is not opened in write mode");
return CR_CW_ERR;
+ }
switch (cr_file->type) {
case (CR_CW_NO_COMPRESSION): // ----------------------------------------
if (fputs(str, (FILE *) cr_file->FILE) != EOF) {
ret = CR_CW_OK;
+ } else {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_IO,
+ "fputs(): %s", strerror(errno));
}
break;
case (CR_CW_GZ_COMPRESSION): // ----------------------------------------
if (gzputs((gzFile) cr_file->FILE, str) != -1) {
ret = CR_CW_OK;
- }
- break;
-
- case (CR_CW_BZ2_COMPRESSION): // ---------------------------------------
- len = strlen(str);
- BZ2_bzWrite(&bzerror, (BZFILE *) cr_file->FILE, (void *) str, len);
- if (bzerror == BZ_OK) {
- ret = CR_CW_OK;
} else {
- ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_GZ,
+ "gzputs(): %s", cr_gz_strerror((gzFile) cr_file->FILE));
}
break;
+ case (CR_CW_BZ2_COMPRESSION): // ---------------------------------------
case (CR_CW_XZ_COMPRESSION): // ----------------------------------------
len = strlen(str);
- ret = cr_write(cr_file, str, len);
- if (ret == (int) len) {
+ ret = cr_write(cr_file, str, len, err);
+ if (ret == (int) len)
ret = CR_CW_OK;
- } else {
+ else
ret = CR_CW_ERR;
- }
break;
default: // ------------------------------------------------------------
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BADARG,
+ "Bad compressed file type");
break;
}
+ assert(!err || (ret == CR_CW_ERR && *err != NULL)
+ || (ret != CR_CW_ERR && *err == NULL));
+
return ret;
}
int
-cr_printf(CR_FILE *cr_file, const char *format, ...)
+cr_printf(GError **err, CR_FILE *cr_file, const char *format, ...)
{
va_list vl;
int ret;
gchar *buf = NULL;
assert(cr_file);
+ assert(!err || *err == NULL);
- if (!format || cr_file->mode != CR_CW_MODE_WRITE)
- return CR_CW_ERR;
+ if (!format)
+ return 0;
- va_start(vl, format);
+ if (cr_file->mode != CR_CW_MODE_WRITE) {
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BADARG,
+ "File is not opened in write mode");
+ return CR_CW_ERR;
+ }
// Fill format string
+ va_start(vl, format);
ret = g_vasprintf(&buf, format, vl);
-
va_end(vl);
if (ret < 0) {
g_debug("%s: vasprintf() call failed", __func__);
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_MEMORY,
+ "vasprintf() call failed");
return CR_CW_ERR;
}
case (CR_CW_NO_COMPRESSION): // ----------------------------------------
if ((ret = fwrite(buf, 1, ret, cr_file->FILE)) < 0) {
ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_IO,
+ "fwrite(): %s", strerror(errno));
}
break;
case (CR_CW_GZ_COMPRESSION): // ----------------------------------------
if (gzputs((gzFile) cr_file->FILE, buf) == -1) {
ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_GZ,
+ "gzputs(): %s", cr_gz_strerror((gzFile) cr_file->FILE));
}
break;
case (CR_CW_BZ2_COMPRESSION): // ---------------------------------------
- BZ2_bzWrite(&tmp_ret, (BZFILE *) cr_file->FILE, buf, ret);
- if (tmp_ret != BZ_OK) {
- ret = CR_CW_ERR;
- }
- break;
-
case (CR_CW_XZ_COMPRESSION): // ----------------------------------------
- tmp_ret = cr_write(cr_file, buf, ret);
+ tmp_ret = cr_write(cr_file, buf, ret, err);
if (tmp_ret != (int) ret) {
ret = CR_CW_ERR;
}
default: // ------------------------------------------------------------
ret = CR_CW_ERR;
+ g_set_error(err, CR_COMPRESSION_WRAPPER_ERROR, CRE_BADARG,
+ "Bad compressed file type");
break;
}
g_free(buf);
+ assert(!err || (ret == CR_CW_ERR && *err != NULL)
+ || (ret != CR_CW_ERR && *err == NULL));
+
return ret;
}
/** Detect a compression type of the specified file.
* @param filename filename
+ * @param err GError **
* @return detected type of compression
*/
-cr_CompressionType cr_detect_compression(const char* filename);
+cr_CompressionType cr_detect_compression(const char* filename, GError **err);
/** Open/Create the specified file.
* @param filename filename
* @param mode open mode
* @param comtype type of compression
+ * @param err GError **
* @return pointer to a CR_FILE or NULL
*/
CR_FILE *cr_open(const char *filename,
cr_OpenMode mode,
- cr_CompressionType comtype);
+ cr_CompressionType comtype,
+ GError **err);
/** Reads an array of len bytes from the CR_FILE.
* @param cr_file CR_FILE pointer
* @param buffer target buffer
* @param len number of bytes to read
+ * @param err GError **
* @return number of readed bytes or CR_CW_ERR
*/
-int cr_read(CR_FILE *cr_file, void *buffer, unsigned int len);
+int cr_read(CR_FILE *cr_file, void *buffer, unsigned int len, GError **err);
/** Writes the array of len bytes from buffer to the cr_file.
* @param cr_file CR_FILE pointer
* @param buffer source buffer
* @param len number of bytes to read
+ * @param err GError **
* @return number of uncompressed bytes readed (0 = EOF)
* or CR_CW_ERR
*/
-int cr_write(CR_FILE *cr_file, const void *buffer, unsigned int len);
+int cr_write(CR_FILE *cr_file,
+ const void *buffer,
+ unsigned int len,
+ GError **err);
/** Writes the string pointed by str into the cr_file.
* @param cr_file CR_FILE pointer
* @param str null terminated ('\0') string
+ * @param err GError **
* @return number of uncompressed bytes writed or CR_CW_ERR
*/
-int cr_puts(CR_FILE *cr_file, const char *str);
+int cr_puts(CR_FILE *cr_file, const char *str, GError **err);
/** Writes a formatted string into the cr_file.
+ * @param err GError **
* @param cr_file CR_FILE pointer
* @param format format string
* @param ... list of additional arguments as specified in format
* @return CR_CW_OK or CR_CW_ERR
*/
-int cr_printf(CR_FILE *cr_file, const char *format, ...);
+int cr_printf(GError **err, CR_FILE *cr_file, const char *format, ...);
/** Closes the CR_FILE.
* @param cr_file CR_FILE pointer
+ * @param err GError **
* @return CR_CW_OK or CR_CW_ERR
*/
-int cr_close(CR_FILE *cr_file);
+int cr_close(CR_FILE *cr_file, GError **err);
/** @} */
}
GQuark
+cr_compression_wrapper_error_quark(void)
+{
+ return g_quark_from_static_string("cr_compression_wrapper_error");
+}
+
+GQuark
cr_db_error_quark(void)
{
return g_quark_from_static_string("cr_db_error");
(16) Bad filelists.xml file */
CRE_BADXMLOTHER, /*!<
(17) Bad filelists.xml file */
+ CRE_BADXMLREPOMD, /*!<
+ (18) Bad repomd.xml file */
+ CRE_MAGIC, /*!<
+ (19) Magic Number Recognition Library (libmagic) error */
+ CRE_GZ, /*!<
+ (20) Gzip library related error */
+ CRE_BZ2, /*!<
+ (21) Bzip2 library related error */
+ CRE_XZ, /*!<
+ (22) Xz (lzma) library related error */
} cr_Error;
/** Converts cr_Error return code to error string.
const char *cr_strerror(cr_Error rc);
/* Error domains */
-#define CR_CHECKSUM_ERROR cr_checksum_error_quark()
-#define CR_DB_ERROR cr_db_error_quark()
-#define CR_LOAD_METADATA_ERROR cr_load_metadata_error_quark()
-#define CR_LOCATE_METADATA_ERROR cr_locate_metadata_error_quark()
-#define CR_PARSEPKG_ERROR cr_parsepkg_error_quark()
-#define CR_REPOMD_ERROR cr_repomd_error_quark()
-#define CR_REPOMD_RECORD_ERROR cr_repomd_record_error_quark()
-#define CR_XML_DUMP_FILELISTS_ERROR cr_xml_dump_filelists_error_quark()
-#define CR_XML_DUMP_OTHER_ERROR cr_xml_dump_other_error_quark()
-#define CR_XML_DUMP_PRIMARY_ERROR cr_xml_dump_primary_error_quark()
-#define CR_XML_FILE_ERROR cr_xml_file_error_quark()
-#define CR_XML_PARSER_FIL_ERROR cr_xml_parser_fil_error_quark()
-#define CR_XML_PARSER_OTH_ERROR cr_xml_parser_oth_error_quark()
-#define CR_XML_PARSER_PRI_ERROR cr_xml_parser_pri_error_quark()
+#define CR_CHECKSUM_ERROR cr_checksum_error_quark()
+#define CR_COMPRESSION_WRAPPER_ERROR cr_compression_wrapper_error_quark()
+#define CR_DB_ERROR cr_db_error_quark()
+#define CR_LOAD_METADATA_ERROR cr_load_metadata_error_quark()
+#define CR_LOCATE_METADATA_ERROR cr_locate_metadata_error_quark()
+#define CR_PARSEPKG_ERROR cr_parsepkg_error_quark()
+#define CR_REPOMD_ERROR cr_repomd_error_quark()
+#define CR_REPOMD_RECORD_ERROR cr_repomd_record_error_quark()
+#define CR_XML_DUMP_FILELISTS_ERROR cr_xml_dump_filelists_error_quark()
+#define CR_XML_DUMP_OTHER_ERROR cr_xml_dump_other_error_quark()
+#define CR_XML_DUMP_PRIMARY_ERROR cr_xml_dump_primary_error_quark()
+#define CR_XML_FILE_ERROR cr_xml_file_error_quark()
+#define CR_XML_PARSER_FIL_ERROR cr_xml_parser_fil_error_quark()
+#define CR_XML_PARSER_OTH_ERROR cr_xml_parser_oth_error_quark()
+#define CR_XML_PARSER_PRI_ERROR cr_xml_parser_pri_error_quark()
GQuark cr_checksum_error_quark(void);
+GQuark cr_compression_wrapper_error_quark(void);
GQuark cr_db_error_quark(void);
GQuark cr_load_metadata_error_quark(void);
GQuark cr_locate_metadata_error_quark(void);
CR_FILE *pri_xml_cwfile, *fil_xml_cwfile, *oth_xml_cwfile;
XML_Parser pri_p, fil_p, oth_p;
struct ParserData parser_data;
+ GError *tmp_err = NULL;
assert(!err || *err == NULL);
// Detect compression type
- compression_type = cr_detect_compression(primary_xml_path);
+ compression_type = cr_detect_compression(primary_xml_path, &tmp_err);
if (compression_type == CR_CW_UNKNOWN_COMPRESSION) {
+ ret = tmp_err->code;
g_debug("%s: Unknown compression", __func__);
- g_set_error(err, CR_LOAD_METADATA_ERROR, CRE_UNKNOWNCOMPRESSION,
- "Unknown compression of %s", primary_xml_path);
- return CRE_UNKNOWNCOMPRESSION;
+ g_propagate_prefixed_error(err, tmp_err,
+ "Compression detection of %s: ", primary_xml_path);
+ return ret;
}
// Open files
- if (!(pri_xml_cwfile = cr_open(primary_xml_path, CR_CW_MODE_READ, compression_type))) {
+ if (!(pri_xml_cwfile = cr_open(primary_xml_path, CR_CW_MODE_READ, compression_type, NULL))) {
g_debug("%s: Cannot open file: %s", __func__, primary_xml_path);
g_set_error(err, CR_LOAD_METADATA_ERROR, CRE_IO,
"Cannot open %s", primary_xml_path);
return CRE_IO;
}
- if (!(fil_xml_cwfile = cr_open(filelists_xml_path, CR_CW_MODE_READ, compression_type))) {
+ if (!(fil_xml_cwfile = cr_open(filelists_xml_path, CR_CW_MODE_READ, compression_type, NULL))) {
g_debug("%s: Cannot open file: %s", __func__, filelists_xml_path);
g_set_error(err, CR_LOAD_METADATA_ERROR, CRE_IO,
"Cannot open %s", primary_xml_path);
return CRE_IO;
}
- if (!(oth_xml_cwfile = cr_open(other_xml_path, CR_CW_MODE_READ, compression_type))) {
+ if (!(oth_xml_cwfile = cr_open(other_xml_path, CR_CW_MODE_READ, compression_type, NULL))) {
g_debug("%s: Cannot open file: %s", __func__, other_xml_path);
g_set_error(err, CR_LOAD_METADATA_ERROR, CRE_IO,
"Cannot open %s", primary_xml_path);
break;
}
- pri_len = cr_read(pri_xml_cwfile, (void *) pri_buff, CHUNK_SIZE);
+ pri_len = cr_read(pri_xml_cwfile, (void *) pri_buff, CHUNK_SIZE, NULL);
if (pri_len < 0) {
g_critical("%s: Read error", __func__);
ret = CRE_IO;
break;
}
- fil_len = cr_read(fil_xml_cwfile, (void *) fil_buff, CHUNK_SIZE);
+ fil_len = cr_read(fil_xml_cwfile, (void *) fil_buff, CHUNK_SIZE, NULL);
if (fil_len < 0) {
g_critical("%s: Read error", __func__);
ret = CRE_IO;
break;
}
- oth_len = cr_read(oth_xml_cwfile, (void *) oth_buff, CHUNK_SIZE);
+ oth_len = cr_read(oth_xml_cwfile, (void *) oth_buff, CHUNK_SIZE, NULL);
if (oth_len < 0) {
g_critical("%s: Read error", __func__);
ret = CRE_IO;
XML_ParserFree(pri_p);
XML_ParserFree(fil_p);
XML_ParserFree(oth_p);
- cr_close(pri_xml_cwfile);
- cr_close(fil_xml_cwfile);
- cr_close(oth_xml_cwfile);
+ cr_close(pri_xml_cwfile, NULL);
+ cr_close(fil_xml_cwfile, NULL);
+ cr_close(oth_xml_cwfile, NULL);
g_string_free(parser_data.current_string, TRUE);
return CR_COPY_ERR;
}
- if ((new = cr_open(dst, CR_CW_MODE_WRITE, compression)) == NULL) {
+ if ((new = cr_open(dst, CR_CW_MODE_WRITE, compression, NULL)) == NULL) {
g_debug("%s: Cannot open destination file %s", __func__, dst);
fclose(orig);
return CR_COPY_ERR;
}
while ((readed = fread(buf, 1, BUFFER_SIZE, orig)) > 0) {
- if (cr_write(new, buf, readed) != readed) {
+ if (cr_write(new, buf, readed, NULL) != readed) {
g_debug("%s: Error while copy %s -> %s", __func__, src, dst);
- cr_close(new);
+ cr_close(new, NULL);
fclose(orig);
return CR_COPY_ERR;
}
if (readed != BUFFER_SIZE && ferror(orig)) {
g_debug("%s: Error while copy %s -> %s (%s)", __func__, src,
dst, strerror(errno));
- cr_close(new);
+ cr_close(new, NULL);
fclose(orig);
return CR_COPY_ERR;
}
}
- if (dst != in_dst) {
+ if (dst != in_dst)
g_free(dst);
- }
- cr_close(new);
+ cr_close(new, NULL);
fclose(orig);
return CR_COPY_OK;
cr_ChecksumType checksum_type,
GError **err)
{
+ GError *tmp_err = NULL;
+
assert(filename);
assert(!err || *err == NULL);
// Open compressed file
- CR_FILE *cwfile;
- if (!(cwfile = cr_open(filename, CR_CW_MODE_READ, CR_CW_AUTO_DETECT_COMPRESSION))) {
- g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_IO,
- "Cannot open a file");
+ CR_FILE *cwfile = cr_open(filename,
+ CR_CW_MODE_READ,
+ CR_CW_AUTO_DETECT_COMPRESSION,
+ &tmp_err);
+ if (!cwfile) {
+ g_propagate_prefixed_error(err, tmp_err,
+ "Cannot open a file %s: ", filename);
return NULL;
}
unsigned char buffer[BUFFER_SIZE];
do {
- readed = cr_read(cwfile, (void *) buffer, BUFFER_SIZE);
+ readed = cr_read(cwfile, (void *) buffer, BUFFER_SIZE, &tmp_err);
if (readed == CR_CW_ERR) {
- g_debug("%s: Error while read compressed file: %s",
- __func__, filename);
- g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_IO,
- "Error while read compressed file");
+ g_debug("%s: Error while read compressed file %s: %s",
+ __func__, filename, tmp_err->message);
+ g_propagate_prefixed_error(err, tmp_err,
+ "Error while read compressed file %s: ",
+ filename);
break;
}
g_checksum_update (checksum, buffer, readed);
// Clean up
g_checksum_free(checksum);
- cr_close(cwfile);
+ cr_close(cwfile, NULL);
return result;
}
// Compute checksum of non compressed content and its size
if (!md->checksum_open_type || !md->checksum_open || !md->size_open) {
- if (cr_detect_compression(path) != CR_CW_UNKNOWN_COMPRESSION &&
- cr_detect_compression(path) != CR_CW_NO_COMPRESSION)
+ cr_CompressionType com_type = cr_detect_compression(path, &tmp_err);
+ if (tmp_err) {
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err,
+ "Cannot detect compression type of %s: ", path);
+ return code;
+ }
+
+ if (com_type != CR_CW_UNKNOWN_COMPRESSION &&
+ com_type != CR_CW_NO_COMPRESSION)
{
// File compressed by supported algorithm
contentStat *open_stat = NULL;
// Compress file + get size of non compressed file
- cw_plain = cr_open(path, CR_CW_MODE_READ, CR_CW_NO_COMPRESSION);
+ cw_plain = cr_open(path,
+ CR_CW_MODE_READ,
+ CR_CW_NO_COMPRESSION,
+ &tmp_err);
if (!cw_plain) {
- g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_IO,
- "Cannot open %s", path);
- return CRE_IO;
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err, "Cannot open %s: ", path);
+ return code;
}
- cw_compressed = cr_open(cpath, CR_CW_MODE_WRITE, record_compression);
+ cw_compressed = cr_open(cpath,
+ CR_CW_MODE_WRITE,
+ record_compression,
+ &tmp_err);
if (!cw_compressed) {
- g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_IO,
- "Cannot open %s", path);
- return CRE_IO;
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err, "Cannot open %s: ", cpath);
+ return code;
}
- while ((readed = cr_read(cw_plain, buf, BUFFER_SIZE)) > 0) {
- if (cr_write(cw_compressed, buf, (unsigned int) readed) == CR_CW_ERR) {
- g_debug("%s: Error while record compression", __func__);
+ while ((readed = cr_read(cw_plain, buf, BUFFER_SIZE, &tmp_err)) > 0) {
+ cr_write(cw_compressed, buf, (unsigned int) readed, &tmp_err);
+ if (tmp_err)
break;
- }
}
- cr_close(cw_compressed);
- cr_close(cw_plain);
+ cr_close(cw_plain, NULL);
- if (readed == CR_CW_ERR) {
- g_debug("%s: Error while record compression", __func__);
- g_set_error(err, CR_REPOMD_RECORD_ERROR, CRE_IO,
- "Error while compression");
- return CRE_IO;
+ if (tmp_err) {
+ int code = tmp_err->code;
+ cr_close(cw_compressed, NULL);
+ g_debug("%s: Error while repomd record compression: %s", __func__,
+ tmp_err->message);
+ g_propagate_prefixed_error(err, tmp_err,
+ "Error while compression %s -> %s:", path, cpath);
+ return code;
+ }
+
+ cr_close(cw_compressed, &tmp_err);
+ if (tmp_err) {
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err,
+ "Error while closing %s: ", path);
+ return code;
}
GError **err)
{
cr_XmlFile *f;
+ GError *tmp_err = NULL;
assert(filename);
assert(type < CR_XMLFILE_SENTINEL);
return NULL;
}
- CR_FILE *cr_f = cr_open(filename, CR_CW_MODE_WRITE, comtype);
- if (cr_f == NULL) {
- g_set_error(err, CR_XML_FILE_ERROR, CRE_IO,
- "Cannot open file");
+ CR_FILE *cr_f = cr_open(filename, CR_CW_MODE_WRITE, comtype, &tmp_err);
+ if (tmp_err) {
+ g_propagate_prefixed_error(err, tmp_err, "Cannot open %s: ", filename);
return NULL;
}
cr_xmlfile_write_xml_header(cr_XmlFile *f, GError **err)
{
const char *xml_header;
+ GError *tmp_err = NULL;
assert(f);
assert(!err || *err == NULL);
assert(0);
}
- if (cr_printf(f->f, xml_header, f->pkgs) == CR_CW_ERR) {
- g_set_error(err, CR_XML_FILE_ERROR, CRE_IO,
- "Cannot write XML header");
- return CRE_IO;
+ if (cr_printf(&tmp_err, f->f, xml_header, f->pkgs) == CR_CW_ERR) {
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err, "Cannot write XML header: ");
+ return code;
}
f->header = 1;
cr_xmlfile_write_xml_footer(cr_XmlFile *f, GError **err)
{
const char *xml_footer;
+ GError *tmp_err = NULL;
assert(f);
assert(!err || *err == NULL);
assert(0);
}
- if (cr_puts(f->f, xml_footer) < 0) {
- g_set_error(err, CR_XML_FILE_ERROR, CRE_IO,
- "Cannot write XML footer");
- return CRE_IO;
+ cr_puts(f->f, xml_footer, &tmp_err);
+ if (tmp_err) {
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err, "Cannot write XML footer: ");
+ return code;
}
f->footer = 1;
}
}
- if (cr_puts(f->f, chunk) < 0) {
- g_set_error(err, CR_XML_FILE_ERROR, CRE_IO,
- "Error while write operation");
- return CRE_IO;
+ cr_puts(f->f, chunk, &tmp_err);
+ if (tmp_err) {
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err, "Error while write: ");
+ return code;
}
return CRE_OK;
}
}
- if (cr_close(f->f) == CR_CW_ERR) {
- g_set_error(err, CR_XML_FILE_ERROR, CRE_IO,
- "Error while closing file");
- return CRE_IO;
+ cr_close(f->f, &tmp_err);
+ if (tmp_err) {
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err,
+ "Error while closing a file: ");
+ return code;
}
g_free(f);
cr_ParserData *pd;
XML_Parser parser;
char *msgs;
+ GError *tmp_err = NULL;
assert(path);
assert(newpkgcb || pkgcb);
if (!newpkgcb) // Use default newpkgcb
newpkgcb = cr_newpkgcb;
- f = cr_open(path, CR_CW_MODE_READ, CR_CW_AUTO_DETECT_COMPRESSION);
- if (!f) {
- g_set_error(err, CR_XML_PARSER_FIL_ERROR, CRE_IO, "Cannot open %s", path);
- return CRE_IO;
+ f = cr_open(path, CR_CW_MODE_READ, CR_CW_AUTO_DETECT_COMPRESSION, &tmp_err);
+ if (tmp_err) {
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err, "Cannot open %s: ", path);
+ return code;
}
parser = XML_ParserCreate(NULL);
break;
}
- len = cr_read(f, buf, XML_BUFFER_SIZE);
- if (len < 0) {
- ret = CRE_IO;
- g_critical("%s: Cannot read for parsing : %s\n",
- __func__, strerror(errno));
- g_set_error(err, CR_XML_PARSER_FIL_ERROR, CRE_IO,
- "Error while reading xml");
+ len = cr_read(f, buf, XML_BUFFER_SIZE, &tmp_err);
+ if (tmp_err) {
+ ret = tmp_err->code;
+ g_critical("%s: Error while reading xml : %s\n",
+ __func__, tmp_err->message);
+ g_propagate_prefixed_error(err, tmp_err, "Read error: ");
break;
}
msgs = cr_xml_parser_data_free(pd);
XML_ParserFree(parser);
- cr_close(f);
+ cr_close(f, &tmp_err);
+ if (tmp_err) {
+ int code = tmp_err->code;
+ g_propagate_prefixed_error(err, tmp_err, "Error while closing: ");
+ return code;
+ }
if (messages)
*messages = msgs;
test_cr_detect_compression(void)
{
cr_CompressionType ret;
+ GError *tmp_err = NULL;
// Plain
- ret = cr_detect_compression(FILE_COMPRESSED_0_PLAIN);
+ ret = cr_detect_compression(FILE_COMPRESSED_0_PLAIN, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_NO_COMPRESSION);
- ret = cr_detect_compression(FILE_COMPRESSED_1_PLAIN);
+ g_assert(!tmp_err);
+ ret = cr_detect_compression(FILE_COMPRESSED_1_PLAIN, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_NO_COMPRESSION);
+ g_assert(!tmp_err);
// Gz
- ret = cr_detect_compression(FILE_COMPRESSED_0_GZ);
+ ret = cr_detect_compression(FILE_COMPRESSED_0_GZ, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_GZ_COMPRESSION);
- ret = cr_detect_compression(FILE_COMPRESSED_1_GZ);
+ g_assert(!tmp_err);
+ ret = cr_detect_compression(FILE_COMPRESSED_1_GZ, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_GZ_COMPRESSION);
+ g_assert(!tmp_err);
// Bz2
- ret = cr_detect_compression(FILE_COMPRESSED_0_BZ2);
+ ret = cr_detect_compression(FILE_COMPRESSED_0_BZ2, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_BZ2_COMPRESSION);
- ret = cr_detect_compression(FILE_COMPRESSED_1_BZ2);
+ g_assert(!tmp_err);
+ ret = cr_detect_compression(FILE_COMPRESSED_1_BZ2, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_BZ2_COMPRESSION);
+ g_assert(!tmp_err);
// Xz
- ret = cr_detect_compression(FILE_COMPRESSED_0_XZ);
+ ret = cr_detect_compression(FILE_COMPRESSED_0_XZ, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_XZ_COMPRESSION);
- ret = cr_detect_compression(FILE_COMPRESSED_1_XZ);
+ g_assert(!tmp_err);
+ ret = cr_detect_compression(FILE_COMPRESSED_1_XZ, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_XZ_COMPRESSION);
+ g_assert(!tmp_err);
}
test_cr_detect_compression_bad_suffix(void)
{
cr_CompressionType ret;
+ GError *tmp_err = NULL;
// Plain
- ret = cr_detect_compression(FILE_COMPRESSED_0_PLAIN_BAD_SUFFIX);
+ ret = cr_detect_compression(FILE_COMPRESSED_0_PLAIN_BAD_SUFFIX, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_NO_COMPRESSION);
- ret = cr_detect_compression(FILE_COMPRESSED_1_PLAIN_BAD_SUFFIX);
+ g_assert(!tmp_err);
+ ret = cr_detect_compression(FILE_COMPRESSED_1_PLAIN_BAD_SUFFIX, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_NO_COMPRESSION);
+ g_assert(!tmp_err);
// Gz
- ret = cr_detect_compression(FILE_COMPRESSED_0_GZ_BAD_SUFFIX);
+ ret = cr_detect_compression(FILE_COMPRESSED_0_GZ_BAD_SUFFIX, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_GZ_COMPRESSION);
- ret = cr_detect_compression(FILE_COMPRESSED_1_GZ_BAD_SUFFIX);
+ g_assert(!tmp_err);
+ ret = cr_detect_compression(FILE_COMPRESSED_1_GZ_BAD_SUFFIX, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_GZ_COMPRESSION);
+ g_assert(!tmp_err);
// Bz2
- ret = cr_detect_compression(FILE_COMPRESSED_0_BZ2_BAD_SUFFIX);
+ ret = cr_detect_compression(FILE_COMPRESSED_0_BZ2_BAD_SUFFIX, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_BZ2_COMPRESSION);
- ret = cr_detect_compression(FILE_COMPRESSED_1_BZ2_BAD_SUFFIX);
+ g_assert(!tmp_err);
+ ret = cr_detect_compression(FILE_COMPRESSED_1_BZ2_BAD_SUFFIX, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_BZ2_COMPRESSION);
+ g_assert(!tmp_err);
// Xz
- ret = cr_detect_compression(FILE_COMPRESSED_0_XZ_BAD_SUFFIX);
+ ret = cr_detect_compression(FILE_COMPRESSED_0_XZ_BAD_SUFFIX, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_XZ_COMPRESSION);
- ret = cr_detect_compression(FILE_COMPRESSED_1_XZ_BAD_SUFFIX);
+ g_assert(!tmp_err);
+ ret = cr_detect_compression(FILE_COMPRESSED_1_XZ_BAD_SUFFIX, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_XZ_COMPRESSION);
+ g_assert(!tmp_err);
}
void
-test_helper_cw_input(const char *filename, cr_CompressionType ctype, const char *content, int len)
+test_helper_cw_input(const char *filename,
+ cr_CompressionType ctype,
+ const char *content,
+ int len)
{
int ret;
CR_FILE *file;
char buffer[COMPRESSED_BUFFER_LEN+1];
+ GError *tmp_err = NULL;
- file = cr_open(filename, CR_CW_MODE_READ, ctype);
- g_assert(file != NULL);
- ret = cr_read(file, buffer, COMPRESSED_BUFFER_LEN);
+ file = cr_open(filename, CR_CW_MODE_READ, ctype, &tmp_err);
+ g_assert(file);
+ g_assert(!tmp_err);
+
+ ret = cr_read(file, buffer, COMPRESSED_BUFFER_LEN, &tmp_err);
g_assert_cmpint(ret, ==, len);
+ g_assert(!tmp_err);
+
buffer[ret] = '\0';
g_assert_cmpstr(buffer, ==, content);
- ret = cr_close(file);
+ ret = cr_close(file, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_OK);
+ g_assert(!tmp_err);
}
{
// Plain
- test_helper_cw_input(FILE_COMPRESSED_0_PLAIN, CR_CW_AUTO_DETECT_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_input(FILE_COMPRESSED_1_PLAIN, CR_CW_AUTO_DETECT_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_input(FILE_COMPRESSED_0_PLAIN, CR_CW_AUTO_DETECT_COMPRESSION,
+ FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_input(FILE_COMPRESSED_1_PLAIN, CR_CW_AUTO_DETECT_COMPRESSION,
+ FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
// Gz
- test_helper_cw_input(FILE_COMPRESSED_0_GZ, CR_CW_AUTO_DETECT_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_input(FILE_COMPRESSED_1_GZ, CR_CW_AUTO_DETECT_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_input(FILE_COMPRESSED_0_GZ, CR_CW_AUTO_DETECT_COMPRESSION,
+ FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_input(FILE_COMPRESSED_1_GZ, CR_CW_AUTO_DETECT_COMPRESSION,
+ FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
// Bzip2
- test_helper_cw_input(FILE_COMPRESSED_0_BZ2, CR_CW_AUTO_DETECT_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_input(FILE_COMPRESSED_1_BZ2, CR_CW_AUTO_DETECT_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_input(FILE_COMPRESSED_0_BZ2, CR_CW_AUTO_DETECT_COMPRESSION,
+ FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_input(FILE_COMPRESSED_1_BZ2, CR_CW_AUTO_DETECT_COMPRESSION,
+ FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
// Xz
- test_helper_cw_input(FILE_COMPRESSED_0_XZ, CR_CW_AUTO_DETECT_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_input(FILE_COMPRESSED_1_XZ, CR_CW_AUTO_DETECT_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_input(FILE_COMPRESSED_0_XZ, CR_CW_AUTO_DETECT_COMPRESSION,
+ FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_input(FILE_COMPRESSED_1_XZ, CR_CW_AUTO_DETECT_COMPRESSION,
+ FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
}
#define OUTPUT_TYPE_PRINTF 2
void
-test_helper_cw_output(int type, const char *filename, cr_CompressionType ctype, const char *content, int len)
+test_helper_cw_output(int type,
+ const char *filename,
+ cr_CompressionType ctype,
+ const char *content,
+ int len)
{
int ret;
CR_FILE *file;
-
- file = cr_open(filename, CR_CW_MODE_WRITE, ctype);
+ GError *tmp_err = NULL;
+ file = cr_open(filename, CR_CW_MODE_WRITE, ctype, &tmp_err);
g_assert(file);
+ g_assert(!tmp_err);
switch(type) {
case OUTPUT_TYPE_WRITE:
- ret = cr_write(file, content, len);
+ ret = cr_write(file, content, len, &tmp_err);
g_assert_cmpint(ret, ==, len);
+ g_assert(!tmp_err);
break;
case OUTPUT_TYPE_PUTS:
- ret = cr_puts(file, content);
+ ret = cr_puts(file, content, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_OK);
+ g_assert(!tmp_err);
break;
case OUTPUT_TYPE_PRINTF:
- ret = cr_printf(file, "%s", content); // XXX
+ ret = cr_printf(&tmp_err, file, "%s", content);
g_assert_cmpint(ret, ==, len);
+ g_assert(!tmp_err);
break;
default:
break;
}
- ret = cr_close(file);
+ ret = cr_close(file, &tmp_err);
g_assert_cmpint(ret, ==, CR_CW_OK);
+ g_assert(!tmp_err);
// Read and compare
{
CR_UNUSED(test_data);
- CR_FILE *file;
-
- file = cr_open(outputtest->tmp_filename, CR_CW_MODE_WRITE, CR_CW_AUTO_DETECT_COMPRESSION);
- g_assert(!file);
-
- file = cr_open(outputtest->tmp_filename, CR_CW_MODE_WRITE, CR_CW_UNKNOWN_COMPRESSION);
- g_assert(!file);
-
// Plain
printf("Testing - plain\nwrite()\n");
- test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename, CR_CW_NO_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename, CR_CW_NO_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename,
+ CR_CW_NO_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename,
+ CR_CW_NO_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
printf("puts()\n");
- test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename, CR_CW_NO_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename, CR_CW_NO_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename,
+ CR_CW_NO_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename,
+ CR_CW_NO_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
printf("printf()\n");
- test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename, CR_CW_NO_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename, CR_CW_NO_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename,
+ CR_CW_NO_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename,
+ CR_CW_NO_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
// Gz
printf("Testing - gz\nwrite()\n");
- test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename, CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename, CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename,
+ CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename,
+ CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
printf("puts()\n");
- test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename, CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename, CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename,
+ CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename,
+ CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
printf("printf()\n");
- test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename, CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename, CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename,
+ CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename,
+ CR_CW_GZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
// Bz2
printf("Testing - bz2\nwrite()\n");
- test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename, CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename, CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename,
+ CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename,
+ CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
printf("puts()\n");
- test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename, CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename, CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename,
+ CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename,
+ CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
printf("printf()\n");
- test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename, CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename, CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename,
+ CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename,
+ CR_CW_BZ2_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
// Xz
printf("Testing - xz\nwrite()\n");
- test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename, CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename, CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename,
+ CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_WRITE, outputtest->tmp_filename,
+ CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
printf("puts()\n");
- test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename, CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename, CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename,
+ CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PUTS, outputtest->tmp_filename,
+ CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
printf("printf()\n");
- test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename, CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT, FILE_COMPRESSED_0_CONTENT_LEN);
- test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename, CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT, FILE_COMPRESSED_1_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename,
+ CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_0_CONTENT,
+ FILE_COMPRESSED_0_CONTENT_LEN);
+ test_helper_cw_output(OUTPUT_TYPE_PRINTF, outputtest->tmp_filename,
+ CR_CW_XZ_COMPRESSION, FILE_COMPRESSED_1_CONTENT,
+ FILE_COMPRESSED_1_CONTENT_LEN);
}
{
g_test_init(&argc, &argv, NULL);
- g_test_add_func("/compression_wrapper/test_cr_compression_suffix", test_cr_compression_suffix);
- g_test_add_func("/compression_wrapper/test_cr_detect_compression", test_cr_detect_compression);
- g_test_add_func("/compression_wrapper/test_cr_detect_compression_bad_suffix", test_cr_detect_compression_bad_suffix);
- g_test_add_func("/compression_wrapper/test_cr_read_with_autodetection", test_cr_read_with_autodetection);
- g_test_add("/compression_wrapper/outputtest_cw_output", Outputtest, NULL, outputtest_setup, outputtest_cw_output, outputtest_teardown);
+ g_test_add_func("/compression_wrapper/test_cr_compression_suffix",
+ test_cr_compression_suffix);
+ g_test_add_func("/compression_wrapper/test_cr_detect_compression",
+ test_cr_detect_compression);
+ g_test_add_func("/compression_wrapper/test_cr_detect_compression_bad_suffix",
+ test_cr_detect_compression_bad_suffix);
+ g_test_add_func("/compression_wrapper/test_cr_read_with_autodetection",
+ test_cr_read_with_autodetection);
+ g_test_add("/compression_wrapper/outputtest_cw_output", Outputtest, NULL,
+ outputtest_setup, outputtest_cw_output, outputtest_teardown);
return g_test_run();
}
g_assert(err == NULL);
cr_xmlfile_close(f, &err);
- CR_FILE *crf = cr_open(path, CR_CW_MODE_READ, CR_CW_AUTO_DETECT_COMPRESSION);
+ CR_FILE *crf = cr_open(path,
+ CR_CW_MODE_READ,
+ CR_CW_AUTO_DETECT_COMPRESSION,
+ NULL);
g_assert(crf);
- ret = cr_read(crf, &contents, 2047);
+ ret = cr_read(crf, &contents, 2047, NULL);
g_assert(ret != CR_CW_ERR);
contents[ret] = '\0';
- cr_close(crf);
+ cr_close(crf, NULL);
g_assert_cmpstr(contents, ==, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<metadata xmlns=\"http://linux.duke.edu/metadata/common\" "
"xmlns:rpm=\"http://linux.duke.edu/metadata/rpm\" "
}
-
int
main(int argc, char *argv[])
{
GError **err)
{
CR_UNUSED(pkgId);
+ CR_UNUSED(name);
CR_UNUSED(arch);
CR_UNUSED(cbdata);