X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fzip-reader.h;h=d245e3c6d3eb776f03da770271fba7a946b32c22;hb=e43a19f339e8eb3a652754001f6668ae0747308c;hp=05642ffdc0ca2c442eef14a070d3b3a878d3f9e0;hpb=b9ccea9860d7123988968605f526a288f27f7544;p=pspp diff --git a/src/libpspp/zip-reader.h b/src/libpspp/zip-reader.h index 05642ffdc0..d245e3c6d3 100644 --- a/src/libpspp/zip-reader.h +++ b/src/libpspp/zip-reader.h @@ -18,35 +18,58 @@ #ifndef ZIP_READER_H #define ZIP_READER_H 1 +#include +#include +#include "libpspp/compiler.h" + struct zip_member; struct zip_reader; struct string; -void zm_dump (const struct zip_member *zm); +/* Create zip reader to read the file called FILENAME. If successful, stores + the new zip_reader in *ZRP and returns NULL; on error, returns an error + message that the caller must free and stores NULL in *ZRP. + + The client must eventually unref *ZRP. */ +char *zip_reader_create (const char *filename, struct zip_reader **zrp) + WARN_UNUSED_RESULT; -/* Create zip reader to read the file called FILENAME. - If ERRS is non-null if will be used to contain any error messages - which the reader wishes to report. - */ -struct zip_reader *zip_reader_create (const char *filename, struct string *errs); +/* Reference counting. */ +struct zip_reader *zip_reader_ref (const struct zip_reader *); +void zip_reader_unref (struct zip_reader *zr); -/* Destroy the zip reader */ -void zip_reader_destroy (struct zip_reader *zr); +/* Returns the name of ZR's member IDX, IDX >= 0. Returns NULL if ZR has fewer + than (IDX + 1) members. */ +const char *zip_reader_get_member_name(const struct zip_reader *zr, + size_t idx); -/* Return the zip member in the reader ZR, called MEMBER */ -struct zip_member *zip_member_open (struct zip_reader *zr, const char *member); +/* Returns true if ZR contains a member named MEMBER, false otherwise. */ +bool zip_reader_contains_member (const struct zip_reader *zr, + const char *member); -/* Read up to N bytes from ZM, storing them in BUF. - Returns the number of bytes read, or -1 on error */ +/* Opens the zip member named MEMBER in ZR. If successful, stores the new + zip_member in *ZMP and returns NULL; on error, returns an error message that + the caller must free and stores NULL in *ZMP. */ +char *zip_member_open (struct zip_reader *zr, const char *member, + struct zip_member **zmp) WARN_UNUSED_RESULT; + +/* Read up to N bytes from ZM, storing them in BUF. Returns the number of + bytes read, or -1 on error. On error, zip_member_steal_error() may be used + to obtain an error message. */ int zip_member_read (struct zip_member *zm, void *buf, size_t n); -/* Unref (and possibly destroy) the zip member ZM */ -void zip_member_unref (struct zip_member *zm); +/* Read all of ZM into memory, storing the data in *DATAP and its size in *NP. + Returns NULL if successful, otherwise an error string that the caller + must eventually free(). */ +char *zip_member_read_all (struct zip_reader *, const char *member_name, + void **datap, size_t *np) WARN_UNUSED_RESULT; -/* Ref the zip member */ -void zip_member_ref (struct zip_member *zm); +/* Returns the error message in ZM (and clears it out of ZM). The caller must + eventually free the returned string. */ +char *zip_member_steal_error (struct zip_member *zm) WARN_UNUSED_RESULT; void zip_member_finish (struct zip_member *zm); + #endif