1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2011, 2013 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #define ZIP_READER_H 1
23 #include "libpspp/compiler.h"
29 /* Create zip reader to read the file called FILENAME. If successful, stores
30 the new zip_reader in *ZRP and returns NULL; on error, returns an error
31 message that the caller must free and stores NULL in *ZRP.
33 The client must eventually unref *ZRP. */
34 char *zip_reader_create (const char *filename
, struct zip_reader
**zrp
)
37 /* Reference counting. */
38 struct zip_reader
*zip_reader_ref (const struct zip_reader
*);
39 void zip_reader_unref (struct zip_reader
*zr
);
41 /* Returns the name of ZR's member IDX, IDX >= 0. Returns NULL if ZR has fewer
42 than (IDX + 1) members. */
43 const char *zip_reader_get_member_name(const struct zip_reader
*zr
,
46 /* Returns true if ZR contains a member named MEMBER, false otherwise. */
47 bool zip_reader_contains_member (const struct zip_reader
*zr
,
50 /* Opens the zip member named MEMBER in ZR. If successful, stores the new
51 zip_member in *ZMP and returns NULL; on error, returns an error message that
52 the caller must free and stores NULL in *ZMP. */
53 char *zip_member_open (struct zip_reader
*zr
, const char *member
,
54 struct zip_member
**zmp
) WARN_UNUSED_RESULT
;
56 /* Read up to N bytes from ZM, storing them in BUF. Returns the number of
57 bytes read, or -1 on error. On error, zip_member_steal_error() may be used
58 to obtain an error message. */
59 int zip_member_read (struct zip_member
*zm
, void *buf
, size_t n
);
61 /* Read all of ZM into memory, storing the data in *DATAP and its size in *NP.
62 Returns NULL if successful, otherwise an error string that the caller
63 must eventually free(). */
64 char *zip_member_read_all (struct zip_reader
*, const char *member_name
,
65 void **datap
, size_t *np
) WARN_UNUSED_RESULT
;
67 /* Returns the error message in ZM (and clears it out of ZM). The caller must
68 eventually free the returned string. */
69 char *zip_member_steal_error (struct zip_member
*zm
) WARN_UNUSED_RESULT
;
71 void zip_member_finish (struct zip_member
*zm
);