annotate modules/zip/libzip/lib/zip_file_get_comment.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_file_get_comment.c -- get file comment
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 Copyright (C) 2006-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 /* lenp is 32 bit because converted comment can be longer than ZIP_UINT16_MAX */
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
38
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
39 ZIP_EXTERN const char *
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
40 zip_file_get_comment(zip_t *za, zip_uint64_t idx, zip_uint32_t *lenp, zip_flags_t flags)
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
41 {
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
42 zip_dirent_t *de;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
43 zip_uint32_t len;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
44 const zip_uint8_t *str;
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 ((de=_zip_get_dirent(za, idx, flags, NULL)) == NULL)
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
47 return NULL;
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 ((str=_zip_string_get(de->comment, &len, flags, &za->error)) == NULL)
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
50 return NULL;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
51
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
52 if (lenp)
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
53 *lenp = len;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
54
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
55 return (const char *)str;
8f8c32f102f1 Zip: resurrection
David Demelier <markand@malikania.fr>
parents:
diff changeset
56 }