annotate modules/zip/libzip/lib/zip_fread.c @ 527:8f8c32f102f1

Zip: resurrection
author David Demelier <markand@malikania.fr>
date Wed, 01 Jun 2016 17:36:52 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
527
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
1 /*
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
2 zip_fread.c -- read from file
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 Copyright (C) 1999-2014 Dieter Baron and Thomas Klausner
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
4
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
5 This file is part of libzip, a library to manipulate ZIP archives.
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
6 The authors can be contacted at <libzip@nih.at>
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
7
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
8 Redistribution and use in source and binary forms, with or without
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
9 modification, are permitted provided that the following conditions
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
10 are met:
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
11 1. Redistributions of source code must retain the above copyright
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer.
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
13 2. Redistributions in binary form must reproduce the above copyright
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
14 notice, this list of conditions and the following disclaimer in
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
15 the documentation and/or other materials provided with the
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
16 distribution.
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
17 3. The names of the authors may not be used to endorse or promote
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
18 products derived from this software without specific prior
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
19 written permission.
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
20
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
21 THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
22 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
24 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
25 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
27 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
29 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
30 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
31 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
32 */
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
33
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
34
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
35 #include "zipint.h"
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
36
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
37
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
38 ZIP_EXTERN zip_int64_t
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
39 zip_fread(zip_file_t *zf, void *outbuf, zip_uint64_t toread)
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
40 {
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
41 zip_int64_t n;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
42
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
43 if (!zf)
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
44 return -1;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
45
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
46 if (zf->error.zip_err != 0)
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
47 return -1;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
48
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
49 if (toread > ZIP_INT64_MAX) {
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
50 zip_error_set(&zf->error, ZIP_ER_INVAL, 0);
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
51 return -1;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
52 }
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
53
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
54 if ((zf->eof) || (toread == 0))
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
55 return 0;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
56
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
57 if ((n=zip_source_read(zf->src, outbuf, toread)) < 0) {
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
58 _zip_error_set_from_source(&zf->error, zf->src);
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
59 return -1;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
60 }
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
61
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
62 return n;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
63 }