annotate modules/zip/libzip/lib/zip_source_close.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_source_close.c -- close zip_source (stop reading)
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 Copyright (C) 2009-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 int
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
39 zip_source_close(zip_source_t *src)
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
40 {
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
41 if (!ZIP_SOURCE_IS_OPEN_READING(src)) {
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
42 zip_error_set(&src->error, ZIP_ER_INVAL, 0);
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
43 return -1;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
44 }
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
45
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
46 src->open_count--;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
47 if (src->open_count == 0) {
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
48 _zip_source_call(src, NULL, 0, ZIP_SOURCE_CLOSE);
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
49
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
50 if (ZIP_SOURCE_IS_LAYERED(src)) {
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
51 if (zip_source_close(src->src) < 0) {
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
52 zip_error_set(&src->error, ZIP_ER_INTERNAL, 0);
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
53 }
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
54 }
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
55 }
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
56
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
57 return 0;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
58 }