From owner-freebsd-hackers Tue Jan 16 09:14:19 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id JAA25987 for hackers-outgoing; Tue, 16 Jan 1996 09:14:19 -0800 (PST) Received: from time.cdrom.com (time.cdrom.com [192.216.222.226]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id JAA25981 for ; Tue, 16 Jan 1996 09:14:16 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by time.cdrom.com (8.6.12/8.6.9) with SMTP id JAA10577; Tue, 16 Jan 1996 09:13:05 -0800 To: Nate Williams cc: Michael Smith , tnaggs@cddotdot.mikom.csir.co.za, Hackers@freebsd.org Subject: Re: FBSD 2.1 In-reply-to: Your message of "Tue, 16 Jan 1996 08:47:13 MST." <199601161547.IAA04366@rocky.sri.MT.net> Date: Tue, 16 Jan 1996 09:13:05 -0800 Message-ID: <10575.821812385@time.cdrom.com> From: "Jordan K. Hubbard" Sender: owner-hackers@freebsd.org Precedence: bulk Ok, you wanted a library API, how about this one? Where ZIP_t is an opaque type: ZIP_t zip_init(int fd) Returns ZIP file handle for already open fd, or NULL on failure. fd should be open for reading, at a minimum, and positioned at the beginning of the file. int zip_options(ZIP_t zp, int opts) Used to set things like compression levels, whether existing entries are replaced by default, etc. I'll leave the definition of `opts' to the implementor. int zip_add(ZIP_t zp, char *fname, int link) Add file fname to zip file (which must be writable). If fname is a link and link is true, the link will be stored as a link, otherwise what it points to will be stored. [I don't know if you want to also do a version which will add directly from a fd - it seems like it'd be cute, but I can't think of any immediate uses :-)] Return 0 on success, -1 if file non-existant, -2 if permission denied. int zip_delete(ZIP_t zp, char *fname) Delete entry named fname from the zip file. Return 0 on success, -1 if file non-existant, -2 if permission denied. int zip_test(ZIP_t zp) Returns 0 if zip file passes internal consistency checks, an internal error code (defined as the set of meaningful condition codes zip can generate, I guess) if not. int zip_dir(ZIP_t zp, int *nitems, char ***list) Return table of contents for zip file, using nitems and list values to pass back the item count and array of char * pointers holding the filenames. Return 0 on success, -1 on failure. User is expected to free contents of list when done with it. int zip_attrs(ZIP_t zp, char *fname, ZIP_file_attrs *attrs) Returns `long' file attributes for a given file, returning the result in the public structure `attrs'. I'm not sure what fields are available in a zip file header, but I'd imagine this being stuff like the creation date, length, etc. Returns 0 on success, -1 on error. int zip_fdopen(ZIP_t zp, char *fname) Return a file descriptor for an entry in a zip file. When a read from the new fd returns EOF, a zip_close() on the fd should be done to clean up any state lying around. Returns new fd on success or -1 if entry not found/open failed. int zip_fdclose(ZIP_t zp, int fd) Close a file descriptor previously returned by zip_open(). Returns 0 on success, -1 on error. char *zip_read(ZIP_t zp, char *fname) Return an entry in a zip file as a single string. User is expected to free storage when done with it. Returns NULL if file could not be found or sufficient memory could not be allocated. int zip_close(ZIP_t zp) Close a zip file and any open resources. This will also invalidate any open handles returned by zip_fdopen(). That should handle just about all the major contingencies that I can think of.. Any major holes in my reasoning anyone can see here? Jordan