#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <zzip/__debug.h>
#include "unzzipcat-zip.h"
#ifdef ZZIP_HAVE_FNMATCH_H
#define O_BINARY 0
#endif
-#ifdef DEBUG
-#define debug1(msg) do { fprintf(stderr, "%s : " msg "\n", __func__); } while(0)
-#define debug2(msg, arg1) do { fprintf(stderr, "%s : " msg "\n", __func__, arg1); } while(0)
-#define debug3(msg, arg1, arg2) do { fprintf(stderr, "%s : " msg "\n", __func__, arg1, arg2); } while(0)
-#else
-#define debug1(msg)
-#define debug2(msg, arg1)
-#define debug3(msg, arg1, arg2)
-#endif
-
static void unzzip_big_entry_fprint(ZZIP_ENTRY* entry, FILE* out)
{
ZZIP_ENTRY_FILE* file = zzip_entry_fopen (entry, 0);
char buffer[1024]; int len;
while ((len = zzip_entry_fread (buffer, 1024, 1, file)))
{
- debug2("entry read %i", len);
+ DBG2("entry read %i", len);
fwrite (buffer, len, 1, out);
}
- debug2("entry done %s", strerror(errno));
+ DBG2("entry done %s", strerror(errno));
zzip_entry_fclose (file);
} else
{
- debug2("could not open entry: %s", strerror(errno));
+ DBG2("could not open entry: %s", strerror(errno));
}
}
for (; entry ; entry = zzip_entry_findnext(entry))
{
char* name = zzip_entry_strdup_name (entry);
- debug3(".. check '%s' to zip '%s'", argv[argn], name);
+ DBG3(".. check '%s' to zip '%s'", argv[argn], name);
if (! fnmatch (argv[argn], name,
FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
{
#define O_BINARY 0
#endif
-#ifdef DEBUG
-#define debug1(msg) do { fprintf(stderr, "%s : " msg "\n", __func__); } while(0)
-#define debug2(msg, arg1) do { fprintf(stderr, "%s : " msg "\n", __func__, arg1); } while(0)
-#define debug3(msg, arg1, arg2) do { fprintf(stderr, "%s : " msg "\n", __func__, arg1, arg2); } while(0)
-#else
-#define debug1(msg)
-#define debug2(msg, arg1)
-#define debug3(msg, arg1, arg2)
-#endif
-
static const char* comprlevel[] = {
"stored", "shrunk", "redu:1", "redu:2", "redu:3", "redu:4",
"impl:N", "toknze", "defl:N", "defl:B", "impl:B" };
#include <zzip/mmapped.h>
#include <zzip/format.h>
#include <zzip/fetch.h>
+#include <zzip/__debug.h>
#include <zzip/__mmap.h>
#include <zzip/__fnmatch.h>
#define ____ }
#endif
-#ifdef DEBUG
-#define debug1(msg) do { fprintf(stderr, "%s : " msg "\n", __func__); } while(0)
-#define debug2(msg, arg1) do { fprintf(stderr, "%s : " msg "\n", __func__, arg1); } while(0)
-#define debug3(msg, arg1, arg2) do { fprintf(stderr, "%s : " msg "\n", __func__, arg1, arg2); } while(0)
-#define debug4(msg, arg1, arg2, arg3) do { fprintf(stderr, "%s : " msg "\n", __func__, arg1, arg2, arg3); } while(0)
-#else
-#define debug1(msg)
-#define debug2(msg, arg1)
-#define debug3(msg, arg1, arg2)
-#define debug4(msg, arg1, arg2, arg3)
-#endif
-
/** => zzip_disk_mmap
* This function does primary initialization of a disk-buffer struct.
*
struct zzip_disk_entry *
zzip_disk_findfirst(ZZIP_DISK * disk)
{
- debug1("findfirst");
+ DBG1("findfirst");
if (! disk)
{
- debug1("non arg");
+ DBG1("non arg");
errno = EINVAL;
return 0;
}
if (disk->buffer > disk->endbuf - sizeof(struct zzip_disk_trailer))
{
- debug1("not enough data for a disk trailer");
+ DBG1("not enough data for a disk trailer");
errno = EBADMSG;
return 0;
}
struct zzip_disk_trailer *trailer = (struct zzip_disk_trailer *) p;
zzip_size_t rootseek = zzip_disk_trailer_get_rootseek(trailer);
root = disk->buffer + rootseek;
- debug2("disk rootseek at %lli", (long long)rootseek);
+ DBG2("disk rootseek at %lli", (long long)rootseek);
if (root > p)
{
/* the first disk_entry is after the disk_trailer? can't be! */
zzip_size_t rootsize = zzip_disk_trailer_get_rootsize(trailer);
- debug2("have rootsize at %lli", (long long)rootsize);
+ DBG2("have rootsize at %lli", (long long)rootsize);
if (disk->buffer + rootsize > p)
continue;
/* a common brokeness that can be fixed: we just assume the
(struct zzip_disk64_trailer *) p;
if (sizeof(void *) < 8)
{
- debug1("disk64 trailer in non-largefile part");
+ DBG1("disk64 trailer in non-largefile part");
errno = EFBIG;
return 0;
}
zzip_size_t rootseek = zzip_disk64_trailer_get_rootseek(trailer);
- debug2("disk64 rootseek at %lli", (long long)rootseek);
+ DBG2("disk64 rootseek at %lli", (long long)rootseek);
root = disk->buffer + rootseek;
if (root > p)
continue;
continue;
}
- debug4("buffer %p root %p endbuf %p", disk->buffer, root, disk->endbuf);
+ DBG4("buffer %p root %p endbuf %p", disk->buffer, root, disk->endbuf);
if (root < disk->buffer)
{
- debug1("root before buffer should be impossible");
+ DBG1("root before buffer should be impossible");
errno = EBADMSG;
return 0;
}
if (zzip_disk_entry_check_magic(root))
{
- debug1("found the disk root");
+ DBG1("found the disk root");
return (struct zzip_disk_entry *) root;
}
} ____;