summaryrefslogtreecommitdiff
path: root/ext/zip/lib/zip_string.c
diff options
context:
space:
mode:
authorRemi Collet <remi@fedoraproject.org>2015-05-06 14:36:18 +0200
committerRemi Collet <remi@php.net>2015-05-06 15:16:43 +0200
commit9e0cc7a1d926c1364a834177cadea431cd8b39a7 (patch)
treef63c505073d6aa0b74bde71eb6a67e6e4c23d8bd /ext/zip/lib/zip_string.c
parent31f516b4888fcf096fe0912828948bed84f2ad1c (diff)
downloadphp-git-9e0cc7a1d926c1364a834177cadea431cd8b39a7.tar.gz
update libzip to version 1.0.1
Diffstat (limited to 'ext/zip/lib/zip_string.c')
-rw-r--r--ext/zip/lib/zip_string.c62
1 files changed, 27 insertions, 35 deletions
diff --git a/ext/zip/lib/zip_string.c b/ext/zip/lib/zip_string.c
index e3905da01b..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>
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -32,31 +32,28 @@
*/
-
#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;
-
+
crc = (zip_uint32_t)crc32(0L, Z_NULL, 0);
- if (s != NULL)
+ if (s != NULL)
crc = (zip_uint32_t)crc32(crc, s->raw, s->length);
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;
@@ -70,9 +67,8 @@ _zip_string_equal(const struct zip_string *a, const struct zip_string *b)
}
-
void
-_zip_string_free(struct zip_string *s)
+_zip_string_free(zip_string_t *s)
{
if (s == NULL)
return;
@@ -83,9 +79,8 @@ _zip_string_free(struct zip_string *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] = "";
@@ -113,16 +108,15 @@ _zip_string_get(struct zip_string *string, zip_uint32_t *lenp, zip_flags_t flags
return string->converted;
}
}
-
+
if (lenp)
*lenp = string->length;
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;
@@ -131,13 +125,12 @@ _zip_string_length(const struct zip_string *s)
}
-
-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,21 +169,20 @@ _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;
}
}
-
+
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;
-
- fwrite(s->raw, s->length, 1, f);
+ return 0;
+
+ return _zip_write(za, s->raw, s->length);
}