summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2013-05-20 16:04:35 +0200
committerportix <portix@gmx.net>2013-05-20 16:04:35 +0200
commitaa1fb093dad88ef2e56bad3a19a27015b5ac59fc (patch)
tree06affb184b2cb073b3e017e75ed69cbd4237fb22
parente9ce243ab6db2dac67ab0982a62b4f2e54134087 (diff)
downloaddwb-aa1fb093dad88ef2e56bad3a19a27015b5ac59fc.zip
Using off_t for filesizes in exar.c
-rw-r--r--dwbem/dwbem.c4
-rw-r--r--exar/exar.c29
-rw-r--r--exar/exar.h6
-rw-r--r--exar/main.c26
-rw-r--r--src/scripts.c2
5 files changed, 38 insertions, 29 deletions
diff --git a/dwbem/dwbem.c b/dwbem/dwbem.c
index 12a3f944..cbfb4368 100644
--- a/dwbem/dwbem.c
+++ b/dwbem/dwbem.c
@@ -1196,9 +1196,9 @@ exar_help(int ret)
}
static void
exar_xextract(const char *archive, const char *path,
- unsigned char * (*extract_func)(const char *, const char *, size_t *))
+ unsigned char * (*extract_func)(const char *, const char *, off_t *))
{
- size_t s;
+ off_t s;
unsigned char *content = extract_func(archive, path, &s);
if (content != NULL)
{
diff --git a/exar/exar.c b/exar/exar.c
index aa5bb2d6..a222377e 100644
--- a/exar/exar.c
+++ b/exar/exar.c
@@ -29,6 +29,7 @@
#include <ftw.h>
#include <errno.h>
#include <assert.h>
+#include <inttypes.h>
#include "exar.h"
#define EXAR_VERSION_BASE "exar-"
@@ -58,7 +59,7 @@
struct exar_header_s {
unsigned char eh_flag;
- size_t eh_size;
+ off_t eh_size;
char eh_name[EXAR_NAME_MAX];
};
@@ -185,7 +186,7 @@ get_file_header(FILE *f, struct exar_header_s *head)
{
char *endptr;
char header[HDR_NAME];
- size_t fs;
+ off_t fs;
char rb;
size_t i = 0;
int st_version = 0;
@@ -210,7 +211,7 @@ get_file_header(FILE *f, struct exar_header_s *head)
}
if (head->eh_flag == FILE_FLAG)
{
- fs = strtoul(&header[HDR_SIZE], &endptr, 16);
+ fs = strtol(&header[HDR_SIZE], &endptr, 16);
if (*endptr)
{
LOG(1, "Cannot determine file size\n");
@@ -235,7 +236,7 @@ get_file_header(FILE *f, struct exar_header_s *head)
}
}
- LOG(2, "Found file header (%s, %c, %zu)\n", head->eh_name, head->eh_flag, head->eh_size);
+ LOG(2, "Found file header (%s, %c, %jd)\n", head->eh_name, head->eh_flag, (intmax_t)head->eh_size);
return EE_OK;
}
static int
@@ -246,7 +247,7 @@ find_cmp(const char *name, const char *search)
return strcmp(&name[offset], search);
}
static unsigned char *
-extract(const char *archive, const char *file, size_t *s, int (*cmp)(const char *, const char *))
+extract(const char *archive, const char *file, off_t *s, int (*cmp)(const char *, const char *))
{
struct exar_header_s header;
FILE *f = NULL;
@@ -264,7 +265,7 @@ extract(const char *archive, const char *file, size_t *s, int (*cmp)(const char
{
ret = xcalloc(header.eh_size, sizeof(unsigned char));
LOG(3, "Reading %s\n", header.eh_name);
- if (fread(ret, 1, header.eh_size, f) != header.eh_size)
+ if (fread(ret, 1, header.eh_size, f) != (size_t)header.eh_size)
{
fprintf(stderr, "Failed to read %s\n", header.eh_name);
*s = -1;
@@ -291,7 +292,7 @@ finish:
}
static int
-write_file_header(FILE *f, const char *name, char flag, size_t r)
+write_file_header(FILE *f, const char *name, char flag, off_t r)
{
char buffer[HDR_NAME] = {0};
size_t l_name;
@@ -472,10 +473,10 @@ exar_unpack(const char *archive, const char *dest)
goto finish;
}
- LOG(2, "Writing %s (%zu bytes)\n", header.eh_name, header.eh_size);
- for (size_t i=0; i<header.eh_size; i += sizeof(buf))
+ LOG(2, "Writing %s (%jd bytes)\n", header.eh_name, (intmax_t)header.eh_size);
+ for (off_t i=0; i<header.eh_size; i += sizeof(buf))
{
- if ( (r = fread(buf, 1, MIN(sizeof(buf), header.eh_size - i), f)) != 0)
+ if ( (r = fread(buf, 1, MIN(sizeof(buf), (size_t)header.eh_size - i), f)) != 0)
{
if (fwrite(buf, 1, r, of) != r)
{
@@ -495,14 +496,14 @@ finish:
}
unsigned char *
-exar_extract(const char *archive, const char *file, size_t *s)
+exar_extract(const char *archive, const char *file, off_t *s)
{
assert(archive != NULL && file != NULL);
return extract(archive, file, s, strcmp);
}
unsigned char *
-exar_search_extract(const char *archive, const char *file, size_t *s)
+exar_search_extract(const char *archive, const char *file, off_t *s)
{
assert(archive != NULL && file != NULL);
@@ -560,7 +561,7 @@ exar_delete(const char *archive, const char *file)
if (header.eh_flag == FILE_FLAG)
{
LOG(2, "Copying %s (%zu bytes)\n", header.eh_name, header.eh_size);
- for (size_t s=0; s<header.eh_size; s++)
+ for (off_t s=0; s<header.eh_size; s++)
{
if (fread(&rbuf, 1, 1, f) != 1 || fwrite(&rbuf, 1, 1, ftmp) != 1)
{
@@ -601,7 +602,7 @@ exar_info(const char *archive)
goto finish;
while(get_file_header(f, &header) == 0)
{
- fprintf(stdout, "%c %-14zu %s\n", header.eh_flag, header.eh_size, header.eh_name);
+ fprintf(stdout, "%c %-14jd %s\n", header.eh_flag, (intmax_t)header.eh_size, header.eh_name);
if (header.eh_flag == FILE_FLAG)
fseek(f, header.eh_size, SEEK_CUR);
}
diff --git a/exar/exar.h b/exar/exar.h
index 105610cb..1fa6f109 100644
--- a/exar/exar.h
+++ b/exar/exar.h
@@ -38,7 +38,7 @@
#ifndef __EXAR_H__
#define __EXAR_H__
-#include <stdio.h>
+#include <sys/types.h>
enum {
EXAR_VERBOSE_L1 = 1<<0,
@@ -86,7 +86,7 @@ exar_unpack(const char *path, const char *dest);
* occured or the file was not found in the archive
* */
unsigned char *
-exar_extract(const char *archive, const char *file, size_t *size);
+exar_extract(const char *archive, const char *file, off_t *size);
/*
* Searches for a file and extracts the content from the archive.
@@ -100,7 +100,7 @@ exar_extract(const char *archive, const char *file, size_t *size);
* occured or the file was not found in the archive
* */
unsigned char *
-exar_search_extract(const char *archive, const char *search, size_t *size);
+exar_search_extract(const char *archive, const char *search, off_t *size);
/*
* Deletes a file from the archive, if it is a directory it is removed
diff --git a/exar/main.c b/exar/main.c
index 604946e1..b1f354c5 100644
--- a/exar/main.c
+++ b/exar/main.c
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
#include "exar.h"
enum {
@@ -28,6 +29,7 @@ enum {
EXAR_FLAG_D = 1<<7,
EXAR_FLAG_L = 1<<8,
EXAR_FLAG_S = 1<<9,
+ EXAR_FLAG_A = 1<<10,
};
#ifndef MIN
#define MIN(X, Y) ((X) > (Y) ? (Y) : (X))
@@ -46,6 +48,7 @@ help(int ret)
" exar option [arguments]\n\n"
"OPTIONS:\n"
" h Print this help and exit.\n"
+ " a[v] archive file Appends a file or directory to the archive\n"
" d[v] archive file Deletes a file from an archive, the file path is the\n"
" relative file path of the file in the archive\n"
" e[v] archive file Extracts a file from an archive and writes the content\n"
@@ -71,9 +74,9 @@ help(int ret)
}
static void
extract(const char *archive, const char *path,
- unsigned char * (*extract_func)(const char *, const char *, size_t *))
+ unsigned char * (*extract_func)(const char *, const char *, off_t *))
{
- size_t s;
+ off_t s;
unsigned char *content = extract_func(archive, path, &s);
if (content != NULL)
{
@@ -94,24 +97,27 @@ main (int argc, char **argv)
{
switch (*options)
{
- case 'p' :
- flag |= EXAR_FLAG_P;
+ case 'a' :
+ flag |= EXAR_FLAG_A;
break;
- case 'u' :
- flag |= EXAR_FLAG_U;
+ case 'd' :
+ flag |= EXAR_FLAG_D;
break;
case 'e' :
flag |= EXAR_FLAG_E;
break;
- case 'd' :
- flag |= EXAR_FLAG_D;
- break;
case 'l' :
flag |= EXAR_FLAG_L;
break;
+ case 'p' :
+ flag |= EXAR_FLAG_P;
+ break;
case 's' :
flag |= EXAR_FLAG_S;
break;
+ case 'u' :
+ flag |= EXAR_FLAG_U;
+ break;
case 'v' :
flag |= MAX(EXAR_FLAG_V, MIN(EXAR_VERBOSE_MASK, ((flag & EXAR_VERBOSE_MASK) << 1)));
break;
@@ -127,6 +133,8 @@ main (int argc, char **argv)
if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_U))
exar_unpack(argv[2], argv[3]);
+ else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_A) && argc > 3)
+ exar_append(argv[2], argv[3]);
else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_P))
exar_pack(argv[2]);
else if (EXAR_CHECK_FLAG(flag, EXAR_FLAG_L))
diff --git a/src/scripts.c b/src/scripts.c
index be90e876..0d3a632a 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -1865,7 +1865,7 @@ global_xinclude(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t
{
char *archive = NULL, *path = NULL, *content = NULL;
JSValueRef ret = NIL;
- size_t fs;
+ off_t fs;
if (argc < 2)
return NIL;