summaryrefslogtreecommitdiff
path: root/ext/zip/lib/zip_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/zip/lib/zip_string.c')
-rw-r--r--ext/zip/lib/zip_string.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/ext/zip/lib/zip_string.c b/ext/zip/lib/zip_string.c
index 4e8709b5f7..307a425f78 100644
--- a/ext/zip/lib/zip_string.c
+++ b/ext/zip/lib/zip_string.c
@@ -1,6 +1,6 @@
/*
zip_string.c -- string handling (with encoding)
- Copyright (C) 2012 Dieter Baron and Thomas Klausner
+ Copyright (C) 2012-2014 Dieter Baron and Thomas Klausner
This file is part of libzip, a library to manipulate ZIP archives.
The authors can be contacted at <libzip@nih.at>
@@ -31,17 +31,15 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
#include <stdlib.h>
#include <string.h>
#include "zipint.h"
-
zip_uint32_t
-_zip_string_crc32(const struct zip_string *s)
+_zip_string_crc32(const zip_string_t *s)
{
zip_uint32_t crc;
@@ -53,10 +51,9 @@ _zip_string_crc32(const struct zip_string *s)
return crc;
}
-
int
-_zip_string_equal(const struct zip_string *a, const struct zip_string *b)
+_zip_string_equal(const zip_string_t *a, const zip_string_t *b)
{
if (a == NULL || b == NULL)
return a == b;
@@ -69,10 +66,9 @@ _zip_string_equal(const struct zip_string *a, const struct zip_string *b)
return (memcmp(a->raw, b->raw, a->length) == 0);
}
-
void
-_zip_string_free(struct zip_string *s)
+_zip_string_free(zip_string_t *s)
{
if (s == NULL)
return;
@@ -82,10 +78,9 @@ _zip_string_free(struct zip_string *s)
free(s);
}
-
const zip_uint8_t *
-_zip_string_get(struct zip_string *string, zip_uint32_t *lenp, zip_flags_t flags, struct zip_error *error)
+_zip_string_get(zip_string_t *string, zip_uint32_t *lenp, zip_flags_t flags, zip_error_t *error)
{
static const zip_uint8_t empty[1] = "";
@@ -119,10 +114,9 @@ _zip_string_get(struct zip_string *string, zip_uint32_t *lenp, zip_flags_t flags
return string->raw;
}
-
zip_uint16_t
-_zip_string_length(const struct zip_string *s)
+_zip_string_length(const zip_string_t *s)
{
if (s == NULL)
return 0;
@@ -130,13 +124,12 @@ _zip_string_length(const struct zip_string *s)
return s->length;
}
-
-struct zip_string *
-_zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, struct zip_error *error)
+zip_string_t *
+_zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags, zip_error_t *error)
{
- struct zip_string *s;
- enum zip_encoding_type expected_encoding;
+ zip_string_t *s;
+ zip_encoding_type_t expected_encoding;
if (length == 0)
return NULL;
@@ -152,16 +145,16 @@ _zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags,
expected_encoding = ZIP_ENCODING_CP437;
break;
default:
- _zip_error_set(error, ZIP_ER_INVAL, 0);
+ zip_error_set(error, ZIP_ER_INVAL, 0);
return NULL;
}
- if ((s=(struct zip_string *)malloc(sizeof(*s))) == NULL) {
- _zip_error_set(error, ZIP_ER_MEMORY, 0);
+ if ((s=(zip_string_t *)malloc(sizeof(*s))) == NULL) {
+ zip_error_set(error, ZIP_ER_MEMORY, 0);
return NULL;
}
- if ((s->raw=(zip_uint8_t *)malloc(length+1)) == NULL) {
+ if ((s->raw=(zip_uint8_t *)malloc((size_t)(length+1))) == NULL) {
free(s);
return NULL;
}
@@ -176,7 +169,7 @@ _zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags,
if (expected_encoding != ZIP_ENCODING_UNKNOWN) {
if (_zip_guess_encoding(s, expected_encoding) == ZIP_ENCODING_ERROR) {
_zip_string_free(s);
- _zip_error_set(error, ZIP_ER_INVAL, 0);
+ zip_error_set(error, ZIP_ER_INVAL, 0);
return NULL;
}
}
@@ -184,13 +177,12 @@ _zip_string_new(const zip_uint8_t *raw, zip_uint16_t length, zip_flags_t flags,
return s;
}
-
-void
-_zip_string_write(const struct zip_string *s, FILE *f)
+int
+_zip_string_write(zip_t *za, const zip_string_t *s)
{
if (s == NULL)
- return;
+ return 0;
- fwrite(s->raw, s->length, 1, f);
+ return _zip_write(za, s->raw, s->length);
}