Discard no-meta branch.

--HG--
branch : HEAD
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..30407a0
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,99 @@
+# $NiH: CMakeLists.txt,v 1.1 2007/03/04 10:35:17 wiz Exp $
+
+# XXX: TODO
+# 1. pkgconfig file not yet built.
+# 2. installation not tested.
+# 3. Problems generating html pages.
+# 4. distribution tarball not checked for unwanted/missing content.
+# 5. create usable libtool .la file
+
+PROJECT(libzip C)
+
+INCLUDE(CheckFunctionExists)
+INCLUDE(CheckIncludeFiles)
+INCLUDE(CheckSymbolExists)
+
+SET(PACKAGE "libzip")
+SET(PACKAGE_NAME ${PACKAGE})
+SET(PACKAGE_VERSION_MAJOR "0")
+SET(PACKAGE_VERSION_MINOR "7")
+SET(PACKAGE_VERSION_PATCH "1")
+SET(VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}")
+SET(PACKAGE_VERSION ${VERSION})
+SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+
+ADD_SUBDIRECTORY(lib)
+ADD_SUBDIRECTORY(man)
+ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(regress)
+
+# Checks
+
+CHECK_FUNCTION_EXISTS(fseeko HAVE_FSEEKO)
+CHECK_FUNCTION_EXISTS(MoveFileEx HAVE_MOVEFILEEX)
+CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
+CHECK_INCLUDE_FILES(unistd.h HAVE_UNISTD_H)
+
+INCLUDE(FindZLIB)
+CHECK_SYMBOL_EXISTS(ZEXPORT zlib.h HAVE_ZEXPORT)
+IF(NOT HAVE_ZEXPORT)
+  MESSAGE(FATAL_ERROR "-- ZLIB version too old, please install at least v1.1.2")
+ENDIF(NOT HAVE_ZEXPORT)
+
+# Targets
+
+# XXX: pkgconfig file
+
+# installation
+
+# XXX: pkgconfig file
+
+# packaging
+
+SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "library for manipulating zip archives")
+SET(CPACK_PACKAGE_VENDOR "Dieter Baron <dillo@giga.or.at> and Thomas Klausner <tk@giga.or.at>")
+SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
+# XXX: provide a license file
+#SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
+SET(CPACK_PACKAGE_VERSION_MAJOR ${PACKAGE_VERSION_MAJOR})
+SET(CPACK_PACKAGE_VERSION_MINOR ${PACKAGE_VERSION_MINOR})
+SET(CPACK_PACKAGE_VERSION_PATCH ${PACKAGE_VERSION_PATCH})
+SET(CPACK_SOURCE_PACKAGE_FILE_NAME ${PACKAGE_NAME}-${PACKAGE_VERSION})
+SET(CPACK_GENERATOR "TGZ")
+SET(CPACK_SOURCE_GENERATOR "TGZ")
+SET(CPACK_SOURCE_IGNORE_FILES
+  ".a$"
+  ".cmake$"
+  ".o$"
+  ".so$"
+  "/.deps/"
+  "/.libs/"
+  "/CMakeFiles/"
+  "/CVS/"
+  "/autom4te.cache/"
+  "/build"
+  "/broken"
+  "/docs/"
+  "AdditionalInfo.txt$"
+  "CMakeCache.txt$"
+  "Makefile$"
+  "\\\\.sh$"
+  "_CPack_"
+  "config.h$"
+  "config.log$"
+  "config.status$"
+  "dccsend$"
+  "dccserver$"
+  "html$"
+  "install_manifest.txt$"
+  "stamp-h1$"
+  "tar.bz2"
+  "tar.gz"
+  "~$"
+)
+SET(CPACK_SOURCE_STRIP_FILES "")
+INCLUDE(CPack)
+
+# write out config file
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake-config.h.in
+  ${CMAKE_CURRENT_BINARY_DIR}/config.h)
diff --git a/ChangeLog b/ChangeLog
index cf6b669..03913af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,574 @@
+2006-05-18 12:01  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* ChangeLog, NEWS, configure.ac: Prepare for 0.7.1.
+
+2006-05-17 19:54  Dieter Baron <dillo@danbala.tuwien.ac.at>
+
+	* TODO: add one
+
+2006-05-10 01:55  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* regress/get_comment.c: Fix printing archive comment.
+
+2006-05-10 01:41  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* regress/add_from_buffer.c: Correct fprintf argument.
+
+2006-05-09 20:15  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* configure.ac: Bump to 0.7a.
+
+2006-05-09 19:21  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_close.c: If _zip_cdir_set_comment or
+	  _zip_create_temp_output failed, cd contained uninitialized data
+	  in cd->entry[i], which might cause bogus free()s.  Initialize cd
+	  entries.
+
+2006-05-09 18:34  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* src/zipcmp.c: Include unistd.h for optind. From Joerg
+	  Sonnenberger.
+
+2006-05-06 01:36  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* man/Makefile.am: Be more strict in regex.
+
+2006-05-06 01:16  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* ChangeLog: cvs2cl for latest entries.
+
+2006-05-06 01:13  Dieter Baron <dillo@danbala.tuwien.ac.at>
+
+	* NEWS, configure.ac: Prepare for 0.7 release.
+
+2006-05-06 01:08  Dieter Baron <dillo@danbala.tuwien.ac.at>
+
+	* TODO, regress/Makefile.am, regress/fread.c,
+	  regress/name_locate.c, regress/open.c: Fix distcheck: retire
+	  mkname (remnant from before runtest).
+
+2006-05-04 02:01  Dieter Baron <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip_open.c: Report ZIP_ERR_INCONS for zip archives with
+	  trailing garbage (if using ZIP_CHECK_CONS).
+
+2006-04-24 16:04  Dieter Baron <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip.h, lib/zip_stat_index.c, lib/zipint.h,
+	  regress/Makefile.am, regress/encrypt.c, regress/encrypt.test,
+	  regress/encrypt.zip: Fill in encryption_method in zip_stat.  XXX:
+	  strong encryption algorithms returned as unknown for now.
+
+2006-04-24 12:34  Dieter Baron <dillo@danbala.tuwien.ac.at>
+
+	* lib/: zip_memdup.c, zip_set_archive_comment.c,
+	  zip_set_file_comment.c: Fix warnings due to missing includes.
+	  Check that comment != NULL if len > 0, avoid _zip_memdup with
+	  size 0.
+
+2006-04-23 20:52  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* ChangeLog: cvs2cl for latest entries.
+
+2006-04-23 20:47  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip_open.c, src/zipcmp.c: Only check for garbage at end of
+	  file when ZIP_CHECKCONS.
+
+2006-04-23 20:47  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* configure.ac: Bump to 0.6.1d for another test release.
+
+2006-04-23 18:38  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* NEWS: Document comment support.
+
+2006-04-23 18:37  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/libzip.man: regen.
+
+2006-04-23 18:37  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/libzip.mdoc: Link zip_unchange_archive.
+
+2006-04-23 18:36  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip.h: Add zip_unchange_archive.
+
+2006-04-23 18:35  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* TODO: Another TODO done.
+
+2006-04-23 18:11  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_get_archive_comment.c: We do not check za for NULL
+	  elsewhere, so do not check it here either.
+
+2006-04-23 18:11  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_close.c: Avoid _zip_memdup of NULL.
+
+2006-04-23 17:26  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/: zip_set_archive_comment.c, zip_set_file_comment.c: Use
+	  _zip_memdup.
+
+2006-04-23 17:03  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/: zip_set_archive_comment.man, zip_set_file_comment.man:
+	  regen.
+
+2006-04-23 16:57  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/: zip_set_archive_comment.mdoc, zip_set_file_comment.mdoc:
+	  Drop trailing whitespace.
+
+2006-04-23 16:55  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/zip_source_free.man: regen.
+
+2006-04-23 16:55  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/zip_source_free.mdoc: Document that it should not be called
+	  after a successful zip_add or zip_replace.
+
+2006-04-23 16:52  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* TODO: UNISTD_H done.
+
+2006-04-23 16:51  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/mkstemp.c, lib/zip_close.c, lib/zip_dirent.c,
+	  lib/zip_file_get_offset.c, src/zipcmp.c: Remove unneeded
+	  inclusion of unistd.h.  Tested on Darwin, Irix, NetBSD, Solaris.
+
+2006-04-23 16:51  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* src/zipmerge.c: Test for HAVE_UNISTD_H before including it.
+
+2006-04-23 16:50  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_source_buffer.c: Unsigned fix for Irix cc.
+
+2006-04-23 16:50  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_open.c: Unsigned fix for Irix cc. Remove unneeded
+	  inclusion of unistd.h.
+
+2006-04-23 16:49  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_fread.c: unsigned fix for Irix cc.
+
+2006-04-23 16:49  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* configure.ac: Check for unistd.h.
+
+2006-04-23 16:33  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/Makefile.am: Set path to zipcmp in environment.
+
+2006-04-23 16:17  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/get_comment.c: Only print len characters from file
+	  comment.
+
+2006-04-23 16:13  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/Makefile.am: Add another zip file.
+
+2006-04-23 15:55  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/: set_comment_all.c, set_comment_localonly.c,
+	  set_comment_removeglobal.c, set_comment_revert.c: Remove unused
+	  variables found by Irix cc.
+
+2006-04-23 15:33  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* TODO: Remove comment related stuff.
+
+2006-04-23 15:30  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/zip_unchange_archive.man: Add.
+
+2006-04-23 15:30  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/: zip_get_archive_comment.man, zip_get_file_comment.man,
+	  zip_unchange.man, zip_unchange_all.man: regen
+
+2006-04-23 15:30  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/Makefile.am: Add zip_unchange_archive.
+
+2006-04-23 15:28  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/: set_comment_all.c, set_comment_localonly.c,
+	  set_comment_revert.c: Correct comment.
+
+2006-04-23 15:28  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/: Makefile.am, set_comment_removeglobal.c,
+	  set_comment_removeglobal.test, testcommentremoved.zip: Add test
+	  for removing archive comment.
+
+2006-04-23 15:21  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_unchange.c, regress/Makefile.am,
+	  regress/set_comment_revert.c, regress/set_comment_revert.test:
+	  Add test for comment reverting via zip_unchange_all, and fix a
+	  bug it found.
+
+2006-04-23 15:14  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/Makefile.am, lib/zip_unchange_all.c,
+	  lib/zip_unchange_archive.c, man/zip_unchange.mdoc,
+	  man/zip_unchange_all.mdoc, man/zip_unchange_archive.mdoc: Add
+	  zip_unchange_archive.
+
+2006-04-23 15:06  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip.h, lib/zip_get_archive_comment.c,
+	  lib/zip_get_file_comment.c, man/zip_get_archive_comment.mdoc,
+	  man/zip_get_file_comment.mdoc, regress/Makefile.am,
+	  regress/get_comment.c: Add flags argument to zip_get_*_comment,
+	  requested by dillo.
+
+2006-04-23 15:06  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_set_file_comment.c: Test idx argument validity.
+
+2006-04-23 15:05  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_close.c: Improve some comments, and remove a superfluous
+	  free.
+
+2006-04-23 14:50  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/: libzip.man, zip_error_get.man, zip_get_archive_comment.man,
+	  zip_get_file_comment.man, zip_get_name.man,
+	  zip_set_archive_comment.man, zip_set_file_comment.man: regen
+
+2006-04-23 14:50  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/libzip.mdoc: Link zip_set_{archive,file}_comment. Bump date.
+
+2006-04-23 14:47  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/: Makefile.am, zip_set_archive_comment.mdoc,
+	  zip_set_file_comment.mdoc: Document
+	  zip_set_{archive,file}_comment.
+
+2006-04-23 14:45  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/zip_get_file_comment.mdoc: Bump date for previous.
+
+2006-04-23 14:44  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/: zip_get_file_comment.mdoc, zip_error_get.mdoc: Consistency
+	  in argument naming.
+
+2006-04-23 14:28  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/: set_comment_localonly.c, testchangedlocal.zip: Test
+	  removing file comments too.
+
+2006-04-23 14:25  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/: Makefile.am, set_comment.c, set_comment.test,
+	  set_comment_all.c, set_comment_all.test, set_comment_localonly.c,
+	  set_comment_localonly.test, testchangedlocal.zip: Rename
+	  set_comment to set_comment_all, testing changing both global and
+	  local comments.  Add test set_comment_localonly, testing changing
+	  only local comments.
+
+2006-04-23 12:13  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_close.c: Put from code from zip_close in separate
+	  functions.
+
+2006-04-23 11:25  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_close.c: Handle malloc/free correctly. Add some comments.
+
+2006-04-23 02:40  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/: Makefile.am, zip.h, zip_close.c, zip_get_archive_comment.c,
+	  zip_memdup.c, zip_new.c, zip_open.c, zip_set_archive_comment.c,
+	  zip_set_file_comment.c, zip_unchange_all.c, zipint.h:
+	  set_*_comment support.  XXX: there's a double free somewhere, but
+	  I currently don't find its cause
+
+2006-04-23 02:39  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/: Makefile.am, comment.c, comment.test, get_comment.c,
+	  get_comment.test, set_comment.c, set_comment.test,
+	  testchanged.zip: Add test for writing comments.  Rename previous
+	  "comment" test to "get_comment" to make clear it's for reading.
+
+2006-04-23 02:38  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/: add_from_buffer.test, add_from_file.test,
+	  add_from_filep.test, fread.test, name_locate.test, open.test:
+	  Adapt for runtest update.
+
+2006-04-23 02:38  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/runtest: Sync with 1.22 from ckmame.
+
+2006-04-09 23:45  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* TODO: Add some API ideas.
+
+2006-04-09 21:05  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/Makefile.am, lib/zip.h, lib/zip_entry_free.c,
+	  lib/zip_entry_new.c, lib/zip_get_archive_comment.c,
+	  lib/zip_get_file_comment.c, lib/zip_open.c, lib/zip_unchange.c,
+	  lib/zip_unchange_all.c, lib/zipint.h, man/Makefile.am,
+	  man/libzip.mdoc, man/zip_get_archive_comment.mdoc,
+	  man/zip_get_file_comment.mdoc, regress/Makefile.am,
+	  regress/comment.c, regress/comment.test, regress/testcomment.zip:
+	  Add read-only comment support: zip_get_file_comment to get the
+	  comment for a file zip_get_archive_comment to get the comment for
+	  the whole zip archive
+
+	  Add documentation and regression test.
+
+2006-04-09  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_replace.c (_zip_replace): return idx of changed file,
+	for zip_add.
+	(zip_replace): return 0 on success, as before.
+	* man/zip_add.mdoc: update.
+
+	* lib/Makefile.am (libzip_la_SOURCES): bump libzip major.
+
+	* lib/zip.h: add encryption_method to zip_stat.
+	* man/zip_stat.mdoc: update docs.
+	* lib/zip_stat_index.c (zip_stat_index): initialize encryption_method.
+
+2006-03-25  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/zip_source_function.mdoc: fix return values; correct
+	argument name. Noted by Tara Milana.
+
+2005-07-20  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* man/zip_source_buffer.mdoc, man/zip_source_file.mdoc,
+	man/zip_source_filep.mdoc, man/zip_source_function.mdoc,
+	man/zip_source_zip.mdoc: fix return value.
+
+2005-07-17  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/Makefile.am: enable add_from_filep test.
+	* regress/add_from_filep.c, regress/add_from_filep.test: new
+	testcase.
+
+2005-07-16  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/runtest: fix typo in comment. Do not require args line.
+	* regress/fread.c, regress/name_locate.c, regress/open.c,
+	regress/fread.test, regress/name_locate.test, regress/open.test,
+	regress/Makefile.am: convert remaining tests to new testing
+	framework.
+
+2005-07-15  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/Makefile.am: convert for new-style test cases
+	* regress/add_from_file.c: add, based on add_from_buffer.c
+	* regress/add_from_buffer.c: add, based on buffadd.c.
+	* regress/buffadd.c: removed.
+	* regress/runtest: add, based on ckmame's
+
+2005-07-14  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* compile, depcomp, install-sh, missing, mkinstalldirs: update
+	from automake-1.9.6.
+
+	* configure.ac: bump version to 0.6.1
+
+	* lib/zip_fread.c (zip_fread): remove unsigned.
+
+2005-07-14  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip.h: make usable from C++. Patch from Heiko Hund.
+
+2005-07-05  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* libzip.pc.in (zipcmp): Fix path to zipcmp.
+
+2005-06-18  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_close.c, lib/zip_dirent.c, lib/zip_fread.c,
+	lib/zipint.h, src/zipcmp.c: fix some warnings with -Wsign-compare.
+
+	* configure.ac, man/Makefile.am: smarter man page installation
+	handling, avoiding symlinks.
+
+2005-06-17  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* libzip.pc: return full path to zipcmp.
+
+2005-06-09  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* configure.ac: bump version to 0.6
+
+2005-06-09  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* regress/buffadd.c (main): check string length before comparing.
+	* ltmain.sh: update from libtool-1.5.18.
+	* compile, depcomp, install-sh, missing, mkinstalldirs: Update
+	from automake-1.9.5.
+
+2005-06-09  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip_source_zip.c (zip_source_zip): if reading uncompressed,
+	set crc in stat buffer to 0.
+
+	* lib/zip_close.c (ch_set_error): use ZIP_SOURCE_ERROR to get
+	error code from source callback.
+	
+	* regress/Makefile.am: add srcdir to TESTS_ENVIRONMENT.
+	* regress/mkname.c, regress/mkname.h: add.
+	* regress/fread.c, regress/name_locate.c, regress/open.c: use
+	mkname.
+
+	* man/Makefile.am: fix DESTDIR support and uninstall.
+	
+2005-01-20  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip_get_name.c (_zip_get_name): return ZIP_ER_DELETED for
+	deleted entries if ZIP_FL_UNCHANGED isn't set.
+
+2005-01-11  Thomas Klausner  <wiz@danbala.tuwien.ac.at>
+
+	* lib/zip_name_locate.c (_zip_name_locate): fix ZIP_FL_NODIR;
+	also follow appnote.txt and only accept forward slashes as
+	directory separators.
+
+2005-01-11  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip_fopen_index.c (zip_fopen_index), lib/zip_fread.c
+	(zip_fread), lib/zip_fclose.c (zip_fclose): fix CRC checking for
+	stored files.
+	
+	* lib/zip_new.c (_zip_new): init error.
+
+	* lib/zip_error.c (_zip_error_get): set system error to 0 for
+	ZIP_ET_NONE.
+
+	* lib/zip_open.c (_zip_memdup): make static, use size_t for size
+	argument, add error argument for passing error code back to
+	caller.
+	* lib/zip_open.c (_zip_readcdir): error out if _zip_memdup
+	failes.
+	
+2004-12-28  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip_free.c (_zip_free): correctly set error of open
+	files to ZIP_ER_ZIPCLOSED.
+
+2004-12-22  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip.h: rename zip_read_func to zip_source_callback, struct
+	zip_cmd to struct zip_source_cmd, and ZIP_CMD_* to ZIP_SOURCE_*;
+	adapt users.
+	
+	* lib/zip_open.c (_zip_checkcons): always initialize variables
+
+2004-12-22  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* zip.h: Rename zip_error_sys_type to zip_error_get_sys_type.
+	Adapt callers and documentation.
+
+2004-11-30  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip_get_name.c (zip_get_name): add flags argument.
+	(_zip_get_name): new function.
+	* lib/zip_uncange.c (zip_unchange): return error if unchanging
+	name would result in duplicate name in archive.
+	
+	* lib/zip_name_locate.c (_zip_name_locate): new function.
+	(zip_name_locate): move actual name lookup to _zip_name_locate.
+	* lib/zip_set_name.c (_zip_set_name): don't allow duplicate names
+	in archive; return error if name is NULL.
+	* lib/zip_replace.c (_zip_replace): don't call _zip_set_name when
+	name is NULL.
+	* lib/zip_get_name.c (zip_get_name): fix when called with
+	partially initialized entry.
+	
+2004-11-30  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* zipint.h: Include zip.h; add zlib.h.
+	* zip.h: Remove zlib.h.
+	* src/zipcmp.c: Add zlib.h.
+
+	* zipint.h: Rename _zip_new_entry to _zip_entry_new;
+	rename _zip_free_entry to _zip_entry_free; adapt users.
+
+2004-11-18  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* zip.h: Rename zip_source_data to zip_source_buffer.
+	Adapt users and documentation.
+
+	* lib/zip_source_*: Verify user-supplied data.
+
+	* zip.h: Rename zip_get_error to zip_error_get;
+	rename zip_file_get_error to zip_file_error_get;
+	rename zip_error_str to zip_error_to_str;
+	replace various zip_add_* and zip_replace_* functions
+	with zip_source_*.  Adapt users.  Update docs.
+
+2004-11-17  Thomas Klausner <wiz@danbala.tuwien.ac.at>
+
+	* zip.h: Rename ZERR_* to ZIP_ER_*; rename ZIP_ET_ZIP to
+	ZIP_ET_ZLIB; remove ZIP_CH_ISCOMP from zip.h.  Adapt users.
+
+2004-04-17  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip_replace_zip.c (_zip_replace_zip): set ZIP_CH_ISCOMP when
+	copying compressed data.
+
+	* lib/zip_fclose.c (zip_fclose): don't compare crc when reading
+	compressed data.
+	* lib/zip_fread.c (zip_fread): don't compute crc when reading
+	compressed data.
+
+2004-04-16  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+	* lib/zip_name_locate.c (zip_name_locate): honour
+	ZIP_FL_UNCHANGED, handle `\' for ZIP_FL_NODIR.
+
+	* lib/zip_stat_index.c (zip_stat_index): return ZERR_INVAL if
+	ZIP_FL_UNCHANGED is specified and file was added.  Honour
+	ZIP_FL_UNCHANGED for name.  If file was changed and
+	ZIP_FL_UNCHANGED is not given, call ch_func with command
+	ZIP_CMD_STAT.
+
+	* lib/zip_fopen_index.c (zip_fopen_index): return ZERR_INVAL if
+	ZIP_FL_UNCHANGED is specified and file was added.
+	
+2004-04-14  Dieter Baron  <dillo@danbala.tuwien.ac.at>
+
+        * TODO, lib/Makefile.am, lib/zip.h, lib/zip_add.c,
+          lib/zip_add_data.c, lib/zip_add_file.c, lib/zip_add_filep.c,
+          lib/zip_add_zip.c, lib/zip_close.c, lib/zip_delete.c,
+          lib/zip_dirent.c, lib/zip_error.c, lib/zip_error_str.c,
+          lib/zip_fclose.c, lib/zip_file_get_offset.c, lib/zip_fopen.c,
+          lib/zip_fopen_index.c, lib/zip_fread.c, lib/zip_free.c,
+          lib/zip_free_entry.c, lib/zip_free_meta.c, lib/zip_get_name.c,
+          lib/zip_merge_meta.c, lib/zip_name_locate.c, lib/zip_new.c,
+          lib/zip_new_entry.c, lib/zip_new_meta.c, lib/zip_open.c,
+          lib/zip_rename.c, lib/zip_replace.c, lib/zip_replace_data.c,
+          lib/zip_replace_file.c, lib/zip_replace_filep.c,
+          lib/zip_replace_zip.c, lib/zip_set_name.c, lib/zip_stat.c,
+          lib/zip_stat_index.c, lib/zip_unchange.c,
+          lib/zip_unchange_data.c, lib/zipint.h, man/zip_fopen.man,
+          man/zip_fopen.mdoc, man/zip_name_locate.man,
+          man/zip_name_locate.mdoc, man/zip_stat.man, man/zip_stat.mdoc,
+	  regress/buffadd.c, regress/open.c, src/zipcmp.c: Remove
+	  zip_meta structure.
+
 2003-12-30  Dieter Baron  <dillo@danbala.tuwien.ac.at>
 
 	* src/zipcmp.c (compare_zip): use correct index.
diff --git a/Makefile.am b/Makefile.am
index f4ec11e..96f65b4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,10 +1,12 @@
 # not GPL, thus no COPYING
-AUTOMAKE_OPTIONS=foreign
+AUTOMAKE_OPTIONS=dist-bzip2 foreign
 
 SUBDIRS=lib src man regress
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libzip.pc
 
-EXTRA_DIST=	libzip.pc.in \
+EXTRA_DIST=	CMakeLists.txt \
+		cmake-config.h.in \
+		libzip.pc.in \
 		libzip-uninstalled.pc.in
diff --git a/NEWS b/NEWS
index 4faecbc..99c346b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,31 @@
-0.6
+0.8
+
+* fix zip_error_strerror to include libzip error string
+* add support for streamed zip files
+* new functions: zip_add_dir, zip_error_clear, zip_file_error_clear
+* add basic support for building with CMake
+
+0.7.1 [2006/05/18]
+
+* bugfix for zip_close
+
+0.7 [2006/05/06]
+
+* struct zip_stat increased for future encryption support
+* zip_add return value changed (now returns new index of added file)
+* shared library major bump because of previous two
+* added functions for reading and writing file and archive comments.
+  New functions: zip_get_archive_comment, zip_get_file_comment,
+  zip_set_archive_comment, zip_set_file_comment, zip_unchange_archive
+
+0.6.1 [2005/07/14]
+
+* various bug fixes
+
+0.6 [2005/06/09]
 
 * first standalone release
 * changed license to three-clause BSD
 * overhauled API
-* install zipcmp
+* added man pages
+* install zipcmp and zipmerge
diff --git a/README b/README
index e69de29..ed5f78b 100644
--- a/README
+++ b/README
@@ -0,0 +1,22 @@
+  This is libzip, a C library for reading, creating, and modifying zip
+archives.  Files can be added from data buffers, files, or compressed
+data copied directly from other zip archives.  Changes made without
+closing the archive can be reverted.  The API is documented by man
+pages.
+
+  For more information, take a look at the included man pages.  You
+can start with libzip(3), which lists all others.  Example source code
+is in the src/ subdirectory.
+
+  For generic installation instructions, see file `INSTALL'.
+Additionally, you'll need zlib (at least version 1.1.2). It comes
+with most operating systems nowadays, or you can get it at
+	http://www.gzip.org/zlib/
+
+  If you make a binary distribution, please include a pointer to the
+distribution site:
+	http://www.nih.at/libzip/
+	ftp.nih.at /pub/nih/libzip
+The latest version can always be found there.
+
+Mail suggestions and bug reports to <nih@giga.or.at>.
diff --git a/THANKS b/THANKS
new file mode 100644
index 0000000..da0f66e
--- /dev/null
+++ b/THANKS
@@ -0,0 +1,8 @@
+Thanks to Info-ZIP for info on the DOS-time/date conversion code,
+and some other general information gathered from their sources.
+
+Thanks to these people for suggestions, testing, and bug reports:
+
+Heiko Hund <heiko@ist.eigentlich.net>
+Joel Ebrahimi <joel.ebrahimi@gmail.com>
+Pierre <pierre.dev@gmail.com>
diff --git a/TODO b/TODO
index 3b23607..f946830 100644
--- a/TODO
+++ b/TODO
@@ -1,26 +1,91 @@
------------------------------------------------- showstopper
-* API cleanup
-	check function names (consistency, appropriateness)
-	file sizes, offsets: type big enough? (no, zip64)
-	let ch_func report errors back to caller
-* documentation: zip_add zip_add_data zip_add_file zip_add_filep zip_add_zip
-	zip_error_sys_type zip_file_get_error zip_get_error
-	zip_replace zip_replace_data zip_replace_file zip_replace_filep
-	zip_replace_zip
-* regression tests
-* code review
-* README
-* set mtime for changed entries
++ [bug] check/cleaup flags bit 3 (streaming) support
+. [cleanup] remove now useless check of fseek 
+* [consistency check] check that local headers come before central dir
+* [bug] zip_open: consistency check: check data descriptor
+* [bug] do not compress if storing is smaller
+* [bug] zip_open: check whether file can be created and fail if not
+* [bug] check for limits imposed by format (central dir size, file size, ...)
+- [feature] handle zip_open/zip_close "race" for new files
+- [feature] support streaming output (creating new archive to e.g. stdout)
+- [feature] add functions to:
+  . set compression method for new/changed entry
+  . set last modification time for entry
+  . read/set EAs
+  . parse/create some EAs?
+  . read/set ASCII file flag
+------------------------------------------------ API ideas
+struct zip *zip_open_encrypted(const char *path, int flags,
+                               const char *password, int *errorp);
+void zip_set_default_password(struct zip *archive, const char *password);
+(NULL for unsetting)
+
+struct zip_file *zip_fopen_encrypted(struct zip *archive,
+                                     const char *fname, int flags,
+                                     const char *password);
+struct zip_file *zip_fopen_index_encrypted(struct zip *archive,
+                                           int index, int flags,
+                                           const char *password);
+
+int zip_set_encryption(struct zip *archive, int idx, int method,
+                       const char *password);
+void zip_set_archive_encryption(struct zip *archive, int encryption_method,
+                                const char *password);
+
+struct zip_source *zip_source_writable(struct zip *archive);
+zip_source_write(struct zip_source *, const void *data, size_t len);
+zip_source_printf(struct zip_source *, const char *fmt, ...);
+/* maybe
+zip_source_vprintf(struct zip_source *, const char *fmt, va_list ap);
+*/
 ------------------------------------------------ others
-* API for (file and archive) comments
-* fix warnings in zipcmp
+* regression tests (duplicate file names, unchange, .{200})
+* zip_commit
+* zip_replace_zip: allow rewinding
+* API for extracting and setting extra fields
 * zipcmp: add option for file content comparison
 * support for zip64 (large file)
 
-* don't allow the same filename twice in a zip (when adding/replacing)
 * append to files (for self-extracting files)
 * add custom compression function support
 * zip_replace_zip: remember compression method, recompress if different speced
 * close even if error...
-* update-zip (instead of close, reopen)
 * support for old compression methods?????
+------------------------------------------------ regression tests
+* (add, replace)
+	add to empty zip
+	add to existing zip
+	add w/ existing file name [E]
+	replace ok
+	replace w/ illegal index [E]
+	replace w/ deleted name [E]
+	unchange added/replaced file
+* (close)
+	copy zip file
+	open copy
+	rename, delete, replace, add w/ new name, add w/ deleted name
+	close
+	zipcmp copy expected
+	remove copy
+* (delete)
+* (error_get)
+* (error_get_sys_type)
+* (error_to_str)
+* (file_error_get)
+* (file_strerror)
+* (fopen_index)
+	illegal index
+* (get_name)
+* (get_num_files)
+* (rename)
+* (replace)
+* (source_buffer)
+* (source_file)
+* (source_filep)
+* (source_free)
+* (source_function)
+* (source_zip)
+* (stat)
+* (stat_index)
+* (strerror)
+* (unchange)
+* (unchange_all)
diff --git a/cmake-config.h.in b/cmake-config.h.in
new file mode 100644
index 0000000..bfc61f0
--- /dev/null
+++ b/cmake-config.h.in
@@ -0,0 +1,9 @@
+#ifndef HAD_CONFIG_H
+#define HAD_CONFIG_H
+#cmakedefine HAVE_FSEEKO
+#cmakedefine HAVE_MKSTEMP
+#cmakedefine HAVE_MOVEFILEEX
+#cmakedefine HAVE_UNISTD_H
+#define PACKAGE "@PACKAGE@"
+#define VERSION "@VERSION@"
+#endif /* HAD_CONFIG_H */
diff --git a/compile b/compile
index a81e000..1b1d232 100755
--- a/compile
+++ b/compile
@@ -1,9 +1,9 @@
 #! /bin/sh
 # Wrapper for compilers which do not understand `-c -o'.
 
-scriptversion=2003-11-09.00
+scriptversion=2005-05-14.22
 
-# Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
 # Written by Tom Tromey <tromey@cygnus.com>.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,7 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -47,45 +47,49 @@
 
 Report bugs to <bug-automake@gnu.org>.
 EOF
-    exit 0
+    exit $?
     ;;
   -v | --v*)
     echo "compile $scriptversion"
-    exit 0
+    exit $?
     ;;
 esac
 
-
-prog=$1
-shift
-
 ofile=
 cfile=
-args=
-while test $# -gt 0; do
-  case "$1" in
-    -o)
-      # configure might choose to run compile as `compile cc -o foo foo.c'.
-      # So we do something ugly here.
-      ofile=$2
-      shift
-      case "$ofile" in
-	*.o | *.obj)
-	  ;;
-	*)
-	  args="$args -o $ofile"
-	  ofile=
-	  ;;
-      esac
-       ;;
-    *.c)
-      cfile=$1
-      args="$args $1"
-      ;;
-    *)
-      args="$args $1"
-      ;;
-  esac
+eat=
+
+for arg
+do
+  if test -n "$eat"; then
+    eat=
+  else
+    case $1 in
+      -o)
+	# configure might choose to run compile as `compile cc -o foo foo.c'.
+	# So we strip `-o arg' only if arg is an object.
+	eat=1
+	case $2 in
+	  *.o | *.obj)
+	    ofile=$2
+	    ;;
+	  *)
+	    set x "$@" -o "$2"
+	    shift
+	    ;;
+	esac
+	;;
+      *.c)
+	cfile=$1
+	set x "$@" "$1"
+	shift
+	;;
+      *)
+	set x "$@" "$1"
+	shift
+	;;
+    esac
+  fi
   shift
 done
 
@@ -95,36 +99,38 @@
   # normal compilation that the losing compiler can handle.  If no
   # `.c' file was seen then we are probably linking.  That is also
   # ok.
-  exec "$prog" $args
+  exec "$@"
 fi
 
 # Name of file we expect compiler to create.
-cofile=`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
+cofile=`echo "$cfile" | sed -e 's|^.*/||' -e 's/\.c$/.o/'`
 
 # Create the lock directory.
 # Note: use `[/.-]' here to ensure that we don't use the same name
 # that we are using for the .o file.  Also, base the name on the expected
 # object file name, since that is what matters with a parallel build.
-lockdir=`echo $cofile | sed -e 's|[/.-]|_|g'`.d
+lockdir=`echo "$cofile" | sed -e 's|[/.-]|_|g'`.d
 while true; do
-  if mkdir $lockdir > /dev/null 2>&1; then
+  if mkdir "$lockdir" >/dev/null 2>&1; then
     break
   fi
   sleep 1
 done
 # FIXME: race condition here if user kills between mkdir and trap.
-trap "rmdir $lockdir; exit 1" 1 2 15
+trap "rmdir '$lockdir'; exit 1" 1 2 15
 
 # Run the compile.
-"$prog" $args
-status=$?
+"$@"
+ret=$?
 
 if test -f "$cofile"; then
   mv "$cofile" "$ofile"
+elif test -f "${cofile}bj"; then
+  mv "${cofile}bj" "$ofile"
 fi
 
-rmdir $lockdir
-exit $status
+rmdir "$lockdir"
+exit $ret
 
 # Local Variables:
 # mode: shell-script
diff --git a/config.guess b/config.guess
index 61f2e4c..3d427f0 100755
--- a/config.guess
+++ b/config.guess
@@ -1,9 +1,13 @@
 #! /bin/sh
+#
+# $NetBSD: config.guess,v 1.9 2006/10/29 23:50:54 wiz Exp $
+#
 # Attempt to guess a canonical system name.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
+#   Inc.
 
-timestamp='2003-10-20'
+timestamp='2006-07-02'
 
 # This file is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License as published by
@@ -17,13 +21,15 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
 #
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # configuration script generated by Autoconf, you may include it under
 # the same distribution terms that you use for the rest of that program.
 
+
 # Originally written by Per Bothner <per@bothner.com>.
 # Please send patches to <config-patches@gnu.org>.  Submit a context
 # diff and a properly formatted ChangeLog entry.
@@ -53,7 +59,7 @@
 GNU config.guess ($timestamp)
 
 Originally written by Per Bothner.
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
@@ -66,11 +72,11 @@
 while test $# -gt 0 ; do
   case $1 in
     --time-stamp | --time* | -t )
-       echo "$timestamp" ; exit 0 ;;
+       echo "$timestamp" ; exit ;;
     --version | -v )
-       echo "$version" ; exit 0 ;;
+       echo "$version" ; exit ;;
     --help | --h* | -h )
-       echo "$usage"; exit 0 ;;
+       echo "$usage"; exit ;;
     -- )     # Stop option processing
        shift; break ;;
     - )	# Use stdin as input.
@@ -104,7 +110,7 @@
 trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
 trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
 : ${TMPDIR=/tmp} ;
- { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
  { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
  { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
  { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
@@ -123,7 +129,7 @@
 	;;
  ,,*)   CC_FOR_BUILD=$CC ;;
  ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
-esac ;'
+esac ; set_cc_for_build= ;'
 
 # This is needed to find uname on a Pyramid OSx when run in the BSD universe.
 # (ghazi@noc.rutgers.edu 1994-08-24)
@@ -158,6 +164,7 @@
 	    arm*) machine=arm-unknown ;;
 	    sh3el) machine=shl-unknown ;;
 	    sh3eb) machine=sh-unknown ;;
+	    sh5el) machine=sh5le-unknown ;;
 	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
 	esac
 	# The Operating System including object format, if it has switched
@@ -196,53 +203,32 @@
 	# contains redundant information, the shorter form:
 	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
 	echo "${machine}-${os}${release}"
-	exit 0 ;;
-    amiga:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    arc:OpenBSD:*:*)
-	echo mipsel-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    hp300:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    mac68k:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    macppc:OpenBSD:*:*)
-	echo powerpc-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    mvme68k:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    mvme88k:OpenBSD:*:*)
-	echo m88k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    mvmeppc:OpenBSD:*:*)
-	echo powerpc-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    pegasos:OpenBSD:*:*)
-	echo powerpc-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    pmax:OpenBSD:*:*)
-	echo mipsel-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    sgi:OpenBSD:*:*)
-	echo mipseb-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    sun3:OpenBSD:*:*)
-	echo m68k-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
-    wgrisc:OpenBSD:*:*)
-	echo mipsel-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:OpenBSD:*:*)
-	echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
-	exit 0 ;;
+	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+	exit ;;
+    *:ekkoBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+	exit ;;
+    *:SolidBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+	exit ;;
+    macppc:MirBSD:*:*)
+	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
+    *:MirBSD:*:*)
+	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+	exit ;;
     alpha:OSF1:*:*)
-	if test $UNAME_RELEASE = "V4.0"; then
+	case $UNAME_RELEASE in
+	*4.0)
 		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
-	fi
+		;;
+	*5.*)
+	        UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+		;;
+	esac
 	# According to Compaq, /usr/sbin/psrinfo has been available on
 	# OSF/1 and Tru64 systems produced since 1995.  I hope that
 	# covers most systems running today.  This code pipes the CPU
@@ -280,45 +266,49 @@
 	    "EV7.9 (21364A)")
 		UNAME_MACHINE="alphaev79" ;;
 	esac
+	# A Pn.n version is a patched version.
 	# A Vn.n version is a released version.
 	# A Tn.n version is a released field test version.
 	# A Xn.n version is an unreleased experimental baselevel.
 	# 1.2 uses "1.2" for uname -r.
-	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
-	exit 0 ;;
-    Alpha*:OpenVMS:*:*)
-	echo alpha-hp-vms
-	exit 0 ;;
+	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+	exit ;;
     Alpha\ *:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# Should we change UNAME_MACHINE based on the output of uname instead
 	# of the specific Alpha model?
 	echo alpha-pc-interix
-	exit 0 ;;
+	exit ;;
     21064:Windows_NT:50:3)
 	echo alpha-dec-winnt3.5
-	exit 0 ;;
+	exit ;;
     Amiga*:UNIX_System_V:4.0:*)
 	echo m68k-unknown-sysv4
-	exit 0;;
+	exit ;;
     *:[Aa]miga[Oo][Ss]:*:*)
 	echo ${UNAME_MACHINE}-unknown-amigaos
-	exit 0 ;;
+	exit ;;
     *:[Mm]orph[Oo][Ss]:*:*)
 	echo ${UNAME_MACHINE}-unknown-morphos
-	exit 0 ;;
+	exit ;;
     *:OS/390:*:*)
 	echo i370-ibm-openedition
-	exit 0 ;;
+	exit ;;
+    *:z/VM:*:*)
+	echo s390-ibm-zvmoe
+	exit ;;
     *:OS400:*:*)
         echo powerpc-ibm-os400
-	exit 0 ;;
+	exit ;;
     arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
 	echo arm-acorn-riscix${UNAME_RELEASE}
-	exit 0;;
+	exit ;;
+    arm:riscos:*:*|arm:RISCOS:*:*)
+	echo arm-unknown-riscos
+	exit ;;
     SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
 	echo hppa1.1-hitachi-hiuxmpp
-	exit 0;;
+	exit ;;
     Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
 	# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
 	if test "`(/bin/universe) 2>/dev/null`" = att ; then
@@ -326,32 +316,32 @@
 	else
 		echo pyramid-pyramid-bsd
 	fi
-	exit 0 ;;
+	exit ;;
     NILE*:*:*:dcosx)
 	echo pyramid-pyramid-svr4
-	exit 0 ;;
+	exit ;;
     DRS?6000:unix:4.0:6*)
 	echo sparc-icl-nx6
-	exit 0 ;;
-    DRS?6000:UNIX_SV:4.2*:7*)
+	exit ;;
+    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
 	case `/usr/bin/uname -p` in
-	    sparc) echo sparc-icl-nx7 && exit 0 ;;
+	    sparc) echo sparc-icl-nx7; exit ;;
 	esac ;;
     sun4H:SunOS:5.*:*)
 	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
+	exit ;;
     sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
 	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
+	exit ;;
     i86pc:SunOS:5.*:*)
 	echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
+	exit ;;
     sun4*:SunOS:6*:*)
 	# According to config.sub, this is the proper way to canonicalize
 	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
 	# it's likely to be more like Solaris than SunOS4.
 	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
+	exit ;;
     sun4*:SunOS:*:*)
 	case "`/usr/bin/arch -k`" in
 	    Series*|S4*)
@@ -360,10 +350,10 @@
 	esac
 	# Japanese Language versions have a version number like `4.1.3-JL'.
 	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
-	exit 0 ;;
+	exit ;;
     sun3*:SunOS:*:*)
 	echo m68k-sun-sunos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     sun*:*:4.2BSD:*)
 	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
 	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
@@ -375,10 +365,10 @@
 		echo sparc-sun-sunos${UNAME_RELEASE}
 		;;
 	esac
-	exit 0 ;;
+	exit ;;
     aushp:SunOS:*:*)
 	echo sparc-auspex-sunos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     # The situation for MiNT is a little confusing.  The machine name
     # can be virtually everything (everything which is not
     # "atarist" or "atariste" at least should have a processor
@@ -389,37 +379,40 @@
     # be no problem.
     atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
         echo m68k-atari-mint${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
 	echo m68k-atari-mint${UNAME_RELEASE}
-        exit 0 ;;
+        exit ;;
     *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
         echo m68k-atari-mint${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
         echo m68k-milan-mint${UNAME_RELEASE}
-        exit 0 ;;
+        exit ;;
     hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
         echo m68k-hades-mint${UNAME_RELEASE}
-        exit 0 ;;
+        exit ;;
     *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
         echo m68k-unknown-mint${UNAME_RELEASE}
-        exit 0 ;;
+        exit ;;
+    m68k:machten:*:*)
+	echo m68k-apple-machten${UNAME_RELEASE}
+	exit ;;
     powerpc:machten:*:*)
 	echo powerpc-apple-machten${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     RISC*:Mach:*:*)
 	echo mips-dec-mach_bsd4.3
-	exit 0 ;;
+	exit ;;
     RISC*:ULTRIX:*:*)
 	echo mips-dec-ultrix${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     VAX*:ULTRIX*:*:*)
 	echo vax-dec-ultrix${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     2020:CLIX:*:* | 2430:CLIX:*:*)
 	echo clipper-intergraph-clix${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     mips:*:*:UMIPS | mips:*:*:RISCos)
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
@@ -443,32 +436,33 @@
 	  exit (-1);
 	}
 EOF
-	$CC_FOR_BUILD -o $dummy $dummy.c \
-	  && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \
-	  && exit 0
+	$CC_FOR_BUILD -o $dummy $dummy.c &&
+	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+	  SYSTEM_NAME=`$dummy $dummyarg` &&
+	    { echo "$SYSTEM_NAME"; exit; }
 	echo mips-mips-riscos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     Motorola:PowerMAX_OS:*:*)
 	echo powerpc-motorola-powermax
-	exit 0 ;;
+	exit ;;
     Motorola:*:4.3:PL8-*)
 	echo powerpc-harris-powermax
-	exit 0 ;;
+	exit ;;
     Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
 	echo powerpc-harris-powermax
-	exit 0 ;;
+	exit ;;
     Night_Hawk:Power_UNIX:*:*)
 	echo powerpc-harris-powerunix
-	exit 0 ;;
+	exit ;;
     m88k:CX/UX:7*:*)
 	echo m88k-harris-cxux7
-	exit 0 ;;
+	exit ;;
     m88k:*:4*:R4*)
 	echo m88k-motorola-sysv4
-	exit 0 ;;
+	exit ;;
     m88k:*:3*:R3*)
 	echo m88k-motorola-sysv3
-	exit 0 ;;
+	exit ;;
     AViiON:dgux:*:*)
         # DG/UX returns AViiON for all architectures
         UNAME_PROCESSOR=`/usr/bin/uname -p`
@@ -484,29 +478,29 @@
 	else
 	    echo i586-dg-dgux${UNAME_RELEASE}
 	fi
- 	exit 0 ;;
+ 	exit ;;
     M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
 	echo m88k-dolphin-sysv3
-	exit 0 ;;
+	exit ;;
     M88*:*:R3*:*)
 	# Delta 88k system running SVR3
 	echo m88k-motorola-sysv3
-	exit 0 ;;
+	exit ;;
     XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
 	echo m88k-tektronix-sysv3
-	exit 0 ;;
+	exit ;;
     Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
 	echo m68k-tektronix-bsd
-	exit 0 ;;
+	exit ;;
     *:IRIX*:*:*)
 	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
-	exit 0 ;;
+	exit ;;
     ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
-	echo romp-ibm-aix      # uname -m gives an 8 hex-code CPU id
-	exit 0 ;;              # Note that: echo "'`uname -s`'" gives 'AIX '
+	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
+	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
     i*86:AIX:*:*)
 	echo i386-ibm-aix
-	exit 0 ;;
+	exit ;;
     ia64:AIX:*:*)
 	if [ -x /usr/bin/oslevel ] ; then
 		IBM_REV=`/usr/bin/oslevel`
@@ -514,7 +508,7 @@
 		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
 	fi
 	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
-	exit 0 ;;
+	exit ;;
     *:AIX:2:3)
 	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
 		eval $set_cc_for_build
@@ -529,14 +523,18 @@
 			exit(0);
 			}
 EOF
-		$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
-		echo rs6000-ibm-aix3.2.5
+		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+		then
+			echo "$SYSTEM_NAME"
+		else
+			echo rs6000-ibm-aix3.2.5
+		fi
 	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
 		echo rs6000-ibm-aix3.2.4
 	else
 		echo rs6000-ibm-aix3.2
 	fi
-	exit 0 ;;
+	exit ;;
     *:AIX:*:[45])
 	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
 	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
@@ -550,28 +548,28 @@
 		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
 	fi
 	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
-	exit 0 ;;
+	exit ;;
     *:AIX:*:*)
 	echo rs6000-ibm-aix
-	exit 0 ;;
+	exit ;;
     ibmrt:4.4BSD:*|romp-ibm:BSD:*)
 	echo romp-ibm-bsd4.4
-	exit 0 ;;
+	exit ;;
     ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
 	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
-	exit 0 ;;                           # report: romp-ibm BSD 4.3
+	exit ;;                             # report: romp-ibm BSD 4.3
     *:BOSX:*:*)
 	echo rs6000-bull-bosx
-	exit 0 ;;
+	exit ;;
     DPX/2?00:B.O.S.:*:*)
 	echo m68k-bull-sysv3
-	exit 0 ;;
+	exit ;;
     9000/[34]??:4.3bsd:1.*:*)
 	echo m68k-hp-bsd
-	exit 0 ;;
+	exit ;;
     hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
 	echo m68k-hp-bsd4.4
-	exit 0 ;;
+	exit ;;
     9000/[34678]??:HP-UX:*:*)
 	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
 	case "${UNAME_MACHINE}" in
@@ -633,9 +631,19 @@
 	esac
 	if [ ${HP_ARCH} = "hppa2.0w" ]
 	then
-	    # avoid double evaluation of $set_cc_for_build
-	    test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
-	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E -) | grep __LP64__ >/dev/null
+	    eval $set_cc_for_build
+
+	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
+	    # generating 64-bit code.  GNU and HP use different nomenclature:
+	    #
+	    # $ CC_FOR_BUILD=cc ./config.guess
+	    # => hppa2.0w-hp-hpux11.23
+	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+	    # => hppa64-hp-hpux11.23
+
+	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+		grep __LP64__ >/dev/null
 	    then
 		HP_ARCH="hppa2.0w"
 	    else
@@ -643,11 +651,11 @@
 	    fi
 	fi
 	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
-	exit 0 ;;
+	exit ;;
     ia64:HP-UX:*:*)
 	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
 	echo ia64-hp-hpux${HPUX_REV}
-	exit 0 ;;
+	exit ;;
     3050*:HI-UX:*:*)
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
@@ -675,163 +683,179 @@
 	  exit (0);
 	}
 EOF
-	$CC_FOR_BUILD -o $dummy $dummy.c && $dummy && exit 0
+	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+		{ echo "$SYSTEM_NAME"; exit; }
 	echo unknown-hitachi-hiuxwe2
-	exit 0 ;;
+	exit ;;
     9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
 	echo hppa1.1-hp-bsd
-	exit 0 ;;
+	exit ;;
     9000/8??:4.3bsd:*:*)
 	echo hppa1.0-hp-bsd
-	exit 0 ;;
+	exit ;;
     *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
 	echo hppa1.0-hp-mpeix
-	exit 0 ;;
+	exit ;;
     hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
 	echo hppa1.1-hp-osf
-	exit 0 ;;
+	exit ;;
     hp8??:OSF1:*:*)
 	echo hppa1.0-hp-osf
-	exit 0 ;;
+	exit ;;
     i*86:OSF1:*:*)
 	if [ -x /usr/sbin/sysversion ] ; then
 	    echo ${UNAME_MACHINE}-unknown-osf1mk
 	else
 	    echo ${UNAME_MACHINE}-unknown-osf1
 	fi
-	exit 0 ;;
+	exit ;;
     parisc*:Lites*:*:*)
 	echo hppa1.1-hp-lites
-	exit 0 ;;
+	exit ;;
     C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
 	echo c1-convex-bsd
-        exit 0 ;;
+        exit ;;
     C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
 	if getsysinfo -f scalar_acc
 	then echo c32-convex-bsd
 	else echo c2-convex-bsd
 	fi
-        exit 0 ;;
+        exit ;;
     C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
 	echo c34-convex-bsd
-        exit 0 ;;
+        exit ;;
     C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
 	echo c38-convex-bsd
-        exit 0 ;;
+        exit ;;
     C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
 	echo c4-convex-bsd
-        exit 0 ;;
+        exit ;;
     CRAY*Y-MP:*:*:*)
 	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     CRAY*[A-Z]90:*:*:*)
 	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
 	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
 	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
 	      -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     CRAY*TS:*:*:*)
 	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     CRAY*T3E:*:*:*)
 	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     CRAY*SV1:*:*:*)
 	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	exit ;;
     *:UNICOS/mp:*:*)
-	echo nv1-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
-	exit 0 ;;
+	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+	exit ;;
     F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
 	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
         FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
         FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
         echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
-        exit 0 ;;
+        exit ;;
     5000:UNIX_System_V:4.*:*)
         FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
         FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
         echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
-	exit 0 ;;
+	exit ;;
     i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
 	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     sparc*:BSD/OS:*:*)
 	echo sparc-unknown-bsdi${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:BSD/OS:*:*)
 	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:FreeBSD:*:*)
-	# Determine whether the default compiler uses glibc.
-	eval $set_cc_for_build
-	sed 's/^	//' << EOF >$dummy.c
-	#include <features.h>
-	#if __GLIBC__ >= 2
-	LIBC=gnu
-	#else
-	LIBC=
-	#endif
-EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
-	# GNU/KFreeBSD systems have a "k" prefix to indicate we are using
-	# FreeBSD's kernel, but not the complete OS.
-	case ${LIBC} in gnu) kernel_only='k' ;; esac
-	echo ${UNAME_MACHINE}-unknown-${kernel_only}freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC}
-	exit 0 ;;
+	case ${UNAME_MACHINE} in
+	    pc98)
+		echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    amd64)
+		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	    *)
+		echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+	esac
+	exit ;;
     i*:CYGWIN*:*)
 	echo ${UNAME_MACHINE}-pc-cygwin
-	exit 0 ;;
+	exit ;;
     i*:MINGW*:*)
 	echo ${UNAME_MACHINE}-pc-mingw32
-	exit 0 ;;
+	exit ;;
+    i*:windows32*:*)
+    	# uname -m includes "-pc" on this system.
+    	echo ${UNAME_MACHINE}-mingw32
+	exit ;;
     i*:PW*:*)
 	echo ${UNAME_MACHINE}-pc-pw32
-	exit 0 ;;
-    x86:Interix*:[34]*)
-	echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
-	exit 0 ;;
+	exit ;;
+    x86:Interix*:[3456]*)
+	echo i586-pc-interix${UNAME_RELEASE}
+	exit ;;
+    EM64T:Interix*:[3456]*)
+	echo x86_64-unknown-interix${UNAME_RELEASE}
+	exit ;;
     [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
 	echo i${UNAME_MACHINE}-pc-mks
-	exit 0 ;;
+	exit ;;
     i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
 	# How do we know it's Interix rather than the generic POSIX subsystem?
 	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
 	# UNAME_MACHINE based on the output of uname instead of i386?
 	echo i586-pc-interix
-	exit 0 ;;
+	exit ;;
     i*:UWIN*:*)
 	echo ${UNAME_MACHINE}-pc-uwin
-	exit 0 ;;
+	exit ;;
+    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+	echo x86_64-unknown-cygwin
+	exit ;;
     p*:CYGWIN*:*)
 	echo powerpcle-unknown-cygwin
-	exit 0 ;;
+	exit ;;
     prep*:SunOS:5.*:*)
 	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
-	exit 0 ;;
+	exit ;;
     *:GNU:*:*)
 	# the GNU system
 	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
-	exit 0 ;;
+	exit ;;
     *:GNU/*:*:*)
 	# other systems with GNU libc and userland
 	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
-	exit 0 ;;
+	exit ;;
     i*86:Minix:*:*)
 	echo ${UNAME_MACHINE}-pc-minix
-	exit 0 ;;
+	exit ;;
     arm*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
+    avr32*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
     cris:Linux:*:*)
 	echo cris-axis-linux-gnu
-	exit 0 ;;
+	exit ;;
+    crisv32:Linux:*:*)
+	echo crisv32-axis-linux-gnu
+	exit ;;
+    frv:Linux:*:*)
+    	echo frv-unknown-linux-gnu
+	exit ;;
     ia64:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
+    m32r*:Linux:*:*)
+	echo ${UNAME_MACHINE}-unknown-linux-gnu
+	exit ;;
     m68*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     mips:Linux:*:*)
 	eval $set_cc_for_build
 	sed 's/^	//' << EOF >$dummy.c
@@ -848,8 +872,12 @@
 	#endif
 	#endif
 EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
-	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^CPU/{
+		s: ::g
+		p
+	    }'`"
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
 	;;
     mips64:Linux:*:*)
 	eval $set_cc_for_build
@@ -867,15 +895,22 @@
 	#endif
 	#endif
 EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
-	test x"${CPU}" != x && echo "${CPU}-unknown-linux-gnu" && exit 0
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^CPU/{
+		s: ::g
+		p
+	    }'`"
+	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
 	;;
+    or32:Linux:*:*)
+	echo or32-unknown-linux-gnu
+	exit ;;
     ppc:Linux:*:*)
 	echo powerpc-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     ppc64:Linux:*:*)
 	echo powerpc64-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     alpha:Linux:*:*)
 	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
 	  EV5)   UNAME_MACHINE=alphaev5 ;;
@@ -889,7 +924,7 @@
 	objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
 	if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
 	echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
-	exit 0 ;;
+	exit ;;
     parisc:Linux:*:* | hppa:Linux:*:*)
 	# Look for CPU level
 	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
@@ -897,25 +932,28 @@
 	  PA8*) echo hppa2.0-unknown-linux-gnu ;;
 	  *)    echo hppa-unknown-linux-gnu ;;
 	esac
-	exit 0 ;;
+	exit ;;
     parisc64:Linux:*:* | hppa64:Linux:*:*)
 	echo hppa64-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     s390:Linux:*:* | s390x:Linux:*:*)
 	echo ${UNAME_MACHINE}-ibm-linux
-	exit 0 ;;
+	exit ;;
     sh64*:Linux:*:*)
     	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     sh*:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     sparc:Linux:*:* | sparc64:Linux:*:*)
 	echo ${UNAME_MACHINE}-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
+    vax:Linux:*:*)
+	echo ${UNAME_MACHINE}-dec-linux-gnu
+	exit ;;
     x86_64:Linux:*:*)
 	echo x86_64-unknown-linux-gnu
-	exit 0 ;;
+	exit ;;
     i*86:Linux:*:*)
 	# The BFD linker knows what the default object file format is, so
 	# first see if it will tell us. cd to the root directory to prevent
@@ -933,15 +971,15 @@
 		;;
 	  a.out-i386-linux)
 		echo "${UNAME_MACHINE}-pc-linux-gnuaout"
-		exit 0 ;;
+		exit ;;
 	  coff-i386)
 		echo "${UNAME_MACHINE}-pc-linux-gnucoff"
-		exit 0 ;;
+		exit ;;
 	  "")
 		# Either a pre-BFD a.out linker (linux-gnuoldld) or
 		# one that does not give us useful --help.
 		echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
-		exit 0 ;;
+		exit ;;
 	esac
 	# Determine whether the default compiler is a.out or elf
 	eval $set_cc_for_build
@@ -958,7 +996,7 @@
 	LIBC=gnulibc1
 	# endif
 	#else
-	#ifdef __INTEL_COMPILER
+	#if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
 	LIBC=gnu
 	#else
 	LIBC=gnuaout
@@ -968,16 +1006,23 @@
 	LIBC=dietlibc
 	#endif
 EOF
-	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
-	test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0
-	test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0
+	eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
+	    /^LIBC/{
+		s: ::g
+		p
+	    }'`"
+	test x"${LIBC}" != x && {
+		echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
+		exit
+	}
+	test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
 	;;
     i*86:DYNIX/ptx:4*:*)
 	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
 	# earlier versions are messed up and put the nodename in both
 	# sysname and nodename.
 	echo i386-sequent-sysv4
-	exit 0 ;;
+	exit ;;
     i*86:UNIX_SV:4.2MP:2.*)
         # Unixware is an offshoot of SVR4, but it has its own version
         # number series starting with 2...
@@ -985,27 +1030,27 @@
 	# I just have to hope.  -- rms.
         # Use sysv4.2uw... so that sysv4* matches it.
 	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
-	exit 0 ;;
+	exit ;;
     i*86:OS/2:*:*)
 	# If we were able to find `uname', then EMX Unix compatibility
 	# is probably installed.
 	echo ${UNAME_MACHINE}-pc-os2-emx
-	exit 0 ;;
+	exit ;;
     i*86:XTS-300:*:STOP)
 	echo ${UNAME_MACHINE}-unknown-stop
-	exit 0 ;;
+	exit ;;
     i*86:atheos:*:*)
 	echo ${UNAME_MACHINE}-unknown-atheos
-	exit 0 ;;
-	i*86:syllable:*:*)
+	exit ;;
+    i*86:syllable:*:*)
 	echo ${UNAME_MACHINE}-pc-syllable
-	exit 0 ;;
+	exit ;;
     i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
 	echo i386-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     i*86:*DOS:*:*)
 	echo ${UNAME_MACHINE}-pc-msdosdjgpp
-	exit 0 ;;
+	exit ;;
     i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
 	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
 	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
@@ -1013,15 +1058,16 @@
 	else
 		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
 	fi
-	exit 0 ;;
-    i*86:*:5:[78]*)
+	exit ;;
+    i*86:*:5:[678]*)
+    	# UnixWare 7.x, OpenUNIX and OpenServer 6.
 	case `/bin/uname -X | grep "^Machine"` in
 	    *486*)	     UNAME_MACHINE=i486 ;;
 	    *Pentium)	     UNAME_MACHINE=i586 ;;
 	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
 	esac
 	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
-	exit 0 ;;
+	exit ;;
     i*86:*:3.2:*)
 	if test -f /usr/options/cb.name; then
 		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
@@ -1039,73 +1085,73 @@
 	else
 		echo ${UNAME_MACHINE}-pc-sysv32
 	fi
-	exit 0 ;;
+	exit ;;
     pc:*:*:*)
 	# Left here for compatibility:
         # uname -m prints for DJGPP always 'pc', but it prints nothing about
         # the processor, so we play safe by assuming i386.
 	echo i386-pc-msdosdjgpp
-        exit 0 ;;
+        exit ;;
     Intel:Mach:3*:*)
 	echo i386-pc-mach3
-	exit 0 ;;
+	exit ;;
     paragon:*:*:*)
 	echo i860-intel-osf1
-	exit 0 ;;
+	exit ;;
     i860:*:4.*:*) # i860-SVR4
 	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
 	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
 	else # Add other i860-SVR4 vendors below as they are discovered.
 	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
 	fi
-	exit 0 ;;
+	exit ;;
     mini*:CTIX:SYS*5:*)
 	# "miniframe"
 	echo m68010-convergent-sysv
-	exit 0 ;;
+	exit ;;
     mc68k:UNIX:SYSTEM5:3.51m)
 	echo m68k-convergent-sysv
-	exit 0 ;;
+	exit ;;
     M680?0:D-NIX:5.3:*)
 	echo m68k-diab-dnix
-	exit 0 ;;
-    M68*:*:R3V[567]*:*)
-	test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;;
-    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0)
+	exit ;;
+    M68*:*:R3V[5678]*:*)
+	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
+    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
 	OS_REL=''
 	test -r /etc/.relid \
 	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
 	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-	  && echo i486-ncr-sysv4.3${OS_REL} && exit 0
+	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
 	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
-	  && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;;
+	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
     3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
         /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
-          && echo i486-ncr-sysv4 && exit 0 ;;
+          && { echo i486-ncr-sysv4; exit; } ;;
     m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
 	echo m68k-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     mc68030:UNIX_System_V:4.*:*)
 	echo m68k-atari-sysv4
-	exit 0 ;;
+	exit ;;
     TSUNAMI:LynxOS:2.*:*)
 	echo sparc-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     rs6000:LynxOS:2.*:*)
 	echo rs6000-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
 	echo powerpc-unknown-lynxos${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     SM[BE]S:UNIX_SV:*:*)
 	echo mips-dde-sysv${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     RM*:ReliantUNIX-*:*:*)
 	echo mips-sni-sysv4
-	exit 0 ;;
+	exit ;;
     RM*:SINIX-*:*:*)
 	echo mips-sni-sysv4
-	exit 0 ;;
+	exit ;;
     *:SINIX-*:*:*)
 	if uname -p 2>/dev/null >/dev/null ; then
 		UNAME_MACHINE=`(uname -p) 2>/dev/null`
@@ -1113,68 +1159,72 @@
 	else
 		echo ns32k-sni-sysv
 	fi
-	exit 0 ;;
+	exit ;;
     PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
                       # says <Richard.M.Bartel@ccMail.Census.GOV>
         echo i586-unisys-sysv4
-        exit 0 ;;
+        exit ;;
     *:UNIX_System_V:4*:FTX*)
 	# From Gerald Hewes <hewes@openmarket.com>.
 	# How about differentiating between stratus architectures? -djm
 	echo hppa1.1-stratus-sysv4
-	exit 0 ;;
+	exit ;;
     *:*:*:FTX*)
 	# From seanf@swdc.stratus.com.
 	echo i860-stratus-sysv4
-	exit 0 ;;
+	exit ;;
+    i*86:VOS:*:*)
+	# From Paul.Green@stratus.com.
+	echo ${UNAME_MACHINE}-stratus-vos
+	exit ;;
     *:VOS:*:*)
 	# From Paul.Green@stratus.com.
 	echo hppa1.1-stratus-vos
-	exit 0 ;;
+	exit ;;
     mc68*:A/UX:*:*)
 	echo m68k-apple-aux${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     news*:NEWS-OS:6*:*)
 	echo mips-sony-newsos6
-	exit 0 ;;
+	exit ;;
     R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
 	if [ -d /usr/nec ]; then
 	        echo mips-nec-sysv${UNAME_RELEASE}
 	else
 	        echo mips-unknown-sysv${UNAME_RELEASE}
 	fi
-        exit 0 ;;
+        exit ;;
     BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
 	echo powerpc-be-beos
-	exit 0 ;;
+	exit ;;
     BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
 	echo powerpc-apple-beos
-	exit 0 ;;
+	exit ;;
     BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
 	echo i586-pc-beos
-	exit 0 ;;
+	exit ;;
     SX-4:SUPER-UX:*:*)
 	echo sx4-nec-superux${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     SX-5:SUPER-UX:*:*)
 	echo sx5-nec-superux${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     SX-6:SUPER-UX:*:*)
 	echo sx6-nec-superux${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     Power*:Rhapsody:*:*)
 	echo powerpc-apple-rhapsody${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:Rhapsody:*:*)
 	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:Darwin:*:*)
-	case `uname -p` in
-	    *86) UNAME_PROCESSOR=i686 ;;
-	    powerpc) UNAME_PROCESSOR=powerpc ;;
+	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+	case $UNAME_PROCESSOR in
+	    unknown) UNAME_PROCESSOR=powerpc ;;
 	esac
 	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:procnto*:*:* | *:QNX:[0123456789]*:*)
 	UNAME_PROCESSOR=`uname -p`
 	if test "$UNAME_PROCESSOR" = "x86"; then
@@ -1182,22 +1232,25 @@
 		UNAME_MACHINE=pc
 	fi
 	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:QNX:*:4*)
 	echo i386-pc-qnx
-	exit 0 ;;
-    NSR-[DGKLNPTVWY]:NONSTOP_KERNEL:*:*)
+	exit ;;
+    NSE-?:NONSTOP_KERNEL:*:*)
+	echo nse-tandem-nsk${UNAME_RELEASE}
+	exit ;;
+    NSR-?:NONSTOP_KERNEL:*:*)
 	echo nsr-tandem-nsk${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:NonStop-UX:*:*)
 	echo mips-compaq-nonstopux
-	exit 0 ;;
+	exit ;;
     BS2000:POSIX*:*:*)
 	echo bs2000-siemens-sysv
-	exit 0 ;;
+	exit ;;
     DS/*:UNIX_System_V:*:*)
 	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
     *:Plan9:*:*)
 	# "uname -m" is not consistent, so use $cputype instead. 386
 	# is converted to i386 for consistency with other x86
@@ -1208,31 +1261,47 @@
 	    UNAME_MACHINE="$cputype"
 	fi
 	echo ${UNAME_MACHINE}-unknown-plan9
-	exit 0 ;;
+	exit ;;
     *:TOPS-10:*:*)
 	echo pdp10-unknown-tops10
-	exit 0 ;;
+	exit ;;
     *:TENEX:*:*)
 	echo pdp10-unknown-tenex
-	exit 0 ;;
+	exit ;;
     KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
 	echo pdp10-dec-tops20
-	exit 0 ;;
+	exit ;;
     XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
 	echo pdp10-xkl-tops20
-	exit 0 ;;
+	exit ;;
     *:TOPS-20:*:*)
 	echo pdp10-unknown-tops20
-	exit 0 ;;
+	exit ;;
     *:ITS:*:*)
 	echo pdp10-unknown-its
-	exit 0 ;;
+	exit ;;
     SEI:*:*:SEIUX)
         echo mips-sei-seiux${UNAME_RELEASE}
-	exit 0 ;;
-    *:DRAGONFLY:*:*)
-	echo ${UNAME_MACHINE}-unknown-dragonfly${UNAME_RELEASE}
-	exit 0 ;;
+	exit ;;
+    *:DragonFly:*:*)
+	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+	exit ;;
+    *:*VMS:*:*)
+    	UNAME_MACHINE=`(uname -p) 2>/dev/null`
+	case "${UNAME_MACHINE}" in
+	    A*) echo alpha-dec-vms ; exit ;;
+	    I*) echo ia64-dec-vms ; exit ;;
+	    V*) echo vax-dec-vms ; exit ;;
+	esac ;;
+    *:XENIX:*:SysV)
+	echo i386-pc-xenix
+	exit ;;
+    i*86:skyos:*:*)
+	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+	exit ;;
+    i*86:rdos:*:*)
+	echo ${UNAME_MACHINE}-pc-rdos
+	exit ;;
 esac
 
 #echo '(No uname command or uname output not recognized.)' 1>&2
@@ -1264,7 +1333,7 @@
 #endif
 
 #if defined (__arm) && defined (__acorn) && defined (__unix)
-  printf ("arm-acorn-riscix"); exit (0);
+  printf ("arm-acorn-riscix\n"); exit (0);
 #endif
 
 #if defined (hp300) && !defined (hpux)
@@ -1353,11 +1422,12 @@
 }
 EOF
 
-$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && exit 0
+$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
+	{ echo "$SYSTEM_NAME"; exit; }
 
 # Apollos put the system type in the environment.
 
-test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; }
+test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
 
 # Convex versions that predate uname can use getsysinfo(1)
 
@@ -1366,22 +1436,22 @@
     case `getsysinfo -f cpu_type` in
     c1*)
 	echo c1-convex-bsd
-	exit 0 ;;
+	exit ;;
     c2*)
 	if getsysinfo -f scalar_acc
 	then echo c32-convex-bsd
 	else echo c2-convex-bsd
 	fi
-	exit 0 ;;
+	exit ;;
     c34*)
 	echo c34-convex-bsd
-	exit 0 ;;
+	exit ;;
     c38*)
 	echo c38-convex-bsd
-	exit 0 ;;
+	exit ;;
     c4*)
 	echo c4-convex-bsd
-	exit 0 ;;
+	exit ;;
     esac
 fi
 
@@ -1392,7 +1462,9 @@
 the operating system you are using. It is advised that you
 download the most up to date version of the config scripts from
 
-    ftp://ftp.gnu.org/pub/gnu/config/
+  http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess
+and
+  http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub
 
 If the version you run ($0) is already up to date, please
 send the following data and any information you think might be
diff --git a/config.sub b/config.sub
index fac5195..5b2ab48 100755
--- a/config.sub
+++ b/config.sub
@@ -1,9 +1,13 @@
 #! /bin/sh
+#
+# $NetBSD: config.sub,v 1.8 2006/10/29 23:52:55 wiz Exp $
+#
 # Configuration validation subroutine script.
 #   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-#   2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+#   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
+#   Inc.
 
-timestamp='2003-11-20'
+timestamp='2006-09-20'
 
 # This file is (in principle) common to ALL GNU software.
 # The presence of a machine in this file suggests that SOME GNU software
@@ -21,14 +25,15 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # configuration script generated by Autoconf, you may include it under
 # the same distribution terms that you use for the rest of that program.
 
+
 # Please send patches to <config-patches@gnu.org>.  Submit a context
 # diff and a properly formatted ChangeLog entry.
 #
@@ -70,7 +75,7 @@
 version="\
 GNU config.sub ($timestamp)
 
-Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
 Free Software Foundation, Inc.
 
 This is free software; see the source for copying conditions.  There is NO
@@ -83,11 +88,11 @@
 while test $# -gt 0 ; do
   case $1 in
     --time-stamp | --time* | -t )
-       echo "$timestamp" ; exit 0 ;;
+       echo "$timestamp" ; exit ;;
     --version | -v )
-       echo "$version" ; exit 0 ;;
+       echo "$version" ; exit ;;
     --help | --h* | -h )
-       echo "$usage"; exit 0 ;;
+       echo "$usage"; exit ;;
     -- )     # Stop option processing
        shift; break ;;
     - )	# Use stdin as input.
@@ -99,7 +104,7 @@
     *local*)
        # First pass through any local machine types.
        echo $1
-       exit 0;;
+       exit ;;
 
     * )
        break ;;
@@ -118,8 +123,9 @@
 # Here we must recognize all the valid KERNEL-OS combinations.
 maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
 case $maybe_os in
-  nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \
-  kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*)
+  nto-qnx* | linux-gnu* | linux-dietlibc | linux-newlib* | linux-uclibc* | \
+  uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | \
+  storm-chaos* | os2-emx* | rtmk-nova*)
     os=-$maybe_os
     basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
     ;;
@@ -145,7 +151,7 @@
 	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
 	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
 	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
-	-apple | -axis)
+	-apple | -axis | -knuth | -cray)
 		os=
 		basic_machine=$1
 		;;
@@ -170,6 +176,10 @@
 	-hiux*)
 		os=-hiuxwe2
 		;;
+	-sco6)
+		os=-sco5v6
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
 	-sco5)
 		os=-sco3.2v5
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
@@ -186,6 +196,10 @@
 		# Don't forget version if it is 3.2v4 or newer.
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
 		;;
+	-sco5v6*)
+		# Don't forget version if it is 3.2v4 or newer.
+		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+		;;
 	-sco*)
 		os=-sco3.2v2
 		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
@@ -230,14 +244,16 @@
 	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
 	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
 	| am33_2.0 \
-	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \
+	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
+	| bfin \
 	| c4x | clipper \
 	| d10v | d30v | dlx | dsp16xx \
 	| fr30 | frv \
 	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
 	| i370 | i860 | i960 | ia64 \
 	| ip2k | iq2000 \
-	| m32r | m68000 | m68k | m88k | mcore \
+	| m32c | m32r | m32rle | m68000 | m68k | m88k \
+	| maxq | mb | microblaze | mcore \
 	| mips | mipsbe | mipseb | mipsel | mipsle \
 	| mips16 \
 	| mips64 | mips64el \
@@ -246,6 +262,7 @@
 	| mips64vr4100 | mips64vr4100el \
 	| mips64vr4300 | mips64vr4300el \
 	| mips64vr5000 | mips64vr5000el \
+	| mips64vr5900 | mips64vr5900el \
 	| mipsisa32 | mipsisa32el \
 	| mipsisa32r2 | mipsisa32r2el \
 	| mipsisa64 | mipsisa64el \
@@ -254,20 +271,24 @@
 	| mipsisa64sr71k | mipsisa64sr71kel \
 	| mipstx39 | mipstx39el \
 	| mn10200 | mn10300 \
+	| mt \
 	| msp430 \
+	| nios | nios2 \
 	| ns16k | ns32k \
-	| openrisc | or32 \
+	| or32 \
 	| pdp10 | pdp11 | pj | pjl \
 	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
 	| pyramid \
-	| sh | sh[1234] | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \
+	| score \
+	| sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
 	| sh64 | sh64le \
-	| sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \
-	| strongarm \
+	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+	| spu | strongarm \
 	| tahoe | thumb | tic4x | tic80 | tron \
 	| v850 | v850e \
 	| we32k \
-	| x86 | xscale | xstormy16 | xtensa \
+	| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
 	| z8k)
 		basic_machine=$basic_machine-unknown
 		;;
@@ -278,6 +299,9 @@
 		;;
 	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
 		;;
+	ms1)
+		basic_machine=mt-unknown
+		;;
 
 	# We use `pc' rather than `unknown'
 	# because (1) that's what they normally are, and
@@ -297,10 +321,10 @@
 	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
 	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
 	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
-	| avr-* \
-	| bs2000-* \
+	| avr-* | avr32-* \
+	| bfin-* | bs2000-* \
 	| c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \
-	| clipper-* | cydra-* \
+	| clipper-* | craynv-* | cydra-* \
 	| d10v-* | d30v-* | dlx-* \
 	| elxsi-* \
 	| f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \
@@ -308,9 +332,9 @@
 	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
 	| i*86-* | i860-* | i960-* | ia64-* \
 	| ip2k-* | iq2000-* \
-	| m32r-* \
+	| m32c-* | m32r-* | m32rle-* \
 	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
-	| m88110-* | m88k-* | mcore-* \
+	| m88110-* | m88k-* | maxq-* | mcore-* \
 	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
 	| mips16-* \
 	| mips64-* | mips64el-* \
@@ -319,6 +343,7 @@
 	| mips64vr4100-* | mips64vr4100el-* \
 	| mips64vr4300-* | mips64vr4300el-* \
 	| mips64vr5000-* | mips64vr5000el-* \
+	| mips64vr5900-* | mips64vr5900el-* \
 	| mipsisa32-* | mipsisa32el-* \
 	| mipsisa32r2-* | mipsisa32r2el-* \
 	| mipsisa64-* | mipsisa64el-* \
@@ -326,24 +351,28 @@
 	| mipsisa64sb1-* | mipsisa64sb1el-* \
 	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
 	| mipstx39-* | mipstx39el-* \
+	| mmix-* \
+	| mt-* \
 	| msp430-* \
-	| none-* | np1-* | nv1-* | ns16k-* | ns32k-* \
+	| nios-* | nios2-* \
+	| none-* | np1-* | ns16k-* | ns32k-* \
 	| orion-* \
 	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
 	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
 	| pyramid-* \
 	| romp-* | rs6000-* \
-	| sh-* | sh[1234]-* | sh[23]e-* | sh[34]eb-* | shbe-* \
+	| sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
 	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
-	| sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \
-	| sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \
+	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+	| sparclite-* \
+	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
 	| tahoe-* | thumb-* \
 	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
 	| tron-* \
 	| v850-* | v850e-* | vax-* \
 	| we32k-* \
-	| x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \
-	| xtensa-* \
+	| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
+	| xstormy16-* | xtensa-* \
 	| ymp-* \
 	| z8k-*)
 		;;
@@ -363,6 +392,9 @@
 		basic_machine=a29k-amd
 		os=-udi
 		;;
+    	abacus)
+		basic_machine=abacus-unknown
+		;;
 	adobe68k)
 		basic_machine=m68010-adobe
 		os=-scout
@@ -380,6 +412,9 @@
 	amd64)
 		basic_machine=x86_64-pc
 		;;
+	amd64-*)
+		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
 	amdahl)
 		basic_machine=580-amdahl
 		os=-sysv
@@ -439,12 +474,27 @@
 		basic_machine=j90-cray
 		os=-unicos
 		;;
+	craynv)
+		basic_machine=craynv-cray
+		os=-unicosmp
+		;;
+	cr16c)
+		basic_machine=cr16c-unknown
+		os=-elf
+		;;
 	crds | unos)
 		basic_machine=m68k-crds
 		;;
+	crisv32 | crisv32-* | etraxfs*)
+		basic_machine=crisv32-axis
+		;;
 	cris | cris-* | etrax*)
 		basic_machine=cris-axis
 		;;
+	crx)
+		basic_machine=crx-unknown
+		os=-elf
+		;;
 	da30 | da30-*)
 		basic_machine=m68k-da30
 		;;
@@ -467,6 +517,10 @@
 		basic_machine=m88k-motorola
 		os=-sysv3
 		;;
+	djgpp)
+		basic_machine=i586-pc
+		os=-msdosdjgpp
+		;;
 	dpx20 | dpx20-*)
 		basic_machine=rs6000-bull
 		os=-bosx
@@ -645,10 +699,6 @@
 	mips3*)
 		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
 		;;
-	mmix*)
-		basic_machine=mmix-knuth
-		os=-mmixware
-		;;
 	monitor)
 		basic_machine=m68k-rom68k
 		os=-coff
@@ -661,6 +711,9 @@
 		basic_machine=i386-pc
 		os=-msdos
 		;;
+	ms1-*)
+		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+		;;
 	mvs)
 		basic_machine=i370-ibm
 		os=-mvs
@@ -729,10 +782,6 @@
 	np1)
 		basic_machine=np1-gould
 		;;
-	nv1)
-		basic_machine=nv1-cray
-		os=-unicosmp
-		;;
 	nsr-tandem)
 		basic_machine=nsr-tandem
 		;;
@@ -740,9 +789,8 @@
 		basic_machine=hppa1.1-oki
 		os=-proelf
 		;;
-	or32 | or32-*)
+	openrisc | openrisc-*)
 		basic_machine=or32-unknown
-		os=-coff
 		;;
 	os400)
 		basic_machine=powerpc-ibm
@@ -773,6 +821,12 @@
 	pc532 | pc532-*)
 		basic_machine=ns32k-pc532
 		;;
+	pc98)
+		basic_machine=i386-pc
+		;;
+	pc98-*)
+		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+		;;
 	pentium | p5 | k5 | k6 | nexgen | viac3)
 		basic_machine=i586-pc
 		;;
@@ -829,6 +883,10 @@
 		basic_machine=i586-unknown
 		os=-pw32
 		;;
+	rdos)
+		basic_machine=i386-pc
+		os=-rdos
+		;;
 	rom68k)
 		basic_machine=m68k-rom68k
 		os=-coff
@@ -855,6 +913,10 @@
 	sb1el)
 		basic_machine=mipsisa64sb1el-unknown
 		;;
+	sde)
+		basic_machine=mipsisa32-sde
+		os=-elf
+		;;
 	sei)
 		basic_machine=mips-sei
 		os=-seiux
@@ -866,6 +928,9 @@
 		basic_machine=sh-hitachi
 		os=-hms
 		;;
+	sh5el)
+		basic_machine=sh5le-unknown
+		;;
 	sh64)
 		basic_machine=sh64-unknown
 		;;
@@ -1015,6 +1080,10 @@
 		basic_machine=hppa1.1-winbond
 		os=-proelf
 		;;
+	xbox)
+		basic_machine=i686-pc
+		os=-mingw32
+		;;
 	xps | xps100)
 		basic_machine=xps100-honeywell
 		;;
@@ -1045,6 +1114,9 @@
 	romp)
 		basic_machine=romp-ibm
 		;;
+	mmix)
+		basic_machine=mmix-knuth
+		;;
 	rs6000)
 		basic_machine=rs6000-ibm
 		;;
@@ -1061,13 +1133,10 @@
 	we32k)
 		basic_machine=we32k-att
 		;;
-	sh3 | sh4 | sh[34]eb | sh[1234]le | sh[23]ele)
+	sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele)
 		basic_machine=sh-unknown
 		;;
-	sh64)
-		basic_machine=sh64-unknown
-		;;
-	sparc | sparcv9 | sparcv9b)
+	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
 		basic_machine=sparc-sun
 		;;
 	cydra)
@@ -1140,19 +1209,23 @@
 	      | -aos* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
-	      | -hiux* | -386bsd* | -knetbsd* | -netbsd* | -openbsd* | -kfreebsd* | -freebsd* | -riscix* \
-	      | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+	      | -openbsd* | -solidbsd* \
+	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
 	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
 	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
 	      | -chorusos* | -chorusrdb* \
 	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
-	      | -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \
+	      | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \
+	      | -uxpv* | -beos* | -mpeix* | -udk* \
 	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
 	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
 	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
 	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
 	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
-	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly*)
+	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+	      | -skyos* | -haiku* | -rdos* | -toppers*)
 	# Remember, each alternative MUST END IN *, to match a version number.
 		;;
 	-qnx*)
@@ -1170,7 +1243,7 @@
 		os=`echo $os | sed -e 's|nto|nto-qnx|'`
 		;;
 	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
-	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* \
+	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
 	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
 		;;
 	-mac*)
@@ -1279,6 +1352,9 @@
 	-kaos*)
 		os=-kaos
 		;;
+	-zvmoe)
+		os=-zvmoe
+		;;
 	-none)
 		;;
 	*)
@@ -1301,6 +1377,12 @@
 # system, and we'll never get to this point.
 
 case $basic_machine in
+        score-*)
+		os=-elf
+		;;
+        spu-*)
+		os=-elf
+		;;
 	*-acorn)
 		os=-riscix1.2
 		;;
@@ -1310,9 +1392,9 @@
 	arm*-semi)
 		os=-aout
 		;;
-    c4x-* | tic4x-*)
-        os=-coff
-        ;;
+        c4x-* | tic4x-*)
+        	os=-coff
+		;;
 	# This must come before the *-dec entry.
 	pdp10-*)
 		os=-tops20
@@ -1356,9 +1438,15 @@
 	*-be)
 		os=-beos
 		;;
+	*-haiku)
+		os=-haiku
+		;;
 	*-ibm)
 		os=-aix
 		;;
+    	*-knuth)
+		os=-mmixware
+		;;
 	*-wec)
 		os=-proelf
 		;;
@@ -1524,7 +1612,7 @@
 esac
 
 echo $basic_machine$os
-exit 0
+exit
 
 # Local variables:
 # eval: (add-hook 'write-file-hooks 'time-stamp)
diff --git a/configure.ac b/configure.ac
index 7f4f669..3b3b442 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,18 +1,13 @@
 AC_PREREQ(2.57)
-AC_INIT([libzip],[0.5a],[nih@giga.or.at])
+AC_INIT([libzip],[0.7.1b],[libzip@nih.at])
 AC_CONFIG_SRCDIR([lib/zip_add.c])
 AC_CONFIG_HEADERS([config.h])
 AM_INIT_AUTOMAKE
 
 dnl AC_CANONICAL_HOST
 
-# We want these before the checks, so the checks can modify their values.
-dnl test -z "$CFLAGS" && CFLAGS='-Wall -g' auto_cflags=1
-
-
 AC_PROG_CC
-AC_PROG_RANLIB
-
+AM_PROG_CC_C_O
 
 AC_ARG_WITH(zlib,
     [  --with-zlib=PREFIX  specify prefix for ZLIB library],,
@@ -42,40 +37,21 @@
     AC_MSG_ERROR([ZLIB version too old, please install at least v1.1.2])
 fi
 
-dnl case $host_os
-dnl in
-dnl 	*bsd*) MANFMT=mdoc;;
-dnl 	*) MANFMT=man;;
-dnl esac
-
 AC_EXEEXT
 
-dnl AM_DISABLE_STATIC
 AM_PROG_LIBTOOL
 
+AC_CHECK_FUNCS([fseeko ftello MoveFileEx])
+AC_CHECK_FUNCS([mkstemp], [], [AC_LIBOBJ(mkstemp)])
+
+AC_CHECK_HEADERS([unistd.h])
+
 case $host_os
 in
     *bsd*) MANFMT=mdoc;;
     *) MANFMT=man;;
 esac
-
-AC_CONFIG_LINKS([man/zipcmp.1:man/zipcmp.${MANFMT}
-		 man/zip_close.3:man/zip_close.${MANFMT}
-		 man/zip_delete.3:man/zip_delete.${MANFMT}
-		 man/zip_error_str.3:man/zip_error_str.${MANFMT}
-		 man/zip_fclose.3:man/zip_fclose.${MANFMT}
-		 man/zip_file_strerror.3:man/zip_file_strerror.${MANFMT}
-		 man/zip_fopen.3:man/zip_fopen.${MANFMT}
-		 man/zip_fread.3:man/zip_fread.${MANFMT}
-		 man/zip_get_name.3:man/zip_get_name.${MANFMT}
-		 man/zip_get_num_files.3:man/zip_get_num_files.${MANFMT}
-		 man/zip_name_locate.3:man/zip_name_locate.${MANFMT}
-		 man/zip_open.3:man/zip_open.${MANFMT}
-		 man/zip_rename.3:man/zip_rename.${MANFMT}
-		 man/zip_stat.3:man/zip_stat.${MANFMT}
-		 man/zip_strerror.3:man/zip_strerror.${MANFMT}
-		 man/zip_unchange.3:man/zip_unchange.${MANFMT}
-		 man/zip_unchange_all.3:man/zip_unchange_all.${MANFMT}])
+AC_SUBST([MANFMT])
 
 AC_CONFIG_FILES([Makefile
 		 libzip.pc
diff --git a/depcomp b/depcomp
index 9e5522d..ca5ea4e 100755
--- a/depcomp
+++ b/depcomp
@@ -1,9 +1,10 @@
 #! /bin/sh
 # depcomp - compile a program generating dependencies as side-effects
 
-scriptversion=2003-11-08.23
+scriptversion=2006-10-15.18
 
-# Copyright (C) 1999, 2000, 2003 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2006 Free Software
+# Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,8 +18,8 @@
 
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -43,17 +44,18 @@
   depmode     Dependency tracking mode.
   source      Source file read by `PROGRAMS ARGS'.
   object      Object file output by `PROGRAMS ARGS'.
+  DEPDIR      directory where to store dependencies.
   depfile     Dependency file to output.
   tmpdepfile  Temporary file to use when outputing dependencies.
   libtool     Whether libtool is used (yes/no).
 
 Report bugs to <bug-automake@gnu.org>.
 EOF
-    exit 0
+    exit $?
     ;;
   -v | --v*)
     echo "depcomp $scriptversion"
-    exit 0
+    exit $?
     ;;
 esac
 
@@ -61,18 +63,10 @@
   echo "depcomp: Variables source, object and depmode must be set" 1>&2
   exit 1
 fi
-# `libtool' can also be set to `yes' or `no'.
 
-if test -z "$depfile"; then
-   base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'`
-   dir=`echo "$object" | sed 's,/.*$,/,'`
-   if test "$dir" = "$object"; then
-      dir=
-   fi
-   # FIXME: should be _deps on DOS.
-   depfile="$dir.deps/$base"
-fi
-
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
+depfile=${depfile-`echo "$object" |
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
 tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
 
 rm -f "$tmpdepfile"
@@ -98,7 +92,20 @@
 ## gcc 3 implements dependency tracking that does exactly what
 ## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
 ## it if -MD -MP comes after the -MF stuff.  Hmm.
-  "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
+## Unfortunately, FreeBSD c89 acceptance of flags depends upon
+## the command line argument order; so add the flags where they
+## appear in depend2.am.  Note that the slowdown incurred here
+## affects only configure: in makefiles, %FASTDEP% shortcuts this.
+  for arg
+  do
+    case $arg in
+    -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
+    *)  set fnord "$@" "$arg" ;;
+    esac
+    shift # fnord
+    shift # $arg
+  done
+  "$@"
   stat=$?
   if test $stat -eq 0; then :
   else
@@ -283,6 +290,46 @@
   rm -f "$tmpdepfile"
   ;;
 
+hp2)
+  # The "hp" stanza above does not work with aCC (C++) and HP's ia64
+  # compilers, which have integrated preprocessors.  The correct option
+  # to use with these is +Maked; it writes dependencies to a file named
+  # 'foo.d', which lands next to the object file, wherever that
+  # happens to be.
+  # Much of this is similar to the tru64 case; see comments there.
+  dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
+  test "x$dir" = "x$object" && dir=
+  base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
+  if test "$libtool" = yes; then
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir.libs/$base.d
+    "$@" -Wc,+Maked
+  else
+    tmpdepfile1=$dir$base.d
+    tmpdepfile2=$dir$base.d
+    "$@" +Maked
+  fi
+  stat=$?
+  if test $stat -eq 0; then :
+  else
+     rm -f "$tmpdepfile1" "$tmpdepfile2"
+     exit $stat
+  fi
+
+  for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
+  do
+    test -f "$tmpdepfile" && break
+  done
+  if test -f "$tmpdepfile"; then
+    sed -e "s,^.*\.[a-z]*:,$object:," "$tmpdepfile" > "$depfile"
+    # Add `dependent.h:' lines.
+    sed -ne '2,${; s/^ *//; s/ \\*$//; s/$/:/; p;}' "$tmpdepfile" >> "$depfile"
+  else
+    echo "#dummy" > "$depfile"
+  fi
+  rm -f "$tmpdepfile" "$tmpdepfile2"
+  ;;
+
 tru64)
    # The Tru64 compiler uses -MD to generate dependencies as a side
    # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
@@ -294,27 +341,43 @@
    base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
 
    if test "$libtool" = yes; then
-      tmpdepfile1="$dir.libs/$base.lo.d"
-      tmpdepfile2="$dir.libs/$base.d"
+      # With Tru64 cc, shared objects can also be used to make a
+      # static library.  This mechanism is used in libtool 1.4 series to
+      # handle both shared and static libraries in a single compilation.
+      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
+      #
+      # With libtool 1.5 this exception was removed, and libtool now
+      # generates 2 separate objects for the 2 libraries.  These two
+      # compilations output dependencies in $dir.libs/$base.o.d and
+      # in $dir$base.o.d.  We have to check for both files, because
+      # one of the two compilations can be disabled.  We should prefer
+      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
+      # automatically cleaned when .libs/ is deleted, while ignoring
+      # the former would cause a distcleancheck panic.
+      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
+      tmpdepfile2=$dir$base.o.d          # libtool 1.5
+      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
+      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
       "$@" -Wc,-MD
    else
-      tmpdepfile1="$dir$base.o.d"
-      tmpdepfile2="$dir$base.d"
+      tmpdepfile1=$dir$base.o.d
+      tmpdepfile2=$dir$base.d
+      tmpdepfile3=$dir$base.d
+      tmpdepfile4=$dir$base.d
       "$@" -MD
    fi
 
    stat=$?
    if test $stat -eq 0; then :
    else
-      rm -f "$tmpdepfile1" "$tmpdepfile2"
+      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
       exit $stat
    fi
 
-   if test -f "$tmpdepfile1"; then
-      tmpdepfile="$tmpdepfile1"
-   else
-      tmpdepfile="$tmpdepfile2"
-   fi
+   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
+   do
+     test -f "$tmpdepfile" && break
+   done
    if test -f "$tmpdepfile"; then
       sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
       # That's a tab and a space in the [].
@@ -458,7 +521,8 @@
   done
 
   "$@" -E |
-    sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
+    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
+       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
     sed '$ s: \\$::' > "$tmpdepfile"
   rm -f "$depfile"
   echo "$object : \\" > "$depfile"
diff --git a/docs/appnote.txt b/docs/appnote.txt
new file mode 100644
index 0000000..aa28672
--- /dev/null
+++ b/docs/appnote.txt
@@ -0,0 +1,3066 @@
+File:    APPNOTE.TXT - .ZIP File Format Specification
+Version: 6.3.0 
+Revised: September 29, 2006
+Copyright (c) 1989 - 2006 PKWARE Inc., All Rights Reserved.
+
+The use of certain technological aspects disclosed in the current
+APPNOTE is available pursuant to the below section entitled
+"Incorporating PKWARE Proprietary Technology into Your Product".
+
+I. Purpose
+----------
+
+This specification is intended to define a cross-platform,
+interoperable file storage and transfer format.  Since its 
+first publication in 1989, PKWARE has remained committed to 
+ensuring the interoperability of the .ZIP file format through 
+publication and maintenance of this specification.  We trust that 
+all .ZIP compatible vendors and application developers that have 
+adopted and benefited from this format will share and support 
+this commitment to interoperability.
+
+II. Contacting PKWARE
+---------------------
+
+     PKWARE, Inc.
+     648 N. Plankinton Avenue, Suite 220
+     Milwaukee, WI 53203
+     +1-414-289-9788
+     +1-414-289-9789 FAX
+     zipformat@pkware.com
+
+III. Disclaimer
+---------------
+
+Although PKWARE will attempt to supply current and accurate
+information relating to its file formats, algorithms, and the
+subject programs, the possibility of error or omission cannot 
+be eliminated. PKWARE therefore expressly disclaims any warranty 
+that the information contained in the associated materials relating 
+to the subject programs and/or the format of the files created or
+accessed by the subject programs and/or the algorithms used by
+the subject programs, or any other matter, is current, correct or
+accurate as delivered.  Any risk of damage due to any possible
+inaccurate information is assumed by the user of the information.
+Furthermore, the information relating to the subject programs
+and/or the file formats created or accessed by the subject
+programs and/or the algorithms used by the subject programs is
+subject to change without notice.
+
+If the version of this file is marked as a NOTIFICATION OF CHANGE,
+the content defines an Early Feature Specification (EFS) change 
+to the .ZIP file format that may be subject to modification prior 
+to publication of the Final Feature Specification (FFS).  This
+document may also contain information on Planned Feature 
+Specifications (PFS) defining recognized future extensions.
+
+IV. Change Log
+--------------
+
+Version       Change Description                        Date
+-------       ------------------                       ----------
+5.2           -Single Password Symmetric Encryption    06/02/2003
+               storage
+
+6.1.0         -Smartcard compatibility                 01/20/2004
+              -Documentation on certificate storage
+
+6.2.0         -Introduction of Central Directory       04/26/2004
+               Encryption for encrypting metadata
+              -Added OS/X to Version Made By values
+
+6.2.1         -Added Extra Field placeholder for       04/01/2005
+               POSZIP using ID 0x4690
+
+              -Clarified size field on 
+               "zip64 end of central directory record"
+
+6.2.2         -Documented Final Feature Specification  01/06/2006
+               for Strong Encryption
+
+              -Clarifications and typographical 
+               corrections
+
+6.3.0         -Added tape positioning storage          09/29/2006
+               parameters
+
+              -Expanded list of supported hash algorithms
+
+              -Expanded list of supported compression
+               algorithms
+
+              -Expanded list of supported encryption
+               algorithms
+
+              -Added option for Unicode filename 
+               storage
+
+              -Clarifications for consistent use
+               of Data Descriptor records
+
+              -Added additional "Extra Field" 
+               definitions
+
+
+V. General Format of a .ZIP file
+--------------------------------
+
+  Files stored in arbitrary order.  Large .ZIP files can span multiple
+  volumes or be split into user-defined segment sizes. All values
+  are stored in little-endian byte order unless otherwise specified. 
+
+  Overall .ZIP file format:
+
+    [local file header 1]
+    [file data 1]
+    [data descriptor 1]
+    . 
+    .
+    .
+    [local file header n]
+    [file data n]
+    [data descriptor n]
+    [archive decryption header] 
+    [archive extra data record] 
+    [central directory]
+    [zip64 end of central directory record]
+    [zip64 end of central directory locator] 
+    [end of central directory record]
+
+
+  A.  Local file header:
+
+        local file header signature     4 bytes  (0x04034b50)
+        version needed to extract       2 bytes
+        general purpose bit flag        2 bytes
+        compression method              2 bytes
+        last mod file time              2 bytes
+        last mod file date              2 bytes
+        crc-32                          4 bytes
+        compressed size                 4 bytes
+        uncompressed size               4 bytes
+        file name length                2 bytes
+        extra field length              2 bytes
+
+        file name (variable size)
+        extra field (variable size)
+
+  B.  File data
+
+      Immediately following the local header for a file
+      is the compressed or stored data for the file. 
+      The series of [local file header][file data][data
+      descriptor] repeats for each file in the .ZIP archive. 
+
+  C.  Data descriptor:
+
+        crc-32                          4 bytes
+        compressed size                 4 bytes
+        uncompressed size               4 bytes
+
+      This descriptor exists only if bit 3 of the general
+      purpose bit flag is set (see below).  It is byte aligned
+      and immediately follows the last byte of compressed data.
+      This descriptor is used only when it was not possible to
+      seek in the output .ZIP file, e.g., when the output .ZIP file
+      was standard output or a non-seekable device.  For ZIP64(tm) format
+      archives, the compressed and uncompressed sizes are 8 bytes each.
+
+      When compressing files, compressed and uncompressed sizes 
+      should be stored in ZIP64 format (as 8 byte values) when a 
+      files size exceeds 0xFFFFFFFF.   However ZIP64 format may be 
+      used regardless of the size of a file.  When extracting, if 
+      the zip64 extended information extra field is present for 
+      the file the compressed and uncompressed sizes will be 8
+      byte values.  
+
+      Although not originally assigned a signature, the value 
+      0x08074b50 has commonly been adopted as a signature value 
+      for the data descriptor record.  Implementers should be 
+      aware that ZIP files may be encountered with or without this 
+      signature marking data descriptors and should account for
+      either case when reading ZIP files to ensure compatibility.
+      When writing ZIP files, it is recommended to include the
+      signature value marking the data descriptor record.  When
+      the signature is used, the fields currently defined for
+      the data descriptor record will immediately follow the
+      signature.
+
+      An extensible data descriptor will be released in a future
+      version of this APPNOTE.  This new record is intended to
+      resolve conflicts with the use of this record going forward,
+      and to provide better support for streamed file processing.
+
+      When the Central Directory Encryption method is used, the data
+      descriptor record is not required, but may be used.  If present,
+      and bit 3 of the general purpose bit field is set to indicate
+      its presence, the values in fields of the data descriptor
+      record should be set to binary zeros.
+
+  D.  Archive decryption header:  
+
+      The Archive Decryption Header is introduced in version 6.2
+      of the ZIP format specification.  This record exists in support
+      of the Central Directory Encryption Feature implemented as part of 
+      the Strong Encryption Specification as described in this document.
+      When the Central Directory Structure is encrypted, this decryption
+      header will precede the encrypted data segment.  The encrypted
+      data segment will consist of the Archive extra data record (if
+      present) and the encrypted Central Directory Structure data.
+      The format of this data record is identical to the Decryption
+      header record preceding compressed file data.  If the central 
+      directory structure is encrypted, the location of the start of
+      this data record is determined using the Start of Central Directory
+      field in the Zip64 End of Central Directory record.  Refer to the 
+      section on the Strong Encryption Specification for information
+      on the fields used in the Archive Decryption Header record.
+
+
+  E.  Archive extra data record: 
+
+        archive extra data signature    4 bytes  (0x08064b50)
+        extra field length              4 bytes
+        extra field data                (variable size)
+
+      The Archive Extra Data Record is introduced in version 6.2
+      of the ZIP format specification.  This record exists in support
+      of the Central Directory Encryption Feature implemented as part of 
+      the Strong Encryption Specification as described in this document.
+      When present, this record immediately precedes the central 
+      directory data structure.  The size of this data record will be
+      included in the Size of the Central Directory field in the
+      End of Central Directory record.  If the central directory structure
+      is compressed, but not encrypted, the location of the start of
+      this data record is determined using the Start of Central Directory
+      field in the Zip64 End of Central Directory record.  
+
+
+  F.  Central directory structure:
+
+      [file header 1]
+      .
+      .
+      . 
+      [file header n]
+      [digital signature] 
+
+      File header:
+
+        central file header signature   4 bytes  (0x02014b50)
+        version made by                 2 bytes
+        version needed to extract       2 bytes
+        general purpose bit flag        2 bytes
+        compression method              2 bytes
+        last mod file time              2 bytes
+        last mod file date              2 bytes
+        crc-32                          4 bytes
+        compressed size                 4 bytes
+        uncompressed size               4 bytes
+        file name length                2 bytes
+        extra field length              2 bytes
+        file comment length             2 bytes
+        disk number start               2 bytes
+        internal file attributes        2 bytes
+        external file attributes        4 bytes
+        relative offset of local header 4 bytes
+
+        file name (variable size)
+        extra field (variable size)
+        file comment (variable size)
+
+      Digital signature:
+
+        header signature                4 bytes  (0x05054b50)
+        size of data                    2 bytes
+        signature data (variable size)
+
+      With the introduction of the Central Directory Encryption 
+      feature in version 6.2 of this specification, the Central 
+      Directory Structure may be stored both compressed and encrypted. 
+      Although not required, it is assumed when encrypting the
+      Central Directory Structure, that it will be compressed
+      for greater storage efficiency.  Information on the
+      Central Directory Encryption feature can be found in the section
+      describing the Strong Encryption Specification. The Digital 
+      Signature record will be neither compressed nor encrypted.
+
+  G.  Zip64 end of central directory record
+
+        zip64 end of central dir 
+        signature                       4 bytes  (0x06064b50)
+        size of zip64 end of central
+        directory record                8 bytes
+        version made by                 2 bytes
+        version needed to extract       2 bytes
+        number of this disk             4 bytes
+        number of the disk with the 
+        start of the central directory  4 bytes
+        total number of entries in the
+        central directory on this disk  8 bytes
+        total number of entries in the
+        central directory               8 bytes
+        size of the central directory   8 bytes
+        offset of start of central
+        directory with respect to
+        the starting disk number        8 bytes
+        zip64 extensible data sector    (variable size)
+
+        The value stored into the "size of zip64 end of central
+        directory record" should be the size of the remaining
+        record and should not include the leading 12 bytes.
+  
+        Size = SizeOfFixedFields + SizeOfVariableData - 12.
+
+        The above record structure defines Version 1 of the 
+        zip64 end of central directory record. Version 1 was 
+        implemented in versions of this specification preceding 
+        6.2 in support of the ZIP64 large file feature. The 
+        introduction of the Central Directory Encryption feature 
+        implemented in version 6.2 as part of the Strong Encryption 
+        Specification defines Version 2 of this record structure. 
+        Refer to the section describing the Strong Encryption 
+        Specification for details on the version 2 format for 
+        this record.
+
+        Special purpose data may reside in the zip64 extensible data
+        sector field following either a V1 or V2 version of this
+        record.  To ensure identification of this special purpose data
+        it must include an identifying header block consisting of the
+        following:
+
+           Header ID  -  2 bytes
+           Data Size  -  4 bytes
+
+        The Header ID field indicates the type of data that is in the 
+        data block that follows.
+
+        Data Size identifies the number of bytes that follow for this
+        data block type.
+
+        Multiple special purpose data blocks may be present, but each
+        must be preceded by a Header ID and Data Size field.  Current
+        mappings of Header ID values supported in this field are as
+        defined in APPENDIX C.
+
+  H.  Zip64 end of central directory locator
+
+        zip64 end of central dir locator 
+        signature                       4 bytes  (0x07064b50)
+        number of the disk with the
+        start of the zip64 end of 
+        central directory               4 bytes
+        relative offset of the zip64
+        end of central directory record 8 bytes
+        total number of disks           4 bytes
+        
+  I.  End of central directory record:
+
+        end of central dir signature    4 bytes  (0x06054b50)
+        number of this disk             2 bytes
+        number of the disk with the
+        start of the central directory  2 bytes
+        total number of entries in the
+        central directory on this disk  2 bytes
+        total number of entries in
+        the central directory           2 bytes
+        size of the central directory   4 bytes
+        offset of start of central
+        directory with respect to
+        the starting disk number        4 bytes
+        .ZIP file comment length        2 bytes
+        .ZIP file comment       (variable size)
+
+  J.  Explanation of fields:
+
+      version made by (2 bytes)
+
+          The upper byte indicates the compatibility of the file
+          attribute information.  If the external file attributes 
+          are compatible with MS-DOS and can be read by PKZIP for 
+          DOS version 2.04g then this value will be zero.  If these 
+          attributes are not compatible, then this value will 
+          identify the host system on which the attributes are 
+          compatible.  Software can use this information to determine
+          the line record format for text files etc.  The current
+          mappings are:
+
+          0 - MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)
+          1 - Amiga                     2 - OpenVMS
+          3 - UNIX                      4 - VM/CMS
+          5 - Atari ST                  6 - OS/2 H.P.F.S.
+          7 - Macintosh                 8 - Z-System
+          9 - CP/M                     10 - Windows NTFS
+         11 - MVS (OS/390 - Z/OS)      12 - VSE
+         13 - Acorn Risc               14 - VFAT
+         15 - alternate MVS            16 - BeOS
+         17 - Tandem                   18 - OS/400
+         19 - OS/X (Darwin)            20 thru 255 - unused
+
+          The lower byte indicates the ZIP specification version 
+          (the version of this document) supported by the software 
+          used to encode the file.  The value/10 indicates the major 
+          version number, and the value mod 10 is the minor version 
+          number.  
+
+      version needed to extract (2 bytes)
+
+          The minimum supported ZIP specification version needed to 
+          extract the file, mapped as above.  This value is based on 
+          the specific format features a ZIP program must support to 
+          be able to extract the file.  If multiple features are
+          applied to a file, the minimum version should be set to the 
+          feature having the highest value. New features or feature 
+          changes affecting the published format specification will be 
+          implemented using higher version numbers than the last 
+          published value to avoid conflict.
+
+          Current minimum feature versions are as defined below:
+
+          1.0 - Default value
+          1.1 - File is a volume label
+          2.0 - File is a folder (directory)
+          2.0 - File is compressed using Deflate compression
+          2.0 - File is encrypted using traditional PKWARE encryption
+          2.1 - File is compressed using Deflate64(tm)
+          2.5 - File is compressed using PKWARE DCL Implode 
+          2.7 - File is a patch data set 
+          4.5 - File uses ZIP64 format extensions
+          4.6 - File is compressed using BZIP2 compression*
+          5.0 - File is encrypted using DES
+          5.0 - File is encrypted using 3DES
+          5.0 - File is encrypted using original RC2 encryption
+          5.0 - File is encrypted using RC4 encryption
+          5.1 - File is encrypted using AES encryption
+          5.1 - File is encrypted using corrected RC2 encryption**
+          5.2 - File is encrypted using corrected RC2-64 encryption**
+          6.1 - File is encrypted using non-OAEP key wrapping***
+          6.2 - Central directory encryption
+          6.3 - File is compressed using LZMA
+          6.3 - File is compressed using PPMd+
+          6.3 - File is encrypted using Blowfish
+          6.3 - File is encrypted using Twofish
+
+
+          * Early 7.x (pre-7.2) versions of PKZIP incorrectly set the
+          version needed to extract for BZIP2 compression to be 50
+          when it should have been 46.
+
+          ** Refer to the section on Strong Encryption Specification
+          for additional information regarding RC2 corrections.
+
+          *** Certificate encryption using non-OAEP key wrapping is the
+          intended mode of operation for all versions beginning with 6.1.
+          Support for OAEP key wrapping should only be used for
+          backward compatibility when sending ZIP files to be opened by
+          versions of PKZIP older than 6.1 (5.0 or 6.0).
+
+          + Files compressed using PPMd should set the version
+          needed to extract field to 6.3, however, not all ZIP 
+          programs enforce this and may be unable to decompress 
+          data files compressed using PPMd if this value is set.
+
+          When using ZIP64 extensions, the corresponding value in the
+          zip64 end of central directory record should also be set.  
+          This field should be set appropriately to indicate whether 
+          Version 1 or Version 2 format is in use. 
+
+      general purpose bit flag: (2 bytes)
+
+          Bit 0: If set, indicates that the file is encrypted.
+
+          (For Method 6 - Imploding)
+          Bit 1: If the compression method used was type 6,
+                 Imploding, then this bit, if set, indicates
+                 an 8K sliding dictionary was used.  If clear,
+                 then a 4K sliding dictionary was used.
+          Bit 2: If the compression method used was type 6,
+                 Imploding, then this bit, if set, indicates
+                 3 Shannon-Fano trees were used to encode the
+                 sliding dictionary output.  If clear, then 2
+                 Shannon-Fano trees were used.
+
+          (For Methods 8 and 9 - Deflating)
+          Bit 2  Bit 1
+            0      0    Normal (-en) compression option was used.
+            0      1    Maximum (-exx/-ex) compression option was used.
+            1      0    Fast (-ef) compression option was used.
+            1      1    Super Fast (-es) compression option was used.
+
+          (For Method 14 - LZMA)
+          Bit 1: If the compression method used was type 14,
+                 LZMA, then this bit, if set, indicates
+                 an end-of-stream (EOS) marker is used to
+                 mark the end of the compressed data stream.
+                 If clear, then an EOS marker is not present
+                 and the compressed data size must be known
+                 to extract.
+
+          Note:  Bits 1 and 2 are undefined if the compression
+                 method is any other.
+
+          Bit 3: If this bit is set, the fields crc-32, compressed 
+                 size and uncompressed size are set to zero in the 
+                 local header.  The correct values are put in the 
+                 data descriptor immediately following the compressed
+                 data.  (Note: PKZIP version 2.04g for DOS only 
+                 recognizes this bit for method 8 compression, newer 
+                 versions of PKZIP recognize this bit for any 
+                 compression method.)
+
+          Bit 4: Reserved for use with method 8, for enhanced
+                 deflating. 
+
+          Bit 5: If this bit is set, this indicates that the file is 
+                 compressed patched data.  (Note: Requires PKZIP 
+                 version 2.70 or greater)
+
+          Bit 6: Strong encryption.  If this bit is set, you should
+                 set the version needed to extract value to at least
+                 50 and you must also set bit 0.  If AES encryption
+                 is used, the version needed to extract value must 
+                 be at least 51.
+
+          Bit 7: Currently unused.
+
+          Bit 8: Currently unused.
+
+          Bit 9: Currently unused.
+
+          Bit 10: Currently unused.
+
+          Bit 11: Language encoding flag (EFS).  If this bit is set,
+                  the filename and comment fields for this file
+                  must be encoded using UTF-8. (see APPENDIX D)
+
+          Bit 12: Reserved by PKWARE for enhanced compression.
+
+          Bit 13: Used when encrypting the Central Directory to indicate 
+                  selected data values in the Local Header are masked to
+                  hide their actual values.  See the section describing 
+                  the Strong Encryption Specification for details.
+
+          Bit 14: Reserved by PKWARE.
+
+          Bit 15: Reserved by PKWARE.
+
+      compression method: (2 bytes)
+
+          (see accompanying documentation for algorithm
+          descriptions)
+
+          0 - The file is stored (no compression)
+          1 - The file is Shrunk
+          2 - The file is Reduced with compression factor 1
+          3 - The file is Reduced with compression factor 2
+          4 - The file is Reduced with compression factor 3
+          5 - The file is Reduced with compression factor 4
+          6 - The file is Imploded
+          7 - Reserved for Tokenizing compression algorithm
+          8 - The file is Deflated
+          9 - Enhanced Deflating using Deflate64(tm)
+         10 - PKWARE Data Compression Library Imploding (old IBM TERSE)
+         11 - Reserved by PKWARE
+         12 - File is compressed using BZIP2 algorithm
+         13 - Reserved by PKWARE
+         14 - LZMA (EFS)
+         15 - Reserved by PKWARE
+         16 - Reserved by PKWARE
+         17 - Reserved by PKWARE
+         18 - File is compressed using IBM TERSE (new)
+         19 - IBM LZ77 z Architecture (PFS)
+         98 - PPMd version I, Rev 1
+
+      date and time fields: (2 bytes each)
+
+          The date and time are encoded in standard MS-DOS format.
+          If input came from standard input, the date and time are
+          those at which compression was started for this data. 
+          If encrypting the central directory and general purpose bit 
+          flag 13 is set indicating masking, the value stored in the 
+          Local Header will be zero. 
+
+      CRC-32: (4 bytes)
+
+          The CRC-32 algorithm was generously contributed by
+          David Schwaderer and can be found in his excellent
+          book "C Programmers Guide to NetBIOS" published by
+          Howard W. Sams & Co. Inc.  The 'magic number' for
+          the CRC is 0xdebb20e3.  The proper CRC pre and post
+          conditioning is used, meaning that the CRC register
+          is pre-conditioned with all ones (a starting value
+          of 0xffffffff) and the value is post-conditioned by
+          taking the one's complement of the CRC residual.
+          If bit 3 of the general purpose flag is set, this
+          field is set to zero in the local header and the correct
+          value is put in the data descriptor and in the central
+          directory. When encrypting the central directory, if the
+          local header is not in ZIP64 format and general purpose 
+          bit flag 13 is set indicating masking, the value stored 
+          in the Local Header will be zero. 
+
+      compressed size: (4 bytes)
+      uncompressed size: (4 bytes)
+
+          The size of the file compressed and uncompressed,
+          respectively.  When a decryption header is present it will
+          be placed in front of the file data and the value of the
+          compressed file size will include the bytes of the decryption
+          header.  If bit 3 of the general purpose bit flag is set, 
+          these fields are set to zero in the local header and the 
+          correct values are put in the data descriptor and
+          in the central directory.  If an archive is in ZIP64 format
+          and the value in this field is 0xFFFFFFFF, the size will be
+          in the corresponding 8 byte ZIP64 extended information 
+          extra field.  When encrypting the central directory, if the
+          local header is not in ZIP64 format and general purpose bit 
+          flag 13 is set indicating masking, the value stored for the 
+          uncompressed size in the Local Header will be zero. 
+
+      file name length: (2 bytes)
+      extra field length: (2 bytes)
+      file comment length: (2 bytes)
+
+          The length of the file name, extra field, and comment
+          fields respectively.  The combined length of any
+          directory record and these three fields should not
+          generally exceed 65,535 bytes.  If input came from standard
+          input, the file name length is set to zero.  
+
+      disk number start: (2 bytes)
+
+          The number of the disk on which this file begins.  If an 
+          archive is in ZIP64 format and the value in this field is 
+          0xFFFF, the size will be in the corresponding 4 byte zip64 
+          extended information extra field.
+
+      internal file attributes: (2 bytes)
+
+          Bits 1 and 2 are reserved for use by PKWARE.
+
+          The lowest bit of this field indicates, if set, that
+          the file is apparently an ASCII or text file.  If not
+          set, that the file apparently contains binary data.
+          The remaining bits are unused in version 1.0.
+
+          The 0x0002 bit of this field indicates, if set, that a 
+          4 byte variable record length control field precedes each 
+          logical record indicating the length of the record. The 
+          record length control field is stored in little-endian byte
+          order.  This flag is independent of text control characters, 
+          and if used in conjunction with text data, includes any 
+          control characters in the total length of the record. This 
+          value is provided for mainframe data transfer support.
+
+      external file attributes: (4 bytes)
+
+          The mapping of the external attributes is
+          host-system dependent (see 'version made by').  For
+          MS-DOS, the low order byte is the MS-DOS directory
+          attribute byte.  If input came from standard input, this
+          field is set to zero.
+
+      relative offset of local header: (4 bytes)
+
+          This is the offset from the start of the first disk on
+          which this file appears, to where the local header should
+          be found.  If an archive is in ZIP64 format and the value
+          in this field is 0xFFFFFFFF, the size will be in the 
+          corresponding 8 byte zip64 extended information extra field.
+
+      file name: (Variable)
+
+          The name of the file, with optional relative path.
+          The path stored should not contain a drive or
+          device letter, or a leading slash.  All slashes
+          should be forward slashes '/' as opposed to
+          backwards slashes '\' for compatibility with Amiga
+          and UNIX file systems etc.  If input came from standard
+          input, there is no file name field.  If encrypting
+          the central directory and general purpose bit flag 13 is set 
+          indicating masking, the file name stored in the Local Header 
+          will not be the actual file name.  A masking value consisting 
+          of a unique hexadecimal value will be stored.  This value will 
+          be sequentially incremented for each file in the archive. See
+          the section on the Strong Encryption Specification for details 
+          on retrieving the encrypted file name. 
+
+      extra field: (Variable)
+
+          This is for expansion.  If additional information
+          needs to be stored for special needs or for specific 
+          platforms, it should be stored here.  Earlier versions 
+          of the software can then safely skip this file, and 
+          find the next file or header.  This field will be 0 
+          length in version 1.0.
+
+          In order to allow different programs and different types
+          of information to be stored in the 'extra' field in .ZIP
+          files, the following structure should be used for all
+          programs storing data in this field:
+
+          header1+data1 + header2+data2 . . .
+
+          Each header should consist of:
+
+            Header ID - 2 bytes
+            Data Size - 2 bytes
+
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          The Header ID field indicates the type of data that is in
+          the following data block.
+
+          Header ID's of 0 thru 31 are reserved for use by PKWARE.
+          The remaining ID's can be used by third party vendors for
+          proprietary usage.
+
+          The current Header ID mappings defined by PKWARE are:
+
+          0x0001        Zip64 extended information extra field
+          0x0007        AV Info
+          0x0008        Reserved for extended language encoding data (PFS)
+                        (see APPENDIX D)
+          0x0009        OS/2
+          0x000a        NTFS 
+          0x000c        OpenVMS
+          0x000d        UNIX
+          0x000e        Reserved for file stream and fork descriptors
+          0x000f        Patch Descriptor
+          0x0014        PKCS#7 Store for X.509 Certificates
+          0x0015        X.509 Certificate ID and Signature for 
+                        individual file
+          0x0016        X.509 Certificate ID for Central Directory
+          0x0017        Strong Encryption Header
+          0x0018        Record Management Controls
+          0x0019        PKCS#7 Encryption Recipient Certificate List
+          0x0065        IBM S/390 (Z390), AS/400 (I400) attributes 
+                        - uncompressed
+          0x0066        Reserved for IBM S/390 (Z390), AS/400 (I400) 
+                        attributes - compressed
+          0x4690        POSZIP 4690 (reserved) 
+
+          Third party mappings commonly used are:
+
+
+          0x07c8        Macintosh
+          0x2605        ZipIt Macintosh
+          0x2705        ZipIt Macintosh 1.3.5+
+          0x2805        ZipIt Macintosh 1.3.5+
+          0x334d        Info-ZIP Macintosh
+          0x4341        Acorn/SparkFS 
+          0x4453        Windows NT security descriptor (binary ACL)
+          0x4704        VM/CMS
+          0x470f        MVS
+          0x4b46        FWKCS MD5 (see below)
+          0x4c41        OS/2 access control list (text ACL)
+          0x4d49        Info-ZIP OpenVMS
+          0x4f4c        Xceed original location extra field
+          0x5356        AOS/VS (ACL)
+          0x5455        extended timestamp
+          0x554e        Xceed unicode extra field
+          0x5855        Info-ZIP UNIX (original, also OS/2, NT, etc)
+          0x6542        BeOS/BeBox
+          0x756e        ASi UNIX
+          0x7855        Info-ZIP UNIX (new)
+          0xa220        Microsoft Open Packaging Growth Hint
+          0xfd4a        SMS/QDOS
+
+          Detailed descriptions of Extra Fields defined by third 
+          party mappings will be documented as information on
+          these data structures is made available to PKWARE.  
+          PKWARE does not guarantee the accuracy of any published
+          third party data.
+
+          The Data Size field indicates the size of the following
+          data block. Programs can use this value to skip to the
+          next header block, passing over any data blocks that are
+          not of interest.
+
+          Note: As stated above, the size of the entire .ZIP file
+                header, including the file name, comment, and extra
+                field should not exceed 64K in size.
+
+          In case two different programs should appropriate the same
+          Header ID value, it is strongly recommended that each
+          program place a unique signature of at least two bytes in
+          size (and preferably 4 bytes or bigger) at the start of
+          each data area.  Every program should verify that its
+          unique signature is present, in addition to the Header ID
+          value being correct, before assuming that it is a block of
+          known type.
+
+         -Zip64 Extended Information Extra Field (0x0001):
+
+          The following is the layout of the zip64 extended 
+          information "extra" block. If one of the size or
+          offset fields in the Local or Central directory
+          record is too small to hold the required data,
+          a Zip64 extended information record is created.
+          The order of the fields in the zip64 extended 
+          information record is fixed, but the fields will
+          only appear if the corresponding Local or Central
+          directory record field is set to 0xFFFF or 0xFFFFFFFF.
+
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value      Size       Description
+          -----      ----       -----------
+  (ZIP64) 0x0001     2 bytes    Tag for this "extra" block type
+          Size       2 bytes    Size of this "extra" block
+          Original 
+          Size       8 bytes    Original uncompressed file size
+          Compressed
+          Size       8 bytes    Size of compressed data
+          Relative Header
+          Offset     8 bytes    Offset of local header record
+          Disk Start
+          Number     4 bytes    Number of the disk on which
+                                this file starts 
+
+          This entry in the Local header must include BOTH original
+          and compressed file size fields. If encrypting the 
+          central directory and bit 13 of the general purpose bit
+          flag is set indicating masking, the value stored in the
+          Local Header for the original file size will be zero.
+
+
+         -OS/2 Extra Field (0x0009):
+
+          The following is the layout of the OS/2 attributes "extra" 
+          block.  (Last Revision  09/05/95)
+
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value       Size          Description
+          -----       ----          -----------
+  (OS/2)  0x0009      2 bytes       Tag for this "extra" block type
+          TSize       2 bytes       Size for the following data block
+          BSize       4 bytes       Uncompressed Block Size
+          CType       2 bytes       Compression type
+          EACRC       4 bytes       CRC value for uncompress block
+          (var)       variable      Compressed block
+
+          The OS/2 extended attribute structure (FEA2LIST) is 
+          compressed and then stored in it's entirety within this 
+          structure.  There will only ever be one "block" of data in 
+          VarFields[].
+
+         -NTFS Extra Field (0x000a):
+
+          The following is the layout of the NTFS attributes 
+          "extra" block. (Note: At this time the Mtime, Atime
+          and Ctime values may be used on any WIN32 system.)  
+
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value      Size       Description
+          -----      ----       -----------
+  (NTFS)  0x000a     2 bytes    Tag for this "extra" block type
+          TSize      2 bytes    Size of the total "extra" block
+          Reserved   4 bytes    Reserved for future use
+          Tag1       2 bytes    NTFS attribute tag value #1
+          Size1      2 bytes    Size of attribute #1, in bytes
+          (var.)     Size1      Attribute #1 data
+          .
+          .
+          .
+          TagN       2 bytes    NTFS attribute tag value #N
+          SizeN      2 bytes    Size of attribute #N, in bytes
+          (var.)     SizeN      Attribute #N data
+
+          For NTFS, values for Tag1 through TagN are as follows:
+          (currently only one set of attributes is defined for NTFS)
+
+          Tag        Size       Description
+          -----      ----       -----------
+          0x0001     2 bytes    Tag for attribute #1 
+          Size1      2 bytes    Size of attribute #1, in bytes
+          Mtime      8 bytes    File last modification time
+          Atime      8 bytes    File last access time
+          Ctime      8 bytes    File creation time
+
+         -OpenVMS Extra Field (0x000c):
+
+          The following is the layout of the OpenVMS attributes 
+          "extra" block.
+
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value      Size       Description
+          -----      ----       -----------
+  (VMS)   0x000c     2 bytes    Tag for this "extra" block type
+          TSize      2 bytes    Size of the total "extra" block
+          CRC        4 bytes    32-bit CRC for remainder of the block
+          Tag1       2 bytes    OpenVMS attribute tag value #1
+          Size1      2 bytes    Size of attribute #1, in bytes
+          (var.)     Size1      Attribute #1 data
+          .
+          .
+          .
+          TagN       2 bytes    OpenVMS attribute tag value #N
+          SizeN      2 bytes    Size of attribute #N, in bytes
+          (var.)     SizeN      Attribute #N data
+
+          Rules:
+
+          1. There will be one or more of attributes present, which 
+             will each be preceded by the above TagX & SizeX values.  
+             These values are identical to the ATR$C_XXXX and 
+             ATR$S_XXXX constants which are defined in ATR.H under 
+             OpenVMS C.  Neither of these values will ever be zero.
+
+          2. No word alignment or padding is performed.
+
+          3. A well-behaved PKZIP/OpenVMS program should never produce
+             more than one sub-block with the same TagX value.  Also,
+             there will never be more than one "extra" block of type
+             0x000c in a particular directory record.
+
+         -UNIX Extra Field (0x000d):
+
+          The following is the layout of the UNIX "extra" block.
+          Note: all fields are stored in Intel low-byte/high-byte 
+          order.
+
+          Value       Size          Description
+          -----       ----          -----------
+  (UNIX)  0x000d      2 bytes       Tag for this "extra" block type
+          TSize       2 bytes       Size for the following data block
+          Atime       4 bytes       File last access time
+          Mtime       4 bytes       File last modification time
+          Uid         2 bytes       File user ID
+          Gid         2 bytes       File group ID
+          (var)       variable      Variable length data field
+
+          The variable length data field will contain file type 
+          specific data.  Currently the only values allowed are
+          the original "linked to" file names for hard or symbolic 
+          links, and the major and minor device node numbers for
+          character and block device nodes.  Since device nodes
+          cannot be either symbolic or hard links, only one set of
+          variable length data is stored.  Link files will have the
+          name of the original file stored.  This name is NOT NULL
+          terminated.  Its size can be determined by checking TSize -
+          12.  Device entries will have eight bytes stored as two 4
+          byte entries (in little endian format).  The first entry
+          will be the major device number, and the second the minor
+          device number.
+          
+         -PATCH Descriptor Extra Field (0x000f):
+
+          The following is the layout of the Patch Descriptor "extra"
+          block.
+
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value     Size     Description
+          -----     ----     -----------
+  (Patch) 0x000f    2 bytes  Tag for this "extra" block type
+          TSize     2 bytes  Size of the total "extra" block
+          Version   2 bytes  Version of the descriptor
+          Flags     4 bytes  Actions and reactions (see below) 
+          OldSize   4 bytes  Size of the file about to be patched 
+          OldCRC    4 bytes  32-bit CRC of the file to be patched 
+          NewSize   4 bytes  Size of the resulting file 
+          NewCRC    4 bytes  32-bit CRC of the resulting file 
+
+          Actions and reactions
+
+          Bits          Description
+          ----          ----------------
+          0             Use for auto detection
+          1             Treat as a self-patch
+          2-3           RESERVED
+          4-5           Action (see below)
+          6-7           RESERVED
+          8-9           Reaction (see below) to absent file 
+          10-11         Reaction (see below) to newer file
+          12-13         Reaction (see below) to unknown file
+          14-15         RESERVED
+          16-31         RESERVED
+
+          Actions
+
+          Action       Value
+          ------       ----- 
+          none         0
+          add          1
+          delete       2
+          patch        3
+
+          Reactions
+ 
+          Reaction     Value
+          --------     -----
+          ask          0
+          skip         1
+          ignore       2
+          fail         3
+
+          Patch support is provided by PKPatchMaker(tm) technology and is 
+          covered under U.S. Patents and Patents Pending. The use or 
+          implementation in a product of certain technological aspects set
+          forth in the current APPNOTE, including those with regard to 
+          strong encryption, patching, or extended tape operations requires
+          a license from PKWARE.  Please contact PKWARE with regard to 
+          acquiring a license. 
+
+         -PKCS#7 Store for X.509 Certificates (0x0014):
+
+          This field contains information about each of the certificates 
+          files may be signed with. When the Central Directory Encryption 
+          feature is enabled for a ZIP file, this record will appear in 
+          the Archive Extra Data Record, otherwise it will appear in the 
+          first central directory record and will be ignored in any 
+          other record.
+          
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value     Size     Description
+          -----     ----     -----------
+  (Store) 0x0014    2 bytes  Tag for this "extra" block type
+          TSize     2 bytes  Size of the store data
+          TData     TSize    Data about the store
+
+
+         -X.509 Certificate ID and Signature for individual file (0x0015):
+
+          This field contains the information about which certificate in 
+          the PKCS#7 store was used to sign a particular file. It also 
+          contains the signature data. This field can appear multiple 
+          times, but can only appear once per certificate.
+
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value     Size     Description
+          -----     ----     -----------
+  (CID)   0x0015    2 bytes  Tag for this "extra" block type
+          TSize     2 bytes  Size of data that follows
+          TData     TSize    Signature Data
+
+         -X.509 Certificate ID and Signature for central directory (0x0016):
+
+          This field contains the information about which certificate in 
+          the PKCS#7 store was used to sign the central directory structure.
+          When the Central Directory Encryption feature is enabled for a 
+          ZIP file, this record will appear in the Archive Extra Data Record, 
+          otherwise it will appear in the first central directory record.
+
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value     Size     Description
+          -----     ----     -----------
+  (CDID)  0x0016    2 bytes  Tag for this "extra" block type
+          TSize     2 bytes  Size of data that follows
+          TData     TSize    Data
+
+         -Strong Encryption Header (0x0017):
+
+          Value     Size     Description
+          -----     ----     -----------
+          0x0017    2 bytes  Tag for this "extra" block type
+          TSize     2 bytes  Size of data that follows
+          Format    2 bytes  Format definition for this record
+          AlgID     2 bytes  Encryption algorithm identifier
+          Bitlen    2 bytes  Bit length of encryption key
+          Flags     2 bytes  Processing flags
+          CertData  TSize-8  Certificate decryption extra field data
+                             (refer to the explanation for CertData
+                              in the section describing the 
+                              Certificate Processing Method under 
+                              the Strong Encryption Specification)
+
+
+         -Record Management Controls (0x0018):
+
+          Value     Size     Description
+          -----     ----     -----------
+(Rec-CTL) 0x0018    2 bytes  Tag for this "extra" block type
+          CSize     2 bytes  Size of total extra block data
+          Tag1      2 bytes  Record control attribute 1
+          Size1     2 bytes  Size of attribute 1, in bytes
+          Data1     Size1    Attribute 1 data
+            .
+            .
+            .
+          TagN      2 bytes  Record control attribute N
+          SizeN     2 bytes  Size of attribute N, in bytes
+          DataN     SizeN    Attribute N data
+
+
+         -PKCS#7 Encryption Recipient Certificate List (0x0019): 
+
+          This field contains information about each of the certificates
+          used in encryption processing and it can be used to identify who is
+          allowed to decrypt encrypted files.  This field should only appear 
+          in the archive extra data record. This field is not required and 
+          serves only to aide archive modifications by preserving public 
+          encryption key data. Individual security requirements may dictate 
+          that this data be omitted to deter information exposure.
+
+          Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value     Size     Description
+          -----     ----     -----------
+ (CStore) 0x0019    2 bytes  Tag for this "extra" block type
+          TSize     2 bytes  Size of the store data
+          TData     TSize    Data about the store
+
+          TData:
+
+          Value     Size     Description
+          -----     ----     -----------
+          Version   2 bytes  Format version number - must 0x0001 at this time
+          CStore    (var)    PKCS#7 data blob
+
+
+         -MVS Extra Field (0x0065):
+
+          The following is the layout of the MVS "extra" block.
+          Note: Some fields are stored in Big Endian format.
+          All text is in EBCDIC format unless otherwise specified.
+
+          Value       Size          Description
+          -----       ----          -----------
+  (MVS)   0x0065      2 bytes       Tag for this "extra" block type
+          TSize       2 bytes       Size for the following data block
+          ID          4 bytes       EBCDIC "Z390" 0xE9F3F9F0 or
+                                    "T4MV" for TargetFour
+          (var)       TSize-4       Attribute data (see APPENDIX B)
+
+
+         -OS/400 Extra Field (0x0065):
+
+          The following is the layout of the OS/400 "extra" block.
+          Note: Some fields are stored in Big Endian format.
+          All text is in EBCDIC format unless otherwise specified.
+
+          Value       Size          Description
+          -----       ----          -----------
+  (OS400) 0x0065      2 bytes       Tag for this "extra" block type
+          TSize       2 bytes       Size for the following data block
+          ID          4 bytes       EBCDIC "I400" 0xC9F4F0F0 or
+                                    "T4MV" for TargetFour
+          (var)       TSize-4       Attribute data (see APPENDIX A)
+
+
+          Third-party Mappings:
+          
+         -ZipIt Macintosh Extra Field (long) (0x2605):
+
+          The following is the layout of the ZipIt extra block 
+          for Macintosh. The local-header and central-header versions 
+          are identical. This block must be present if the file is 
+          stored MacBinary-encoded and it should not be used if the file 
+          is not stored MacBinary-encoded.
+
+          Value         Size        Description
+          -----         ----        -----------
+  (Mac2)  0x2605        Short       tag for this extra block type
+          TSize         Short       total data size for this block
+          "ZPIT"        beLong      extra-field signature
+          FnLen         Byte        length of FileName
+          FileName      variable    full Macintosh filename
+          FileType      Byte[4]     four-byte Mac file type string
+          Creator       Byte[4]     four-byte Mac creator string
+
+
+         -ZipIt Macintosh Extra Field (short, for files) (0x2705):
+
+          The following is the layout of a shortened variant of the
+          ZipIt extra block for Macintosh (without "full name" entry).
+          This variant is used by ZipIt 1.3.5 and newer for entries of
+          files (not directories) that do not have a MacBinary encoded
+          file. The local-header and central-header versions are identical.
+
+          Value         Size        Description
+          -----         ----        -----------
+  (Mac2b) 0x2705        Short       tag for this extra block type
+          TSize         Short       total data size for this block (12)
+          "ZPIT"        beLong      extra-field signature
+          FileType      Byte[4]     four-byte Mac file type string
+          Creator       Byte[4]     four-byte Mac creator string
+          fdFlags       beShort     attributes from FInfo.frFlags,
+                                    may be omitted
+          0x0000        beShort     reserved, may be omitted
+
+
+         -ZipIt Macintosh Extra Field (short, for directories) (0x2805):
+
+          The following is the layout of a shortened variant of the
+          ZipIt extra block for Macintosh used only for directory
+          entries. This variant is used by ZipIt 1.3.5 and newer to 
+          save some optional Mac-specific information about directories.
+          The local-header and central-header versions are identical.
+
+          Value         Size        Description
+          -----         ----        -----------
+  (Mac2c) 0x2805        Short       tag for this extra block type
+          TSize         Short       total data size for this block (12)
+          "ZPIT"        beLong      extra-field signature
+          frFlags       beShort     attributes from DInfo.frFlags, may
+                                    be omitted
+          View          beShort     ZipIt view flag, may be omitted
+
+
+          The View field specifies ZipIt-internal settings as follows:
+
+          Bits of the Flags:
+              bit 0           if set, the folder is shown expanded (open)
+                              when the archive contents are viewed in ZipIt.
+              bits 1-15       reserved, zero;
+
+
+         -FWKCS MD5 Extra Field (0x4b46):
+
+          The FWKCS Contents_Signature System, used in
+          automatically identifying files independent of file name,
+          optionally adds and uses an extra field to support the
+          rapid creation of an enhanced contents_signature:
+
+              Header ID = 0x4b46
+              Data Size = 0x0013
+              Preface   = 'M','D','5'
+              followed by 16 bytes containing the uncompressed file's
+              128_bit MD5 hash(1), low byte first.
+
+          When FWKCS revises a .ZIP file central directory to add
+          this extra field for a file, it also replaces the
+          central directory entry for that file's uncompressed
+          file length with a measured value.
+
+          FWKCS provides an option to strip this extra field, if
+          present, from a .ZIP file central directory. In adding
+          this extra field, FWKCS preserves .ZIP file Authenticity
+          Verification; if stripping this extra field, FWKCS
+          preserves all versions of AV through PKZIP version 2.04g.
+
+          FWKCS, and FWKCS Contents_Signature System, are
+          trademarks of Frederick W. Kantor.
+
+          (1) R. Rivest, RFC1321.TXT, MIT Laboratory for Computer
+              Science and RSA Data Security, Inc., April 1992.
+              ll.76-77: "The MD5 algorithm is being placed in the
+              public domain for review and possible adoption as a
+              standard."
+
+         -Microsoft Open Packaging Growth Hint (0xa220):
+
+          Value         Size        Description
+          -----         ----        -----------
+          0xa220        Short       tag for this extra block type
+          TSize         Short       size of Sig + PadVal + Padding
+          Sig           Short       verification signature (A028)
+          PadVal        Short       Initial padding value
+          Padding       variable    filled with NULL characters
+
+
+      file comment: (Variable)
+
+          The comment for this file.
+
+      number of this disk: (2 bytes)
+
+          The number of this disk, which contains central
+          directory end record. If an archive is in ZIP64 format
+          and the value in this field is 0xFFFF, the size will 
+          be in the corresponding 4 byte zip64 end of central 
+          directory field.
+
+
+      number of the disk with the start of the central
+      directory: (2 bytes)
+
+          The number of the disk on which the central
+          directory starts. If an archive is in ZIP64 format
+          and the value in this field is 0xFFFF, the size will 
+          be in the corresponding 4 byte zip64 end of central 
+          directory field.
+
+      total number of entries in the central dir on 
+      this disk: (2 bytes)
+
+          The number of central directory entries on this disk.
+          If an archive is in ZIP64 format and the value in 
+          this field is 0xFFFF, the size will be in the 
+          corresponding 8 byte zip64 end of central 
+          directory field.
+
+      total number of entries in the central dir: (2 bytes)
+
+          The total number of files in the .ZIP file. If an 
+          archive is in ZIP64 format and the value in this field
+          is 0xFFFF, the size will be in the corresponding 8 byte 
+          zip64 end of central directory field.
+
+      size of the central directory: (4 bytes)
+
+          The size (in bytes) of the entire central directory.
+          If an archive is in ZIP64 format and the value in 
+          this field is 0xFFFFFFFF, the size will be in the 
+          corresponding 8 byte zip64 end of central 
+          directory field.
+
+      offset of start of central directory with respect to
+      the starting disk number:  (4 bytes)
+
+          Offset of the start of the central directory on the
+          disk on which the central directory starts. If an 
+          archive is in ZIP64 format and the value in this 
+          field is 0xFFFFFFFF, the size will be in the 
+          corresponding 8 byte zip64 end of central 
+          directory field.
+
+      .ZIP file comment length: (2 bytes)
+
+          The length of the comment for this .ZIP file.
+
+      .ZIP file comment: (Variable)
+
+          The comment for this .ZIP file.  ZIP file comment data
+          is stored unsecured.  No encryption or data authentication
+          is applied to this area at this time.  Confidential information
+          should not be stored in this section.
+
+      zip64 extensible data sector    (variable size)
+
+          (currently reserved for use by PKWARE)
+
+
+  K.  Splitting and Spanning ZIP files
+
+          Spanning is the process of segmenting a ZIP file across 
+          multiple removable media. This support has typically only 
+          been provided for DOS formatted floppy diskettes. 
+
+          File splitting is a newer derivative of spanning.  
+          Splitting follows the same segmentation process as
+          spanning, however, it does not require writing each
+          segment to a unique removable medium and instead supports
+          placing all pieces onto local or non-removable locations
+          such as file systems, local drives, folders, etc...
+
+          A key difference between spanned and split ZIP files is
+          that all pieces of a spanned ZIP file have the same name.  
+          Since each piece is written to a separate volume, no name 
+          collisions occur and each segment can reuse the original 
+          .ZIP file name given to the archive.
+
+          Sequence ordering for DOS spanned archives uses the DOS 
+          volume label to determine segment numbers.  Volume labels
+          for each segment are written using the form PKBACK#xxx, 
+          where xxx is the segment number written as a decimal 
+          value from 001 - nnn.
+
+          Split ZIP files are typically written to the same location
+          and are subject to name collisions if the spanned name
+          format is used since each segment will reside on the same 
+          drive. To avoid name collisions, split archives are named 
+          as follows.
+
+          Segment 1   = filename.z01
+          Segment n-1 = filename.z(n-1)
+          Segment n   = filename.zip
+
+          The .ZIP extension is used on the last segment to support
+          quickly reading the central directory.  The segment number
+          n should be a decimal value.
+
+          Spanned ZIP files may be PKSFX Self-extracting ZIP files.
+          PKSFX files may also be split, however, in this case
+          the first segment must be named filename.exe.  The first
+          segment of a split PKSFX archive must be large enough to
+          include the entire executable program.
+
+          Capacities for split archives are as follows.
+
+          Maximum number of segments = 4,294,967,295 - 1
+          Maximum .ZIP segment size = 4,294,967,295 bytes
+          Minimum segment size = 64K
+          Maximum PKSFX segment size = 2,147,483,647 bytes
+          
+          Segment sizes may be different however by convention, all 
+          segment sizes should be the same with the exception of the 
+          last, which may be smaller.  Local and central directory 
+          header records must never be split across a segment boundary. 
+          When writing a header record, if the number of bytes remaining 
+          within a segment is less than the size of the header record,
+          end the current segment and write the header at the start
+          of the next segment.  The central directory may span segment
+          boundaries, but no single record in the central directory
+          should be split across segments.
+
+          Spanned/Split archives created using PKZIP for Windows
+          (V2.50 or greater), PKZIP Command Line (V2.50 or greater),
+          or PKZIP Explorer will include a special spanning 
+          signature as the first 4 bytes of the first segment of
+          the archive.  This signature (0x08074b50) will be 
+          followed immediately by the local header signature for
+          the first file in the archive.  
+
+          A special spanning marker may also appear in spanned/split 
+          archives if the spanning or splitting process starts but 
+          only requires one segment.  In this case the 0x08074b50 
+          signature will be replaced with the temporary spanning 
+          marker signature of 0x30304b50.  Split archives can
+          only be uncompressed by other versions of PKZIP that
+          know how to create a split archive.
+
+          The signature value 0x08074b50 is also used by some
+          ZIP implementations as a marker for the Data Descriptor 
+          record.  Conflict in this alternate assignment can be
+          avoided by ensuring the position of the signature
+          within the ZIP file to determine the use for which it
+          is intended.  
+
+  L.  General notes:
+
+      1)  All fields unless otherwise noted are unsigned and stored
+          in Intel low-byte:high-byte, low-word:high-word order.
+
+      2)  String fields are not null terminated, since the
+          length is given explicitly.
+
+      3)  The entries in the central directory may not necessarily
+          be in the same order that files appear in the .ZIP file.
+
+      4)  If one of the fields in the end of central directory
+          record is too small to hold required data, the field
+          should be set to -1 (0xFFFF or 0xFFFFFFFF) and the
+          ZIP64 format record should be created.
+
+      5)  The end of central directory record and the
+          Zip64 end of central directory locator record must
+          reside on the same disk when splitting or spanning
+          an archive.
+
+VI. UnShrinking - Method 1
+--------------------------
+
+Shrinking is a Dynamic Ziv-Lempel-Welch compression algorithm
+with partial clearing.  The initial code size is 9 bits, and
+the maximum code size is 13 bits.  Shrinking differs from
+conventional Dynamic Ziv-Lempel-Welch implementations in several
+respects:
+
+1)  The code size is controlled by the compressor, and is not
+    automatically increased when codes larger than the current
+    code size are created (but not necessarily used).  When
+    the decompressor encounters the code sequence 256
+    (decimal) followed by 1, it should increase the code size
+    read from the input stream to the next bit size.  No
+    blocking of the codes is performed, so the next code at
+    the increased size should be read from the input stream
+    immediately after where the previous code at the smaller
+    bit size was read.  Again, the decompressor should not
+    increase the code size used until the sequence 256,1 is
+    encountered.
+
+2)  When the table becomes full, total clearing is not
+    performed.  Rather, when the compressor emits the code
+    sequence 256,2 (decimal), the decompressor should clear
+    all leaf nodes from the Ziv-Lempel tree, and continue to
+    use the current code size.  The nodes that are cleared
+    from the Ziv-Lempel tree are then re-used, with the lowest
+    code value re-used first, and the highest code value
+    re-used last.  The compressor can emit the sequence 256,2
+    at any time.
+
+VII. Expanding - Methods 2-5
+----------------------------
+
+The Reducing algorithm is actually a combination of two
+distinct algorithms.  The first algorithm compresses repeated
+byte sequences, and the second algorithm takes the compressed
+stream from the first algorithm and applies a probabilistic
+compression method.
+
+The probabilistic compression stores an array of 'follower
+sets' S(j), for j=0 to 255, corresponding to each possible
+ASCII character.  Each set contains between 0 and 32
+characters, to be denoted as S(j)[0],...,S(j)[m], where m<32.
+The sets are stored at the beginning of the data area for a
+Reduced file, in reverse order, with S(255) first, and S(0)
+last.
+
+The sets are encoded as { N(j), S(j)[0],...,S(j)[N(j)-1] },
+where N(j) is the size of set S(j).  N(j) can be 0, in which
+case the follower set for S(j) is empty.  Each N(j) value is
+encoded in 6 bits, followed by N(j) eight bit character values
+corresponding to S(j)[0] to S(j)[N(j)-1] respectively.  If
+N(j) is 0, then no values for S(j) are stored, and the value
+for N(j-1) immediately follows.
+
+Immediately after the follower sets, is the compressed data
+stream.  The compressed data stream can be interpreted for the
+probabilistic decompression as follows:
+
+let Last-Character <- 0.
+loop until done
+    if the follower set S(Last-Character) is empty then
+        read 8 bits from the input stream, and copy this
+        value to the output stream.
+    otherwise if the follower set S(Last-Character) is non-empty then
+        read 1 bit from the input stream.
+        if this bit is not zero then
+            read 8 bits from the input stream, and copy this
+            value to the output stream.
+        otherwise if this bit is zero then
+            read B(N(Last-Character)) bits from the input
+            stream, and assign this value to I.
+            Copy the value of S(Last-Character)[I] to the
+            output stream.
+
+    assign the last value placed on the output stream to
+    Last-Character.
+end loop
+
+B(N(j)) is defined as the minimal number of bits required to
+encode the value N(j)-1.
+
+The decompressed stream from above can then be expanded to
+re-create the original file as follows:
+
+let State <- 0.
+
+loop until done
+    read 8 bits from the input stream into C.
+    case State of
+        0:  if C is not equal to DLE (144 decimal) then
+                copy C to the output stream.
+            otherwise if C is equal to DLE then
+                let State <- 1.
+
+        1:  if C is non-zero then
+                let V <- C.
+                let Len <- L(V)
+                let State <- F(Len).
+            otherwise if C is zero then
+                copy the value 144 (decimal) to the output stream.
+                let State <- 0
+
+        2:  let Len <- Len + C
+            let State <- 3.
+
+        3:  move backwards D(V,C) bytes in the output stream
+            (if this position is before the start of the output
+            stream, then assume that all the data before the
+            start of the output stream is filled with zeros).
+            copy Len+3 bytes from this position to the output stream.
+            let State <- 0.
+    end case
+end loop
+
+The functions F,L, and D are dependent on the 'compression
+factor', 1 through 4, and are defined as follows:
+
+For compression factor 1:
+    L(X) equals the lower 7 bits of X.
+    F(X) equals 2 if X equals 127 otherwise F(X) equals 3.
+    D(X,Y) equals the (upper 1 bit of X) * 256 + Y + 1.
+For compression factor 2:
+    L(X) equals the lower 6 bits of X.
+    F(X) equals 2 if X equals 63 otherwise F(X) equals 3.
+    D(X,Y) equals the (upper 2 bits of X) * 256 + Y + 1.
+For compression factor 3:
+    L(X) equals the lower 5 bits of X.
+    F(X) equals 2 if X equals 31 otherwise F(X) equals 3.
+    D(X,Y) equals the (upper 3 bits of X) * 256 + Y + 1.
+For compression factor 4:
+    L(X) equals the lower 4 bits of X.
+    F(X) equals 2 if X equals 15 otherwise F(X) equals 3.
+    D(X,Y) equals the (upper 4 bits of X) * 256 + Y + 1.
+
+VIII. Imploding - Method 6
+--------------------------
+
+The Imploding algorithm is actually a combination of two distinct
+algorithms.  The first algorithm compresses repeated byte
+sequences using a sliding dictionary.  The second algorithm is
+used to compress the encoding of the sliding dictionary output,
+using multiple Shannon-Fano trees.
+
+The Imploding algorithm can use a 4K or 8K sliding dictionary
+size. The dictionary size used can be determined by bit 1 in the
+general purpose flag word; a 0 bit indicates a 4K dictionary
+while a 1 bit indicates an 8K dictionary.
+
+The Shannon-Fano trees are stored at the start of the compressed
+file. The number of trees stored is defined by bit 2 in the
+general purpose flag word; a 0 bit indicates two trees stored, a
+1 bit indicates three trees are stored.  If 3 trees are stored,
+the first Shannon-Fano tree represents the encoding of the
+Literal characters, the second tree represents the encoding of
+the Length information, the third represents the encoding of the
+Distance information.  When 2 Shannon-Fano trees are stored, the
+Length tree is stored first, followed by the Distance tree.
+
+The Literal Shannon-Fano tree, if present is used to represent
+the entire ASCII character set, and contains 256 values.  This
+tree is used to compress any data not compressed by the sliding
+dictionary algorithm.  When this tree is present, the Minimum
+Match Length for the sliding dictionary is 3.  If this tree is
+not present, the Minimum Match Length is 2.
+
+The Length Shannon-Fano tree is used to compress the Length part
+of the (length,distance) pairs from the sliding dictionary
+output.  The Length tree contains 64 values, ranging from the
+Minimum Match Length, to 63 plus the Minimum Match Length.
+
+The Distance Shannon-Fano tree is used to compress the Distance
+part of the (length,distance) pairs from the sliding dictionary
+output. The Distance tree contains 64 values, ranging from 0 to
+63, representing the upper 6 bits of the distance value.  The
+distance values themselves will be between 0 and the sliding
+dictionary size, either 4K or 8K.
+
+The Shannon-Fano trees themselves are stored in a compressed
+format. The first byte of the tree data represents the number of
+bytes of data representing the (compressed) Shannon-Fano tree
+minus 1.  The remaining bytes represent the Shannon-Fano tree
+data encoded as:
+
+    High 4 bits: Number of values at this bit length + 1. (1 - 16)
+    Low  4 bits: Bit Length needed to represent value + 1. (1 - 16)
+
+The Shannon-Fano codes can be constructed from the bit lengths
+using the following algorithm:
+
+1)  Sort the Bit Lengths in ascending order, while retaining the
+    order of the original lengths stored in the file.
+
+2)  Generate the Shannon-Fano trees:
+
+    Code <- 0
+    CodeIncrement <- 0
+    LastBitLength <- 0
+    i <- number of Shannon-Fano codes - 1   (either 255 or 63)
+
+    loop while i >= 0
+        Code = Code + CodeIncrement
+        if BitLength(i) <> LastBitLength then
+            LastBitLength=BitLength(i)
+            CodeIncrement = 1 shifted left (16 - LastBitLength)
+        ShannonCode(i) = Code
+        i <- i - 1
+    end loop
+
+3)  Reverse the order of all the bits in the above ShannonCode()
+    vector, so that the most significant bit becomes the least
+    significant bit.  For example, the value 0x1234 (hex) would
+    become 0x2C48 (hex).
+
+4)  Restore the order of Shannon-Fano codes as originally stored
+    within the file.
+
+Example:
+
+    This example will show the encoding of a Shannon-Fano tree
+    of size 8.  Notice that the actual Shannon-Fano trees used
+    for Imploding are either 64 or 256 entries in size.
+
+Example:   0x02, 0x42, 0x01, 0x13
+
+    The first byte indicates 3 values in this table.  Decoding the
+    bytes:
+            0x42 = 5 codes of 3 bits long
+            0x01 = 1 code  of 2 bits long
+            0x13 = 2 codes of 4 bits long
+
+    This would generate the original bit length array of:
+    (3, 3, 3, 3, 3, 2, 4, 4)
+
+    There are 8 codes in this table for the values 0 thru 7.  Using 
+    the algorithm to obtain the Shannon-Fano codes produces:
+
+                                  Reversed     Order     Original
+Val  Sorted   Constructed Code      Value     Restored    Length
+---  ------   -----------------   --------    --------    ------
+0:     2      1100000000000000        11       101          3
+1:     3      1010000000000000       101       001          3
+2:     3      1000000000000000       001       110          3
+3:     3      0110000000000000       110       010          3
+4:     3      0100000000000000       010       100          3
+5:     3      0010000000000000       100        11          2
+6:     4      0001000000000000      1000      1000          4
+7:     4      0000000000000000      0000      0000          4
+
+The values in the Val, Order Restored and Original Length columns
+now represent the Shannon-Fano encoding tree that can be used for
+decoding the Shannon-Fano encoded data.  How to parse the
+variable length Shannon-Fano values from the data stream is beyond
+the scope of this document.  (See the references listed at the end of
+this document for more information.)  However, traditional decoding
+schemes used for Huffman variable length decoding, such as the
+Greenlaw algorithm, can be successfully applied.
+
+The compressed data stream begins immediately after the
+compressed Shannon-Fano data.  The compressed data stream can be
+interpreted as follows:
+
+loop until done
+    read 1 bit from input stream.
+
+    if this bit is non-zero then       (encoded data is literal data)
+        if Literal Shannon-Fano tree is present
+            read and decode character using Literal Shannon-Fano tree.
+        otherwise
+            read 8 bits from input stream.
+        copy character to the output stream.
+    otherwise              (encoded data is sliding dictionary match)
+        if 8K dictionary size
+            read 7 bits for offset Distance (lower 7 bits of offset).
+        otherwise
+            read 6 bits for offset Distance (lower 6 bits of offset).
+
+        using the Distance Shannon-Fano tree, read and decode the
+          upper 6 bits of the Distance value.
+
+        using the Length Shannon-Fano tree, read and decode
+          the Length value.
+
+        Length <- Length + Minimum Match Length
+
+        if Length = 63 + Minimum Match Length
+            read 8 bits from the input stream,
+            add this value to Length.
+
+        move backwards Distance+1 bytes in the output stream, and
+        copy Length characters from this position to the output
+        stream.  (if this position is before the start of the output
+        stream, then assume that all the data before the start of
+        the output stream is filled with zeros).
+end loop
+
+IX. Tokenizing - Method 7
+-------------------------
+
+This method is not used by PKZIP.
+
+X. Deflating - Method 8
+-----------------------
+
+The Deflate algorithm is similar to the Implode algorithm using
+a sliding dictionary of up to 32K with secondary compression
+from Huffman/Shannon-Fano codes.
+
+The compressed data is stored in blocks with a header describing
+the block and the Huffman codes used in the data block.  The header
+format is as follows:
+
+   Bit 0: Last Block bit     This bit is set to 1 if this is the last
+                             compressed block in the data.
+   Bits 1-2: Block type
+      00 (0) - Block is stored - All stored data is byte aligned.
+               Skip bits until next byte, then next word = block 
+               length, followed by the ones compliment of the block
+               length word. Remaining data in block is the stored 
+               data.
+
+      01 (1) - Use fixed Huffman codes for literal and distance codes.
+               Lit Code    Bits             Dist Code   Bits
+               ---------   ----             ---------   ----
+                 0 - 143    8                 0 - 31      5
+               144 - 255    9
+               256 - 279    7
+               280 - 287    8
+
+               Literal codes 286-287 and distance codes 30-31 are 
+               never used but participate in the huffman construction.
+
+      10 (2) - Dynamic Huffman codes.  (See expanding Huffman codes)
+
+      11 (3) - Reserved - Flag a "Error in compressed data" if seen.
+
+Expanding Huffman Codes
+-----------------------
+If the data block is stored with dynamic Huffman codes, the Huffman
+codes are sent in the following compressed format:
+
+   5 Bits: # of Literal codes sent - 256 (256 - 286)
+           All other codes are never sent.
+   5 Bits: # of Dist codes - 1           (1 - 32)
+   4 Bits: # of Bit Length codes - 3     (3 - 19)
+
+The Huffman codes are sent as bit lengths and the codes are built as
+described in the implode algorithm.  The bit lengths themselves are
+compressed with Huffman codes.  There are 19 bit length codes:
+
+   0 - 15: Represent bit lengths of 0 - 15
+       16: Copy the previous bit length 3 - 6 times.
+           The next 2 bits indicate repeat length (0 = 3, ... ,3 = 6)
+              Example:  Codes 8, 16 (+2 bits 11), 16 (+2 bits 10) will
+                        expand to 12 bit lengths of 8 (1 + 6 + 5)
+       17: Repeat a bit length of 0 for 3 - 10 times. (3 bits of length)
+       18: Repeat a bit length of 0 for 11 - 138 times (7 bits of length)
+
+The lengths of the bit length codes are sent packed 3 bits per value
+(0 - 7) in the following order:
+
+   16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
+
+The Huffman codes should be built as described in the Implode algorithm
+except codes are assigned starting at the shortest bit length, i.e. the
+shortest code should be all 0's rather than all 1's.  Also, codes with
+a bit length of zero do not participate in the tree construction.  The
+codes are then used to decode the bit lengths for the literal and 
+distance tables.
+
+The bit lengths for the literal tables are sent first with the number
+of entries sent described by the 5 bits sent earlier.  There are up
+to 286 literal characters; the first 256 represent the respective 8
+bit character, code 256 represents the End-Of-Block code, the remaining
+29 codes represent copy lengths of 3 thru 258.  There are up to 30
+distance codes representing distances from 1 thru 32k as described
+below.
+
+                             Length Codes
+                             ------------
+      Extra             Extra              Extra              Extra
+ Code Bits Length  Code Bits Lengths  Code Bits Lengths  Code Bits Length(s)
+ ---- ---- ------  ---- ---- -------  ---- ---- -------  ---- ---- ---------
+  257   0     3     265   1   11,12    273   3   35-42    281   5  131-162
+  258   0     4     266   1   13,14    274   3   43-50    282   5  163-194
+  259   0     5     267   1   15,16    275   3   51-58    283   5  195-226
+  260   0     6     268   1   17,18    276   3   59-66    284   5  227-257
+  261   0     7     269   2   19-22    277   4   67-82    285   0    258
+  262   0     8     270   2   23-26    278   4   83-98
+  263   0     9     271   2   27-30    279   4   99-114
+  264   0    10     272   2   31-34    280   4  115-130
+
+                            Distance Codes
+                            --------------
+      Extra           Extra             Extra               Extra
+ Code Bits Dist  Code Bits  Dist   Code Bits Distance  Code Bits Distance
+ ---- ---- ----  ---- ---- ------  ---- ---- --------  ---- ---- --------
+   0   0    1      8   3   17-24    16    7  257-384    24   11  4097-6144
+   1   0    2      9   3   25-32    17    7  385-512    25   11  6145-8192
+   2   0    3     10   4   33-48    18    8  513-768    26   12  8193-12288
+   3   0    4     11   4   49-64    19    8  769-1024   27   12 12289-16384
+   4   1   5,6    12   5   65-96    20    9 1025-1536   28   13 16385-24576
+   5   1   7,8    13   5   97-128   21    9 1537-2048   29   13 24577-32768
+   6   2   9-12   14   6  129-192   22   10 2049-3072
+   7   2  13-16   15   6  193-256   23   10 3073-4096
+
+The compressed data stream begins immediately after the
+compressed header data.  The compressed data stream can be
+interpreted as follows:
+
+do
+   read header from input stream.
+
+   if stored block
+      skip bits until byte aligned
+      read count and 1's compliment of count
+      copy count bytes data block
+   otherwise
+      loop until end of block code sent
+         decode literal character from input stream
+         if literal < 256
+            copy character to the output stream
+         otherwise
+            if literal = end of block
+               break from loop
+            otherwise
+               decode distance from input stream
+
+               move backwards distance bytes in the output stream, and
+               copy length characters from this position to the output
+               stream.
+      end loop
+while not last block
+
+if data descriptor exists
+   skip bits until byte aligned
+   read crc and sizes
+endif
+
+XI. Enhanced Deflating - Method 9
+---------------------------------
+
+The Enhanced Deflating algorithm is similar to Deflate but
+uses a sliding dictionary of up to 64K. Deflate64(tm) is supported
+by the Deflate extractor. 
+
+XII. BZIP2 - Method 12
+----------------------
+
+BZIP2 is an open-source data compression algorithm developed by 
+Julian Seward.  Information and source code for this algorithm
+can be found on the internet.
+
+XIII. LZMA - Method 14 (EFS)
+----------------------------
+
+LZMA is a block-oriented, general purpose data compression algorithm  
+developed and maintained by Igor Pavlov.  It is a derivative of LZ77
+that utilizes Markov chains and a range coder.  Information and 
+source code for this algorithm can be found on the internet.  Consult 
+with the author of this algorithm for information on terms or 
+restrictions on use.
+
+Support for LZMA within the ZIP format is defined as follows:   
+
+The Compression method field within the ZIP Local and Central 
+Header records will be set to the value 14 to indicate data was
+compressed using LZMA. 
+
+The Version needed to extract field within the ZIP Local and 
+Central Header records will be set to 6.3 to indicate the 
+minimum ZIP format version supporting this feature.
+
+File data compressed using the LZMA algorithm must be placed 
+immediately following the Local Header for the file.  If a 
+standard ZIP encryption header is required, it will follow 
+the Local Header and will precede the LZMA compressed file 
+data segment.  The location of LZMA compressed data segment 
+within the ZIP format will be as shown:
+
+    [local header file 1]
+    [encryption header file 1]
+    [LZMA compressed data segment for file 1]
+    [data descriptor 1]
+    [local header file 2]
+
+The encryption header and data descriptor records may
+be conditionally present.  The LZMA Compressed Data Segment 
+will consist of an LZMA Properties Header followed by the 
+LZMA Compressed Data as shown:
+
+    [LZMA properties header for file 1]
+    [LZMA compressed data for file 1]
+
+The LZMA Compressed Data will be stored as provided by the 
+LZMA compression library.  Compressed size, uncompressed 
+size and other file characteristics about the file being 
+compressed must be stored in standard ZIP storage format.
+
+The LZMA Properties Header will store specific data required to 
+decompress the LZMA compressed Data.  This data is set by the 
+LZMA compression engine using the function WriteCoderProperties() 
+as documented within the LZMA SDK. 
+ 
+Storage fields for the property information within the LZMA 
+Properties Header are as follows:
+
+     LZMA Version Information 2 bytes
+     LZMA Properties Size 2 bytes
+     LZMA Properties Data variable, defined by "LZMA Properties Size"
+
+LZMA Version Information - this field identifies which version of 
+     the LZMA SDK was used to compress a file.  The first byte will 
+     store the major version number of the LZMA SDK and the second 
+     byte will store the minor number.  
+
+LZMA Properties Size - this field defines the size of the remaining 
+     property data.  Typically this size should be determined by the 
+     version of the SDK.  This size field is included as a convenience
+     and to help avoid any ambiguity should it arise in the future due
+     to changes in this compression algorithm. 
+
+LZMA Property Data - this variable sized field records the required 
+     values for the decompressor as defined by the LZMA SDK.  The 
+     data stored in this field should be obtained using the 
+     WriteCoderProperties() in the version of the SDK defined by 
+     the "LZMA Version Information" field.  
+
+The layout of the "LZMA Properties Data" field is a function of the
+LZMA compression algorithm.  It is possible that this layout may be
+changed by the author over time.  The data layout in version 4.32 
+of the LZMA SDK defines a 5 byte array that uses 4 bytes to store 
+the dictionary size in little-endian order. This is preceded by a 
+single packed byte as the first element of the array that contains
+the following fields:
+
+     PosStateBits
+     LiteralPosStateBits
+     LiteralContextBits
+
+Refer to the LZMA documentation for a more detailed explanation of 
+these fields.  
+
+Data compressed with method 14, LZMA, may include an end-of-stream
+(EOS) marker ending the compressed data stream.  This marker is not
+required, but its use is highly recommended to facilitate processing
+and implementers should include the EOS marker whenever possible.
+When the EOS marker is used, general purpose bit 1 must be set.  If
+general purpose bit 1 is not set, the EOS marker is not present.
+
+XIV. PPMd - Method 98
+---------------------
+
+PPMd is a data compression algorithm developed by Dmitry Shkarin
+which includes a carryless rangecoder developed by Dmitry Subbotin.
+This algorithm is based on predictive phrase matching on multiple
+order contexts.  Information and source code for this algorithm
+can be found on the internet. Consult with the author of this
+algorithm for information on terms or restrictions on use.
+
+Support for PPMd within the ZIP format currently is provided only 
+for version I, revision 1 of the algorithm.  Storage requirements
+for using this algorithm are as follows:
+
+Parameters needed to control the algorithm are stored in the two
+bytes immediately preceding the compressed data.  These bytes are
+used to store the following fields:
+
+Model order - sets the maximum model order, default is 8, possible
+              values are from 2 to 16 inclusive
+
+Sub-allocator size - sets the size of sub-allocator in MB, default is 50,
+            possible values are from 1MB to 256MB inclusive
+
+Model restoration method - sets the method used to restart context
+            model at memory insufficiency, values are:
+
+            0 - restarts model from scratch - default
+            1 - cut off model - decreases performance by as much as 2x
+            2 - freeze context tree - not recommended
+
+An example for packing these fields into the 2 byte storage field is
+illustrated below.  These values are stored in Intel low-byte/high-byte
+order.
+
+wPPMd = (Model order - 1) + 
+        ((Sub-allocator size - 1) << 4) + 
+        (Model restoration method << 12)
+
+
+XV. Traditional PKWARE Encryption
+---------------------------------
+
+The following information discusses the decryption steps
+required to support traditional PKWARE encryption.  This
+form of encryption is considered weak by today's standards
+and its use is recommended only for situations with
+low security needs or for compatibility with older .ZIP 
+applications.
+
+Decryption
+----------
+
+PKWARE is grateful to Mr. Roger Schlafly for his expert contribution 
+towards the development of PKWARE's traditional encryption.
+
+PKZIP encrypts the compressed data stream.  Encrypted files must
+be decrypted before they can be extracted.
+
+Each encrypted file has an extra 12 bytes stored at the start of
+the data area defining the encryption header for that file.  The
+encryption header is originally set to random values, and then
+itself encrypted, using three, 32-bit keys.  The key values are
+initialized using the supplied encryption password.  After each byte
+is encrypted, the keys are then updated using pseudo-random number
+generation techniques in combination with the same CRC-32 algorithm
+used in PKZIP and described elsewhere in this document.
+
+The following is the basic steps required to decrypt a file:
+
+1) Initialize the three 32-bit keys with the password.
+2) Read and decrypt the 12-byte encryption header, further
+   initializing the encryption keys.
+3) Read and decrypt the compressed data stream using the
+   encryption keys.
+
+Step 1 - Initializing the encryption keys
+-----------------------------------------
+
+Key(0) <- 305419896
+Key(1) <- 591751049
+Key(2) <- 878082192
+
+loop for i <- 0 to length(password)-1
+    update_keys(password(i))
+end loop
+
+Where update_keys() is defined as:
+
+update_keys(char):
+  Key(0) <- crc32(key(0),char)
+  Key(1) <- Key(1) + (Key(0) & 000000ffH)
+  Key(1) <- Key(1) * 134775813 + 1
+  Key(2) <- crc32(key(2),key(1) >> 24)
+end update_keys
+
+Where crc32(old_crc,char) is a routine that given a CRC value and a
+character, returns an updated CRC value after applying the CRC-32
+algorithm described elsewhere in this document.
+
+Step 2 - Decrypting the encryption header
+-----------------------------------------
+
+The purpose of this step is to further initialize the encryption
+keys, based on random data, to render a plaintext attack on the
+data ineffective.
+
+Read the 12-byte encryption header into Buffer, in locations
+Buffer(0) thru Buffer(11).
+
+loop for i <- 0 to 11
+    C <- buffer(i) ^ decrypt_byte()
+    update_keys(C)
+    buffer(i) <- C
+end loop
+
+Where decrypt_byte() is defined as:
+
+unsigned char decrypt_byte()
+    local unsigned short temp
+    temp <- Key(2) | 2
+    decrypt_byte <- (temp * (temp ^ 1)) >> 8
+end decrypt_byte
+
+After the header is decrypted,  the last 1 or 2 bytes in Buffer
+should be the high-order word/byte of the CRC for the file being
+decrypted, stored in Intel low-byte/high-byte order.  Versions of
+PKZIP prior to 2.0 used a 2 byte CRC check; a 1 byte CRC check is
+used on versions after 2.0.  This can be used to test if the password
+supplied is correct or not.
+
+Step 3 - Decrypting the compressed data stream
+----------------------------------------------
+
+The compressed data stream can be decrypted as follows:
+
+loop until done
+    read a character into C
+    Temp <- C ^ decrypt_byte()
+    update_keys(temp)
+    output Temp
+end loop
+
+
+XVI. Strong Encryption Specification
+------------------------------------
+
+The Strong Encryption technology defined in this specification is 
+covered under a pending patent application. The use or implementation
+in a product of certain technological aspects set forth in the current
+APPNOTE, including those with regard to strong encryption, patching, 
+or extended tape operations requires a license from PKWARE. Portions
+of this Strong Encryption technology are available for use at no charge.
+Contact PKWARE for licensing terms and conditions. Refer to section II
+of this APPNOTE (Contacting PKWARE) for information on how to 
+contact PKWARE. 
+
+Version 5.x of this specification introduced support for strong 
+encryption algorithms.  These algorithms can be used with either 
+a password or an X.509v3 digital certificate to encrypt each file. 
+This format specification supports either password or certificate 
+based encryption to meet the security needs of today, to enable 
+interoperability between users within both PKI and non-PKI 
+environments, and to ensure interoperability between different 
+computing platforms that are running a ZIP program.  
+
+Password based encryption is the most common form of encryption 
+people are familiar with.  However, inherent weaknesses with 
+passwords (e.g. susceptibility to dictionary/brute force attack) 
+as well as password management and support issues make certificate 
+based encryption a more secure and scalable option.  Industry 
+efforts and support are defining and moving towards more advanced 
+security solutions built around X.509v3 digital certificates and 
+Public Key Infrastructures(PKI) because of the greater scalability, 
+administrative options, and more robust security over traditional 
+password based encryption. 
+
+Most standard encryption algorithms are supported with this
+specification. Reference implementations for many of these 
+algorithms are available from either commercial or open source 
+distributors.  Readily available cryptographic toolkits make
+implementation of the encryption features straight-forward.  
+This document is not intended to provide a treatise on data 
+encryption principles or theory.  Its purpose is to document the 
+data structures required for implementing interoperable data 
+encryption within the .ZIP format.  It is strongly recommended that 
+you have a good understanding of data encryption before reading 
+further.
+
+The algorithms introduced in Version 5.0 of this specification 
+include:
+
+    RC2 40 bit, 64 bit, and 128 bit
+    RC4 40 bit, 64 bit, and 128 bit
+    DES
+    3DES 112 bit and 168 bit
+  
+Version 5.1 adds support for the following:
+
+    AES 128 bit, 192 bit, and 256 bit
+
+
+Version 6.1 introduces encryption data changes to support 
+interoperability with Smartcard and USB Token certificate storage 
+methods which do not support the OAEP strengthening standard.
+
+Version 6.2 introduces support for encrypting metadata by compressing 
+and encrypting the central directory data structure to reduce information 
+leakage.   Information leakage can occur in legacy ZIP applications 
+through exposure of information about a file even though that file is 
+stored encrypted.  The information exposed consists of file 
+characteristics stored within the records and fields defined by this 
+specification.  This includes data such as a files name, its original 
+size, timestamp and CRC32 value. 
+
+Version 6.3 introduces support for encrypting data using the Blowfish
+and Twofish algorithms.  These are symmetric block ciphers developed 
+by Bruce Schneier.  Blowfish supports using a variable length key from 
+32 to 448 bits.  Block size is 64 bits.  Implementations should use 16
+rounds and the only mode supported within ZIP files is CBC. Twofish 
+supports key sizes 128, 192 and 256 bits.  Block size is 128 bits.  
+Implementations should use 16 rounds and the only mode supported within
+ZIP files is CBC.  Information and source code for both Blowfish and 
+Twofish algorithms can be found on the internet.  Consult with the author
+of these algorithms for information on terms or restrictions on use.
+
+Central Directory Encryption provides greater protection against 
+information leakage by encrypting the Central Directory structure and 
+by masking key values that are replicated in the unencrypted Local 
+Header.   ZIP compatible programs that cannot interpret an encrypted 
+Central Directory structure cannot rely on the data in the corresponding 
+Local Header for decompression information.  
+
+Extra Field records that may contain information about a file that should 
+not be exposed should not be stored in the Local Header and should only 
+be written to the Central Directory where they can be encrypted.  This 
+design currently does not support streaming.  Information in the End of 
+Central Directory record, the Zip64 End of Central Directory Locator, 
+and the Zip64 End of Central Directory records are not encrypted.  Access 
+to view data on files within a ZIP file with an encrypted Central Directory
+requires the appropriate password or private key for decryption prior to 
+viewing any files, or any information about the files, in the archive.  
+
+Older ZIP compatible programs not familiar with the Central Directory 
+Encryption feature will no longer be able to recognize the Central 
+Directory and may assume the ZIP file is corrupt.  Programs that 
+attempt streaming access using Local Headers will see invalid 
+information for each file.  Central Directory Encryption need not be 
+used for every ZIP file.  Its use is recommended for greater security.  
+ZIP files not using Central Directory Encryption should operate as 
+in the past. 
+
+This strong encryption feature specification is intended to provide for 
+scalable, cross-platform encryption needs ranging from simple password
+encryption to authenticated public/private key encryption.  
+
+Encryption provides data confidentiality and privacy.  It is 
+recommended that you combine X.509 digital signing with encryption 
+to add authentication and non-repudiation.
+
+
+Single Password Symmetric Encryption Method:
+-------------------------------------------
+
+The Single Password Symmetric Encryption Method using strong 
+encryption algorithms operates similarly to the traditional 
+PKWARE encryption defined in this format.  Additional data 
+structures are added to support the processing needs of the 
+strong algorithms.
+
+The Strong Encryption data structures are:
+
+1. General Purpose Bits - Bits 0 and 6 of the General Purpose bit 
+flag in both local and central header records.  Both bits set 
+indicates strong encryption.  Bit 13, when set indicates the Central
+Directory is encrypted and that selected fields in the Local Header
+are masked to hide their actual value.
+
+
+2. Extra Field 0x0017 in central header only.
+
+     Fields to consider in this record are:
+
+     Format - the data format identifier for this record.  The only
+     value allowed at this time is the integer value 2.
+
+     AlgId - integer identifier of the encryption algorithm from the
+     following range
+
+         0x6601 - DES
+         0x6602 - RC2 (version needed to extract < 5.2)
+         0x6603 - 3DES 168
+         0x6609 - 3DES 112
+         0x660E - AES 128 
+         0x660F - AES 192 
+         0x6610 - AES 256 
+         0x6702 - RC2 (version needed to extract >= 5.2)
+         0x6720 - Blowfish
+         0x6721 - Twofish
+         0x6801 - RC4
+         0xFFFF - Unknown algorithm
+
+     Bitlen - Explicit bit length of key
+
+         32 - 448 bits
+   
+     Flags - Processing flags needed for decryption
+
+         0x0001 - Password is required to decrypt
+         0x0002 - Certificates only
+         0x0003 - Password or certificate required to decrypt
+
+         Values > 0x0003 reserved for certificate processing
+
+
+3. Decryption header record preceding compressed file data.
+
+         -Decryption Header:
+
+          Value     Size     Description
+          -----     ----     -----------
+          IVSize    2 bytes  Size of initialization vector (IV)
+          IVData    IVSize   Initialization vector for this file
+          Size      4 bytes  Size of remaining decryption header data
+          Format    2 bytes  Format definition for this record
+          AlgID     2 bytes  Encryption algorithm identifier
+          Bitlen    2 bytes  Bit length of encryption key
+          Flags     2 bytes  Processing flags
+          ErdSize   2 bytes  Size of Encrypted Random Data
+          ErdData   ErdSize  Encrypted Random Data
+          Reserved1 4 bytes  Reserved certificate processing data
+          Reserved2 (var)    Reserved for certificate processing data
+          VSize     2 bytes  Size of password validation data
+          VData     VSize-4  Password validation data
+          VCRC32    4 bytes  Standard ZIP CRC32 of password validation data
+
+     IVData - The size of the IV should match the algorithm block size.
+              The IVData can be completely random data.  If the size of
+              the randomly generated data does not match the block size
+              it should be complemented with zero's or truncated as
+              necessary.  If IVSize is 0,then IV = CRC32 + Uncompressed
+              File Size (as a 64 bit little-endian, unsigned integer value).
+
+     Format - the data format identifier for this record.  The only
+     value allowed at this time is the integer value 3.
+
+     AlgId - integer identifier of the encryption algorithm from the
+     following range
+
+         0x6601 - DES
+         0x6602 - RC2 (version needed to extract < 5.2)
+         0x6603 - 3DES 168
+         0x6609 - 3DES 112
+         0x660E - AES 128 
+         0x660F - AES 192 
+         0x6610 - AES 256 
+         0x6702 - RC2 (version needed to extract >= 5.2)
+         0x6720 - Blowfish
+         0x6721 - Twofish
+         0x6801 - RC4
+         0xFFFF - Unknown algorithm
+
+     Bitlen - Explicit bit length of key
+
+         32 - 448 bits
+   
+     Flags - Processing flags needed for decryption
+
+         0x0001 - Password is required to decrypt
+         0x0002 - Certificates only
+         0x0003 - Password or certificate required to decrypt
+
+         Values > 0x0003 reserved for certificate processing
+
+     ErdData - Encrypted random data is used to store random data that
+               is used to generate a file session key for encrypting 
+               each file.  SHA1 is used to calculate hash data used to 
+               derive keys.  File session keys are derived from a master 
+               session key generated from the user-supplied password.
+               If the Flags field in the decryption header contains 
+               the value 0x4000, then the ErdData field must be 
+               decrypted using 3DES. If the value 0x4000 is not set,
+               then the ErdData field must be decrypted using AlgId.
+
+
+     Reserved1 - Reserved for certificate processing, if value is
+               zero, then Reserved2 data is absent.  See the explanation
+               under the Certificate Processing Method for details on
+               this data structure.
+
+     Reserved2 - If present, the size of the Reserved2 data structure 
+               is located by skipping the first 4 bytes of this field 
+               and using the next 2 bytes as the remaining size.  See
+               the explanation under the Certificate Processing Method
+               for details on this data structure.
+
+     VSize - This size value will always include the 4 bytes of the
+             VCRC32 data and will be greater than 4 bytes.
+
+     VData - Random data for password validation.  This data is VSize
+             in length and VSize must be a multiple of the encryption
+             block size.  VCRC32 is a checksum value of VData.  
+             VData and VCRC32 are stored encrypted and start the
+             stream of encrypted data for a file.
+
+
+4. Useful Tips
+
+Strong Encryption is always applied to a file after compression. The
+block oriented algorithms all operate in Cypher Block Chaining (CBC) 
+mode.  The block size used for AES encryption is 16.  All other block
+algorithms use a block size of 8.  Two ID's are defined for RC2 to 
+account for a discrepancy found in the implementation of the RC2
+algorithm in the cryptographic library on Windows XP SP1 and all 
+earlier versions of Windows.  It is recommended that zero length files
+not be encrypted, however programs should be prepared to extract them
+if they are found within a ZIP file.
+
+A pseudo-code representation of the encryption process is as follows:
+
+Password = GetUserPassword()
+MasterSessionKey = DeriveKey(SHA1(Password)) 
+RD = CryptographicStrengthRandomData() 
+For Each File
+   IV = CryptographicStrengthRandomData() 
+   VData = CryptographicStrengthRandomData()
+   VCRC32 = CRC32(VData)
+   FileSessionKey = DeriveKey(SHA1(IV + RD) 
+   ErdData = Encrypt(RD,MasterSessionKey,IV) 
+   Encrypt(VData + VCRC32 + FileData, FileSessionKey,IV)
+Done
+
+The function names and parameter requirements will depend on
+the choice of the cryptographic toolkit selected.  Almost any
+toolkit supporting the reference implementations for each
+algorithm can be used.  The RSA BSAFE(r), OpenSSL, and Microsoft
+CryptoAPI libraries are all known to work well.  
+
+
+Single Password - Central Directory Encryption:
+-----------------------------------------------
+
+Central Directory Encryption is achieved within the .ZIP format by 
+encrypting the Central Directory structure.  This encapsulates the metadata 
+most often used for processing .ZIP files.  Additional metadata is stored for 
+redundancy in the Local Header for each file.  The process of concealing 
+metadata by encrypting the Central Directory does not protect the data within 
+the Local Header.  To avoid information leakage from the exposed metadata 
+in the Local Header, the fields containing information about a file are masked.  
+
+Local Header:
+
+Masking replaces the true content of the fields for a file in the Local 
+Header with false information.  When masked, the Local Header is not 
+suitable for streaming access and the options for data recovery of damaged
+archives is reduced.  Extra Data fields that may contain confidential
+data should not be stored within the Local Header.  The value set into
+the Version needed to extract field should be the correct value needed to
+extract the file without regard to Central Directory Encryption. The fields 
+within the Local Header targeted for masking when the Central Directory is 
+encrypted are:
+
+        Field Name                     Mask Value
+        ------------------             ---------------------------
+        compression method              0
+        last mod file time              0
+        last mod file date              0
+        crc-32                          0
+        compressed size                 0
+        uncompressed size               0
+        file name (variable size)       Base 16 value from the
+                                        range 1 - 0xFFFFFFFFFFFFFFFF
+                                        represented as a string whose
+                                        size will be set into the
+                                        file name length field
+
+The Base 16 value assigned as a masked file name is simply a sequentially
+incremented value for each file starting with 1 for the first file.  
+Modifications to a ZIP file may cause different values to be stored for 
+each file.  For compatibility, the file name field in the Local Header 
+should never be left blank.  As of Version 6.2 of this specification, 
+the Compression Method and Compressed Size fields are not yet masked.
+Fields having a value of 0xFFFF or 0xFFFFFFFF for the ZIP64 format
+should not be masked.  
+
+Encrypting the Central Directory:
+
+Encryption of the Central Directory does not include encryption of the 
+Central Directory Signature data, the Zip64 End of Central Directory
+record, the Zip64 End of Central Directory Locator, or the End
+of Central Directory record.  The ZIP file comment data is never
+encrypted.
+
+Before encrypting the Central Directory, it may optionally be compressed.
+Compression is not required, but for storage efficiency it is assumed
+this structure will be compressed before encrypting.  Similarly, this 
+specification supports compressing the Central Directory without
+requiring that it also be encrypted.  Early implementations of this
+feature will assume the encryption method applied to files matches the 
+encryption applied to the Central Directory.
+
+Encryption of the Central Directory is done in a manner similar to
+that of file encryption.  The encrypted data is preceded by a 
+decryption header.  The decryption header is known as the Archive
+Decryption Header.  The fields of this record are identical to
+the decryption header preceding each encrypted file.  The location
+of the Archive Decryption Header is determined by the value in the
+Start of the Central Directory field in the Zip64 End of Central
+Directory record.  When the Central Directory is encrypted, the
+Zip64 End of Central Directory record will always be present.
+
+The layout of the Zip64 End of Central Directory record for all
+versions starting with 6.2 of this specification will follow the
+Version 2 format.  The Version 2 format is as follows:
+
+The leading fixed size fields within the Version 1 format for this
+record remain unchanged.  The record signature for both Version 1 
+and Version 2 will be 0x06064b50.  Immediately following the last
+byte of the field known as the Offset of Start of Central 
+Directory With Respect to the Starting Disk Number will begin the 
+new fields defining Version 2 of this record.  
+
+New fields for Version 2:
+
+Note: all fields stored in Intel low-byte/high-byte order.
+
+          Value                 Size       Description
+          -----                 ----       -----------
+          Compression Method    2 bytes    Method used to compress the
+                                           Central Directory
+          Compressed Size       8 bytes    Size of the compressed data
+          Original   Size       8 bytes    Original uncompressed size
+          AlgId                 2 bytes    Encryption algorithm ID
+          BitLen                2 bytes    Encryption key length
+          Flags                 2 bytes    Encryption flags
+          HashID                2 bytes    Hash algorithm identifier
+          Hash Length           2 bytes    Length of hash data
+          Hash Data             (variable) Hash data
+
+The Compression Method accepts the same range of values as the 
+corresponding field in the Central Header.
+
+The Compressed Size and Original Size values will not include the
+data of the Central Directory Signature which is compressed or
+encrypted.
+
+The AlgId, BitLen, and Flags fields accept the same range of values
+the corresponding fields within the 0x0017 record. 
+
+Hash ID identifies the algorithm used to hash the Central Directory 
+data.  This data does not have to be hashed, in which case the
+values for both the HashID and Hash Length will be 0.  Possible 
+values for HashID are:
+
+      Value         Algorithm
+     ------         ---------
+     0x0000          none
+     0x0001          CRC32
+     0x8003          MD5
+     0x8004          SHA1
+     0x8007          RIPEMD160
+     0x8012          SHA256
+     0x8013          SHA384
+     0x8015          SHA512
+
+When the Central Directory data is signed, the same hash algorithm
+used to hash the Central Directory for signing should be used.
+This is recommended for processing efficiency, however, it is 
+permissible for any of the above algorithms to be used independent 
+of the signing process.
+
+The Hash Data will contain the hash data for the Central Directory.
+The length of this data will vary depending on the algorithm used.
+
+The Version Needed to Extract should be set to 62.
+
+The value for the Total Number of Entries on the Current Disk will
+be 0.  These records will no longer support random access when
+encrypting the Central Directory.
+
+When the Central Directory is compressed and/or encrypted, the
+End of Central Directory record will store the value 0xFFFFFFFF
+as the value for the Total Number of Entries in the Central
+Directory.  The value stored in the Total Number of Entries in
+the Central Directory on this Disk field will be 0.  The actual
+values will be stored in the equivalent fields of the Zip64
+End of Central Directory record.
+
+Decrypting and decompressing the Central Directory is accomplished
+in the same manner as decrypting and decompressing a file.
+
+Certificate Processing Method:
+-----------------------------
+
+The Certificate Processing Method of for ZIP file encryption 
+defines the following additional data fields:
+
+1. Certificate Flag Values
+
+Additional processing flags that can be present in the Flags field of both 
+the 0x0017 field of the central directory Extra Field and the Decryption 
+header record preceding compressed file data are:
+
+         0x0007 - reserved for future use
+         0x000F - reserved for future use
+         0x0100 - Indicates non-OAEP key wrapping was used.  If this
+                  this field is set, the version needed to extract must
+                  be at least 61.  This means OAEP key wrapping is not
+                  used when generating a Master Session Key using
+                  ErdData.
+         0x4000 - ErdData must be decrypted using 3DES-168, otherwise use the
+                  same algorithm used for encrypting the file contents.
+         0x8000 - reserved for future use
+
+
+2. CertData - Extra Field 0x0017 record certificate data structure
+
+The data structure used to store certificate data within the section
+of the Extra Field defined by the CertData field of the 0x0017
+record are as shown:
+
+          Value     Size     Description
+          -----     ----     -----------
+          RCount    4 bytes  Number of recipients.  
+          HashAlg   2 bytes  Hash algorithm identifier
+          HSize     2 bytes  Hash size
+          SRList    (var)    Simple list of recipients hashed public keys
+
+          
+     RCount    This defines the number intended recipients whose 
+               public keys were used for encryption.  This identifies
+               the number of elements in the SRList.
+
+     HashAlg   This defines the hash algorithm used to calculate
+               the public key hash of each public key used
+               for encryption. This field currently supports
+               only the following value for SHA-1
+
+               0x8004 - SHA1
+
+     HSize     This defines the size of a hashed public key.
+
+     SRList    This is a variable length list of the hashed 
+               public keys for each intended recipient.  Each 
+               element in this list is HSize.  The total size of 
+               SRList is determined using RCount * HSize.
+
+
+3. Reserved1 - Certificate Decryption Header Reserved1 Data:
+
+          Value     Size     Description
+          -----     ----     -----------
+          RCount    4 bytes  Number of recipients.  
+          
+     RCount    This defines the number intended recipients whose 
+               public keys were used for encryption.  This defines
+               the number of elements in the REList field defined below.
+
+
+4. Reserved2 - Certificate Decryption Header Reserved2 Data Structures:
+
+
+          Value     Size     Description
+          -----     ----     -----------
+          HashAlg   2 bytes  Hash algorithm identifier
+          HSize     2 bytes  Hash size
+          REList    (var)    List of recipient data elements
+
+
+     HashAlg   This defines the hash algorithm used to calculate
+               the public key hash of each public key used
+               for encryption. This field currently supports
+               only the following value for SHA-1
+
+               0x8004 - SHA1
+
+     HSize     This defines the size of a hashed public key
+               defined in REHData.
+
+     REList    This is a variable length of list of recipient data.  
+               Each element in this list consists of a Recipient
+               Element data structure as follows:
+
+
+    Recipient Element (REList) Data Structure:
+
+          Value     Size     Description
+          -----     ----     -----------
+          RESize    2 bytes  Size of REHData + REKData
+          REHData   HSize    Hash of recipients public key
+          REKData   (var)    Simple key blob
+
+
+     RESize    This defines the size of an individual REList 
+               element.  This value is the combined size of the
+               REHData field + REKData field.  REHData is defined by
+               HSize.  REKData is variable and can be calculated
+               for each REList element using RESize and HSize.
+
+     REHData   Hashed public key for this recipient.
+
+     REKData   Simple Key Blob.  The format of this data structure
+               is identical to that defined in the Microsoft
+               CryptoAPI and generated using the CryptExportKey()
+               function.  The version of the Simple Key Blob
+               supported at this time is 0x02 as defined by
+               Microsoft.
+
+Certificate Processing - Central Directory Encryption:
+------------------------------------------------------
+
+Central Directory Encryption using Digital Certificates will 
+operate in a manner similar to that of Single Password Central
+Directory Encryption.  This record will only be present when there 
+is data to place into it.  Currently, data is placed into this
+record when digital certificates are used for either encrypting 
+or signing the files within a ZIP file.  When only password 
+encryption is used with no certificate encryption or digital 
+signing, this record is not currently needed. When present, this 
+record will appear before the start of the actual Central Directory 
+data structure and will be located immediately after the Archive 
+Decryption Header if the Central Directory is encrypted.
+
+The Archive Extra Data record will be used to store the following
+information.  Additional data may be added in future versions.
+
+Extra Data Fields:
+
+0x0014 - PKCS#7 Store for X.509 Certificates
+0x0016 - X.509 Certificate ID and Signature for central directory
+0x0019 - PKCS#7 Encryption Recipient Certificate List
+
+The 0x0014 and 0x0016 Extra Data records that otherwise would be 
+located in the first record of the Central Directory for digital 
+certificate processing. When encrypting or compressing the Central 
+Directory, the 0x0014 and 0x0016 records must be located in the 
+Archive Extra Data record and they should not remain in the first 
+Central Directory record.  The Archive Extra Data record will also 
+be used to store the 0x0019 data. 
+
+When present, the size of the Archive Extra Data record will be
+included in the size of the Central Directory.  The data of the
+Archive Extra Data record will also be compressed and encrypted
+along with the Central Directory data structure.
+
+Certificate Processing Differences:
+
+The Certificate Processing Method of encryption differs from the
+Single Password Symmetric Encryption Method as follows.  Instead
+of using a user-defined password to generate a master session key,
+cryptographically random data is used.  The key material is then
+wrapped using standard key-wrapping techniques.  This key material
+is wrapped using the public key of each recipient that will need
+to decrypt the file using their corresponding private key.
+
+This specification currently assumes digital certificates will follow
+the X.509 V3 format for 1024 bit and higher RSA format digital
+certificates.  Implementation of this Certificate Processing Method
+requires supporting logic for key access and management.  This logic
+is outside the scope of this specification.
+
+OAEP Processing with Certificate-based Encryption:
+
+OAEP stands for Optimal Asymmetric Encryption Padding.  It is a
+strengthening technique used for small encoded items such as decryption
+keys.  This is commonly applied in cryptographic key-wrapping techniques
+and is supported by PKCS #1.  Versions 5.0 and 6.0 of this specification 
+were designed to support OAEP key-wrapping for certificate-based 
+decryption keys for additional security.  
+
+Support for private keys stored on Smartcards or Tokens introduced
+a conflict with this OAEP logic.  Most card and token products do 
+not support the additional strengthening applied to OAEP key-wrapped 
+data.  In order to resolve this conflict, versions 6.1 and above of this 
+specification will no longer support OAEP when encrypting using 
+digital certificates. 
+
+Versions of PKZIP available during initial development of the 
+certificate processing method set a value of 61 into the 
+version needed to extract field for a file.  This indicates that 
+non-OAEP key wrapping is used.  This affects certificate encryption 
+only, and password encryption functions should not be affected by 
+this value.  This means values of 61 may be found on files encrypted
+with certificates only, or on files encrypted with both password
+encryption and certificate encryption.  Files encrypted with both
+methods can safely be decrypted using the password methods documented.
+
+XVII. Change Process
+--------------------
+
+In order for the .ZIP file format to remain a viable definition, this
+specification should be considered as open for periodic review and
+revision.  Although this format was originally designed with a 
+certain level of extensibility, not all changes in technology
+(present or future) were or will be necessarily considered in its
+design.  If your application requires new definitions to the
+extensible sections in this format, or if you would like to 
+submit new data structures, please forward your request to
+zipformat@pkware.com.  All submissions will be reviewed by the
+ZIP File Specification Committee for possible inclusion into
+future versions of this specification.  Periodic revisions
+to this specification will be published to ensure interoperability. 
+We encourage comments and feedback that may help improve clarity 
+or content.
+
+XVIII. Incorporating PKWARE Proprietary Technology into Your Product
+--------------------------------------------------------------------
+
+PKWARE is committed to the interoperability and advancement of the
+.ZIP format.  PKWARE offers a free license for certain technological
+aspects described above under certain restrictions and conditions.
+However, the use or implementation in a product of certain technological
+aspects set forth in the current APPNOTE, including those with regard to
+strong encryption, patching, or extended tape operations requires a 
+license from PKWARE.  Please contact PKWARE with regard to acquiring
+a license.
+
+XIX. Acknowledgements
+----------------------
+
+In addition to the above mentioned contributors to PKZIP and PKUNZIP,
+I would like to extend special thanks to Robert Mahoney for suggesting
+the extension .ZIP for this software.
+
+XX. References
+--------------
+
+    Fiala, Edward R., and Greene, Daniel H., "Data compression with
+       finite windows",  Communications of the ACM, Volume 32, Number 4,
+       April 1989, pages 490-505.
+
+    Held, Gilbert, "Data Compression, Techniques and Applications,
+       Hardware and Software Considerations", John Wiley & Sons, 1987.
+
+    Huffman, D.A., "A method for the construction of minimum-redundancy
+       codes", Proceedings of the IRE, Volume 40, Number 9, September 1952,
+       pages 1098-1101.
+
+    Nelson, Mark, "LZW Data Compression", Dr. Dobbs Journal, Volume 14,
+       Number 10, October 1989, pages 29-37.
+
+    Nelson, Mark, "The Data Compression Book",  M&T Books, 1991.
+
+    Storer, James A., "Data Compression, Methods and Theory",
+       Computer Science Press, 1988
+
+    Welch, Terry, "A Technique for High-Performance Data Compression",
+       IEEE Computer, Volume 17, Number 6, June 1984, pages 8-19.
+
+    Ziv, J. and Lempel, A., "A universal algorithm for sequential data
+       compression", Communications of the ACM, Volume 30, Number 6,
+       June 1987, pages 520-540.
+
+    Ziv, J. and Lempel, A., "Compression of individual sequences via
+       variable-rate coding", IEEE Transactions on Information Theory,
+       Volume 24, Number 5, September 1978, pages 530-536.
+
+
+APPENDIX A - AS/400 Extra Field (0x0065) Attribute Definitions
+--------------------------------------------------------------
+
+Field Definition Structure:
+
+   a. field length including length             2 bytes
+   b. field code                                2 bytes
+   c. data                                      x bytes
+
+Field Code  Description
+   4001     Source type i.e. CLP etc
+   4002     The text description of the library 
+   4003     The text description of the file
+   4004     The text description of the member
+   4005     x'F0' or 0 is PF-DTA,  x'F1' or 1 is PF_SRC
+   4007     Database Type Code                  1 byte
+   4008     Database file and fields definition
+   4009     GZIP file type                      2 bytes
+   400B     IFS code page                       2 bytes
+   400C     IFS Creation Time                   4 bytes
+   400D     IFS Access Time                     4 bytes
+   400E     IFS Modification time               4 bytes
+   005C     Length of the records in the file   2 bytes
+   0068     GZIP two words                      8 bytes
+
+APPENDIX B - z/OS Extra Field (0x0065) Attribute Definitions
+------------------------------------------------------------
+
+Field Definition Structure:
+
+   a. field length including length             2 bytes
+   b. field code                                2 bytes
+   c. data                                      x bytes
+
+Field Code  Description
+   0001     File Type                           2 bytes 
+   0002     NonVSAM Record Format               1 byte
+   0003     Reserved		
+   0004     NonVSAM Block Size                  2 bytes Big Endian
+   0005     Primary Space Allocation            3 bytes Big Endian
+   0006     Secondary Space Allocation          3 bytes Big Endian
+   0007     Space Allocation Type1 byte flag		
+   0008     Modification Date                   Retired with PKZIP 5.0 +
+   0009     Expiration Date                     Retired with PKZIP 5.0 +
+   000A     PDS Directory Block Allocation      3 bytes Big Endian binary value
+   000B     NonVSAM Volume List                 variable		
+   000C     UNIT Reference                      Retired with PKZIP 5.0 +
+   000D     DF/SMS Management Class             8 bytes EBCDIC Text Value
+   000E     DF/SMS Storage Class                8 bytes EBCDIC Text Value
+   000F     DF/SMS Data Class                   8 bytes EBCDIC Text Value
+   0010     PDS/PDSE Member Info.               30 bytes	
+   0011     VSAM sub-filetype                   2 bytes		
+   0012     VSAM LRECL                          13 bytes EBCDIC "(num_avg num_max)"
+   0013     VSAM Cluster Name                   Retired with PKZIP 5.0 +
+   0014     VSAM KSDS Key Information           13 bytes EBCDIC "(num_length num_position)"
+   0015     VSAM Average LRECL                  5 bytes EBCDIC num_value padded with blanks
+   0016     VSAM Maximum LRECL                  5 bytes EBCDIC num_value padded with blanks
+   0017     VSAM KSDS Key Length                5 bytes EBCDIC num_value padded with blanks
+   0018     VSAM KSDS Key Position              5 bytes EBCDIC num_value padded with blanks
+   0019     VSAM Data Name                      1-44 bytes EBCDIC text string
+   001A     VSAM KSDS Index Name                1-44 bytes EBCDIC text string
+   001B     VSAM Catalog Name                   1-44 bytes EBCDIC text string
+   001C     VSAM Data Space Type                9 bytes EBCDIC text string
+   001D     VSAM Data Space Primary             9 bytes EBCDIC num_value left-justified
+   001E     VSAM Data Space Secondary           9 bytes EBCDIC num_value left-justified
+   001F     VSAM Data Volume List               variable EBCDIC text list of 6-character Volume IDs
+   0020     VSAM Data Buffer Space              8 bytes EBCDIC num_value left-justified
+   0021     VSAM Data CISIZE                    5 bytes EBCDIC num_value left-justified
+   0022     VSAM Erase Flag                     1 byte flag		
+   0023     VSAM Free CI %                      3 bytes EBCDIC num_value left-justified
+   0024     VSAM Free CA %                      3 bytes EBCDIC num_value left-justified
+   0025     VSAM Index Volume List              variable EBCDIC text list of 6-character Volume IDs
+   0026     VSAM Ordered Flag                   1 byte flag		
+   0027     VSAM REUSE Flag                     1 byte flag		
+   0028     VSAM SPANNED Flag                   1 byte flag		
+   0029     VSAM Recovery Flag                  1 byte flag		
+   002A     VSAM  WRITECHK  Flag                1 byte flag		
+   002B     VSAM Cluster/Data SHROPTS           3 bytes EBCDIC "n,y"	
+   002C     VSAM Index SHROPTS                  3 bytes EBCDIC "n,y"	
+   002D     VSAM Index Space Type               9 bytes EBCDIC text string
+   002E     VSAM Index Space Primary            9 bytes EBCDIC num_value left-justified
+   002F     VSAM Index Space Secondary          9 bytes EBCDIC num_value left-justified
+   0030     VSAM Index CISIZE                   5 bytes EBCDIC num_value left-justified
+   0031     VSAM Index IMBED                    1 byte flag		
+   0032     VSAM Index Ordered Flag             1 byte flag		
+   0033     VSAM REPLICATE Flag                 1 byte flag		
+   0034     VSAM Index REUSE Flag               1 byte flag		
+   0035     VSAM Index WRITECHK Flag            1 byte flag Retired with PKZIP 5.0 +
+   0036     VSAM Owner                          8 bytes EBCDIC text string
+   0037     VSAM Index Owner                    8 bytes EBCDIC text string
+   0038     Reserved
+   0039     Reserved
+   003A     Reserved
+   003B     Reserved
+   003C     Reserved
+   003D     Reserved
+   003E     Reserved
+   003F     Reserved
+   0040     Reserved
+   0041     Reserved
+   0042     Reserved
+   0043     Reserved
+   0044     Reserved
+   0045     Reserved
+   0046     Reserved
+   0047     Reserved
+   0048     Reserved
+   0049     Reserved
+   004A     Reserved
+   004B     Reserved
+   004C     Reserved
+   004D     Reserved
+   004E     Reserved
+   004F     Reserved
+   0050     Reserved
+   0051     Reserved
+   0052     Reserved
+   0053     Reserved
+   0054     Reserved
+   0055     Reserved
+   0056     Reserved
+   0057     Reserved
+   0058     PDS/PDSE Member TTR Info.           6 bytes  Big Endian
+   0059     PDS 1st LMOD Text TTR               3 bytes  Big Endian
+   005A     PDS LMOD EP Rec #                   4 bytes  Big Endian
+   005B     Reserved
+   005C     Max Length of records               2 bytes  Big Endian
+   005D     PDSE Flag                           1 byte flag
+   005E     Reserved
+   005F     Reserved
+   0060     Reserved
+   0061     Reserved
+   0062     Reserved
+   0063     Reserved
+   0064     Reserved
+   0065     Last Date Referenced                4 bytes  Packed Hex "yyyymmdd"
+   0066     Date Created                        4 bytes  Packed Hex "yyyymmdd"
+   0068     GZIP two words                      8 bytes
+   0071     Extended NOTE Location              12 bytes Big Endian
+   0072     Archive device UNIT                 6 bytes  EBCDIC
+   0073     Archive 1st Volume                  6 bytes  EBCDIC
+   0074     Archive 1st VOL File Seq#           2 bytes  Binary
+
+APPENDIX C - Zip64 Extensible Data Sector Mappings (EFS)
+--------------------------------------------------------
+
+          -Z390   Extra Field:
+
+          The following is the general layout of the attributes for the 
+          ZIP 64 "extra" block for extended tape operations. Portions of 
+          this extended tape processing technology is covered under a 
+          pending patent application. The use or implementation in a 
+          product of certain technological aspects set forth in the 
+          current APPNOTE, including those with regard to strong encryption,
+          patching or extended tape operations, requires a license from
+          PKWARE.  Please contact PKWARE with regard to acquiring a license. 
+ 
+
+          Note: some fields stored in Big Endian format.  All text is 
+	  in EBCDIC format unless otherwise specified.
+
+          Value       Size          Description
+          -----       ----          -----------
+  (Z390)  0x0065      2 bytes       Tag for this "extra" block type
+          Size        4 bytes       Size for the following data block
+          Tag         4 bytes       EBCDIC "Z390"
+          Length71    2 bytes       Big Endian
+          Subcode71   2 bytes       Enote type code
+          FMEPos      1 byte
+          Length72    2 bytes       Big Endian
+          Subcode72   2 bytes       Unit type code
+          Unit        1 byte        Unit
+          Length73    2 bytes       Big Endian
+          Subcode73   2 bytes       Volume1 type code
+          FirstVol    1 byte        Volume
+          Length74    2 bytes       Big Endian
+          Subcode74   2 bytes       FirstVol file sequence
+          FileSeq     2 bytes       Sequence 
+
+APPENDIX D - Language Encoding (EFS)
+------------------------------------
+
+The ZIP format has historically supported only the original IBM PC character 
+encoding set, commonly referred to as IBM Code Page 437.  This limits storing 
+file name characters to only those within the original MS-DOS range of values 
+and does not properly support file names in other character encodings, or 
+languages. To address this limitation, this specification will support the 
+following change. 
+
+If general purpose bit 11 is unset, the file name and comment should conform 
+to the original ZIP character encoding.  If general purpose bit 11 is set, the 
+filename and comment must support The Unicode Standard, Version 4.1.0 or 
+greater using the character encoding form defined by the UTF-8 storage 
+specification.  The Unicode Standard is published by the The Unicode
+Consortium (www.unicode.org).  UTF-8 encoded data stored within ZIP files 
+is expected to not include a byte order mark (BOM). 
+
+Applications may choose to supplement this file name storage through the use 
+of the 0x0008 Extra Field.  Storage for this optional field is currently 
+undefined, however it will be used to allow storing extended information 
+on source or target encoding that may further assist applications with file 
+name, or file content encoding tasks.  Please contact PKWARE with any
+requirements on how this field should be used.
+
+The 0x0008 Extra Field storage may be used with either setting for general 
+purpose bit 11.  Examples of the intended usage for this field is to store 
+whether "modified-UTF-8" (JAVA) is used, or UTF-8-MAC.  Similarly, other 
+commonly used character encoding (code page) designations can be indicated 
+through this field.  Formalized values for use of the 0x0008 record remain 
+undefined at this time.  The definition for the layout of the 0x0008 field
+will be published when available.  Use of the 0x0008 Extra Field provides
+for storing data within a ZIP file in an encoding other than IBM Code
+Page 437 or UTF-8.
+
+General purpose bit 11 will not imply any encoding of file content or
+password.  Values defining character encoding for file content or 
+password must be stored within the 0x0008 Extended Language Encoding 
+Extra Field.
+
+
diff --git a/install-sh b/install-sh
index f5061e7..4fbbae7 100755
--- a/install-sh
+++ b/install-sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 # install - install a program, script, or datafile
 
-scriptversion=2003-09-24.23
+scriptversion=2006-10-14.15
 
 # This originates from X11R5 (mit/util/scripts/install.sh), which was
 # later released in X11R6 (xc/config/util/install.sh) with the
@@ -39,15 +39,24 @@
 # when there is no Makefile.
 #
 # This script is compatible with the BSD install script, but was written
-# from scratch.  It can only install one file at a time, a restriction
-# shared with many OS's install programs.
+# from scratch.
+
+nl='
+'
+IFS=" ""	$nl"
 
 # set DOITPROG to echo to test this script
 
 # Don't use :- since 4.3BSD and earlier shells don't like it.
 doit="${DOITPROG-}"
+if test -z "$doit"; then
+  doit_exec=exec
+else
+  doit_exec=$doit
+fi
 
-# put in absolute paths if you don't have them in your path; or use env. vars.
+# Put in absolute file names if you don't have them in your path;
+# or use environment vars.
 
 mvprog="${MVPROG-mv}"
 cpprog="${CPPROG-cp}"
@@ -58,10 +67,13 @@
 rmprog="${RMPROG-rm}"
 mkdirprog="${MKDIRPROG-mkdir}"
 
-transformbasename=
-transform_arg=
-instcmd="$mvprog"
-chmodcmd="$chmodprog 0755"
+posix_glob=
+posix_mkdir=
+
+# Desired mode of installed file.
+mode=0755
+
+chmodcmd=$chmodprog
 chowncmd=
 chgrpcmd=
 stripcmd=
@@ -70,22 +82,27 @@
 src=
 dst=
 dir_arg=
+dstarg=
+no_target_directory=
 
-usage="Usage: $0 [OPTION]... SRCFILE DSTFILE
-   or: $0 -d DIR1 DIR2...
+usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
+   or: $0 [OPTION]... -d DIRECTORIES...
 
-In the first form, install SRCFILE to DSTFILE, removing SRCFILE by default.
-In the second, create the directory path DIR.
+In the 1st form, copy SRCFILE to DSTFILE.
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
+In the 4th, create DIRECTORIES.
 
 Options:
--b=TRANSFORMBASENAME
--c         copy source (using $cpprog) instead of moving (using $mvprog).
+-c         (ignored)
 -d         create directories instead of installing files.
--g GROUP   $chgrp installed files to GROUP.
--m MODE    $chmod installed files to MODE.
--o USER    $chown installed files to USER.
--s         strip installed files (using $stripprog).
--t=TRANSFORM
+-g GROUP   $chgrpprog installed files to GROUP.
+-m MODE    $chmodprog installed files to MODE.
+-o USER    $chownprog installed files to USER.
+-s         $stripprog installed files.
+-t DIRECTORY  install into DIRECTORY.
+-T         report an error if DSTFILE is a directory.
 --help     display this help and exit.
 --version  display version info and exit.
 
@@ -93,14 +110,9 @@
   CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
 "
 
-while test -n "$1"; do
+while test $# -ne 0; do
   case $1 in
-    -b=*) transformbasename=`echo $1 | sed 's/-b=//'`
-        shift
-        continue;;
-
-    -c) instcmd=$cpprog
-        shift
+    -c) shift
         continue;;
 
     -d) dir_arg=true
@@ -112,11 +124,17 @@
         shift
         continue;;
 
-    --help) echo "$usage"; exit 0;;
+    --help) echo "$usage"; exit $?;;
 
-    -m) chmodcmd="$chmodprog $2"
+    -m) mode=$2
         shift
         shift
+	case $mode in
+	  *' '* | *'	'* | *'
+'*	  | *'*'* | *'?'* | *'['*)
+	    echo "$0: invalid mode: $mode" >&2
+	    exit 1;;
+	esac
         continue;;
 
     -o) chowncmd="$chownprog $2"
@@ -128,164 +146,358 @@
         shift
         continue;;
 
-    -t=*) transformarg=`echo $1 | sed 's/-t=//'`
-        shift
-        continue;;
+    -t) dstarg=$2
+	shift
+	shift
+	continue;;
 
-    --version) echo "$0 $scriptversion"; exit 0;;
+    -T) no_target_directory=true
+	shift
+	continue;;
 
-    *)  if test -z "$src"; then
-          src=$1
-        else
-          # this colon is to work around a 386BSD /bin/sh bug
-          :
-          dst=$1
-        fi
-        shift
-        continue;;
+    --version) echo "$0 $scriptversion"; exit $?;;
+
+    --)	shift
+	break;;
+
+    -*)	echo "$0: invalid option: $1" >&2
+	exit 1;;
+
+    *)  break;;
   esac
 done
 
-if test -z "$src"; then
-  echo "$0: no input file specified." >&2
-  exit 1
-fi
-
-# Protect names starting with `-'.
-case $src in
-  -*) src=./$src ;;
-esac
-
-if test -n "$dir_arg"; then
-  dst=$src
-  src=
-
-  if test -d "$dst"; then
-    instcmd=:
-    chmodcmd=
-  else
-    instcmd=$mkdirprog
-  fi
-else
-  # Waiting for this to be detected by the "$instcmd $src $dsttmp" command
-  # might cause directories to be created, which would be especially bad
-  # if $src (and thus $dsttmp) contains '*'.
-  if test ! -f "$src" && test ! -d "$src"; then
-    echo "$0: $src does not exist." >&2
-    exit 1
-  fi
-
-  if test -z "$dst"; then
-    echo "$0: no destination specified." >&2
-    exit 1
-  fi
-
-  # Protect names starting with `-'.
-  case $dst in
-    -*) dst=./$dst ;;
-  esac
-
-  # If destination is a directory, append the input filename; won't work
-  # if double slashes aren't ignored.
-  if test -d "$dst"; then
-    dst=$dst/`basename "$src"`
-  fi
-fi
-
-# This sed command emulates the dirname command.
-dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-# Make sure that the destination directory exists.
-
-# Skip lots of stat calls in the usual case.
-if test ! -d "$dstdir"; then
-  defaultIFS='
-	'
-  IFS="${IFS-$defaultIFS}"
-
-  oIFS=$IFS
-  # Some sh's can't handle IFS=/ for some reason.
-  IFS='%'
-  set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
-  IFS=$oIFS
-
-  pathcomp=
-
-  while test $# -ne 0 ; do
-    pathcomp=$pathcomp$1
-    shift
-    test -d "$pathcomp" || $mkdirprog "$pathcomp"
-    pathcomp=$pathcomp/
+if test $# -ne 0 && test -z "$dir_arg$dstarg"; then
+  # When -d is used, all remaining arguments are directories to create.
+  # When -t is used, the destination is already specified.
+  # Otherwise, the last argument is the destination.  Remove it from $@.
+  for arg
+  do
+    if test -n "$dstarg"; then
+      # $@ is not empty: it contains at least $arg.
+      set fnord "$@" "$dstarg"
+      shift # fnord
+    fi
+    shift # arg
+    dstarg=$arg
   done
 fi
 
-if test -n "$dir_arg"; then
-  $doit $instcmd "$dst" \
-    && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
-    && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
-    && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
-    && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
-
-else
-  # If we're going to rename the final executable, determine the name now.
-  if test -z "$transformarg"; then
-    dstfile=`basename "$dst"`
-  else
-    dstfile=`basename "$dst" $transformbasename \
-             | sed $transformarg`$transformbasename
+if test $# -eq 0; then
+  if test -z "$dir_arg"; then
+    echo "$0: no input file specified." >&2
+    exit 1
   fi
+  # It's OK to call `install-sh -d' without argument.
+  # This can happen when creating conditional directories.
+  exit 0
+fi
 
-  # don't allow the sed command to completely eliminate the filename.
-  test -z "$dstfile" && dstfile=`basename "$dst"`
-
-  # Make a couple of temp file names in the proper directory.
-  dsttmp=$dstdir/_inst.$$_
-  rmtmp=$dstdir/_rm.$$_
-
-  # Trap to clean up those temp files at exit.
-  trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
+if test -z "$dir_arg"; then
   trap '(exit $?); exit' 1 2 13 15
 
-  # Move or copy the file name to the temp name
-  $doit $instcmd "$src" "$dsttmp" &&
+  # Set umask so as not to create temps with too-generous modes.
+  # However, 'strip' requires both read and write access to temps.
+  case $mode in
+    # Optimize common cases.
+    *644) cp_umask=133;;
+    *755) cp_umask=22;;
 
-  # and set any options; do chmod last to preserve setuid bits.
-  #
-  # If any of these fail, we abort the whole thing.  If we want to
-  # ignore errors from any of these, just make sure not to ignore
-  # errors from the above "$doit $instcmd $src $dsttmp" command.
-  #
-  { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
-    && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
-    && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
-    && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
+    *[0-7])
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw='% 200'
+      fi
+      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
+    *)
+      if test -z "$stripcmd"; then
+	u_plus_rw=
+      else
+	u_plus_rw=,u+rw
+      fi
+      cp_umask=$mode$u_plus_rw;;
+  esac
+fi
 
-  # Now remove or move aside any old file at destination location.  We
-  # try this two ways since rm can't unlink itself on some systems and
-  # the destination file might be busy for other reasons.  In this case,
-  # the final cleanup might fail but the new file should still install
-  # successfully.
-  {
-    if test -f "$dstdir/$dstfile"; then
-      $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
-      || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
-      || {
-	  echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
-	  (exit 1); exit
-      }
-    else
-      :
+for src
+do
+  # Protect names starting with `-'.
+  case $src in
+    -*) src=./$src ;;
+  esac
+
+  if test -n "$dir_arg"; then
+    dst=$src
+    dstdir=$dst
+    test -d "$dstdir"
+    dstdir_status=$?
+  else
+
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
+    # might cause directories to be created, which would be especially bad
+    # if $src (and thus $dsttmp) contains '*'.
+    if test ! -f "$src" && test ! -d "$src"; then
+      echo "$0: $src does not exist." >&2
+      exit 1
     fi
-  } &&
 
-  # Now rename the file to the real destination.
-  $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
-fi &&
+    if test -z "$dstarg"; then
+      echo "$0: no destination specified." >&2
+      exit 1
+    fi
 
-# The final little trick to "correctly" pass the exit status to the exit trap.
-{
-  (exit 0); exit
-}
+    dst=$dstarg
+    # Protect names starting with `-'.
+    case $dst in
+      -*) dst=./$dst ;;
+    esac
+
+    # If destination is a directory, append the input filename; won't work
+    # if double slashes aren't ignored.
+    if test -d "$dst"; then
+      if test -n "$no_target_directory"; then
+	echo "$0: $dstarg: Is a directory" >&2
+	exit 1
+      fi
+      dstdir=$dst
+      dst=$dstdir/`basename "$src"`
+      dstdir_status=0
+    else
+      # Prefer dirname, but fall back on a substitute if dirname fails.
+      dstdir=`
+	(dirname "$dst") 2>/dev/null ||
+	expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+	     X"$dst" : 'X\(//\)[^/]' \| \
+	     X"$dst" : 'X\(//\)$' \| \
+	     X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
+	echo X"$dst" |
+	    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)[^/].*/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\/\)$/{
+		   s//\1/
+		   q
+		 }
+		 /^X\(\/\).*/{
+		   s//\1/
+		   q
+		 }
+		 s/.*/./; q'
+      `
+
+      test -d "$dstdir"
+      dstdir_status=$?
+    fi
+  fi
+
+  obsolete_mkdir_used=false
+
+  if test $dstdir_status != 0; then
+    case $posix_mkdir in
+      '')
+	# Create intermediate dirs using mode 755 as modified by the umask.
+	# This is like FreeBSD 'install' as of 1997-10-28.
+	umask=`umask`
+	case $stripcmd.$umask in
+	  # Optimize common cases.
+	  *[2367][2367]) mkdir_umask=$umask;;
+	  .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
+
+	  *[0-7])
+	    mkdir_umask=`expr $umask + 22 \
+	      - $umask % 100 % 40 + $umask % 20 \
+	      - $umask % 10 % 4 + $umask % 2
+	    `;;
+	  *) mkdir_umask=$umask,go-w;;
+	esac
+
+	# With -d, create the new directory with the user-specified mode.
+	# Otherwise, rely on $mkdir_umask.
+	if test -n "$dir_arg"; then
+	  mkdir_mode=-m$mode
+	else
+	  mkdir_mode=
+	fi
+
+	posix_mkdir=false
+	case $umask in
+	  *[123567][0-7][0-7])
+	    # POSIX mkdir -p sets u+wx bits regardless of umask, which
+	    # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
+	    ;;
+	  *)
+	    tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
+	    trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
+
+	    if (umask $mkdir_umask &&
+		exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
+	    then
+	      if test -z "$dir_arg" || {
+		   # Check for POSIX incompatibilities with -m.
+		   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
+		   # other-writeable bit of parent directory when it shouldn't.
+		   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
+		   ls_ld_tmpdir=`ls -ld "$tmpdir"`
+		   case $ls_ld_tmpdir in
+		     d????-?r-*) different_mode=700;;
+		     d????-?--*) different_mode=755;;
+		     *) false;;
+		   esac &&
+		   $mkdirprog -m$different_mode -p -- "$tmpdir" && {
+		     ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
+		     test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
+		   }
+		 }
+	      then posix_mkdir=:
+	      fi
+	      rmdir "$tmpdir/d" "$tmpdir"
+	    else
+	      # Remove any dirs left behind by ancient mkdir implementations.
+	      rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
+	    fi
+	    trap '' 0;;
+	esac;;
+    esac
+
+    if
+      $posix_mkdir && (
+	umask $mkdir_umask &&
+	$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
+      )
+    then :
+    else
+
+      # The umask is ridiculous, or mkdir does not conform to POSIX,
+      # or it failed possibly due to a race condition.  Create the
+      # directory the slow way, step by step, checking for races as we go.
+
+      case $dstdir in
+	/*) prefix=/ ;;
+	-*) prefix=./ ;;
+	*)  prefix= ;;
+      esac
+
+      case $posix_glob in
+        '')
+	  if (set -f) 2>/dev/null; then
+	    posix_glob=true
+	  else
+	    posix_glob=false
+	  fi ;;
+      esac
+
+      oIFS=$IFS
+      IFS=/
+      $posix_glob && set -f
+      set fnord $dstdir
+      shift
+      $posix_glob && set +f
+      IFS=$oIFS
+
+      prefixes=
+
+      for d
+      do
+	test -z "$d" && continue
+
+	prefix=$prefix$d
+	if test -d "$prefix"; then
+	  prefixes=
+	else
+	  if $posix_mkdir; then
+	    (umask=$mkdir_umask &&
+	     $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
+	    # Don't fail if two instances are running concurrently.
+	    test -d "$prefix" || exit 1
+	  else
+	    case $prefix in
+	      *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
+	      *) qprefix=$prefix;;
+	    esac
+	    prefixes="$prefixes '$qprefix'"
+	  fi
+	fi
+	prefix=$prefix/
+      done
+
+      if test -n "$prefixes"; then
+	# Don't fail if two instances are running concurrently.
+	(umask $mkdir_umask &&
+	 eval "\$doit_exec \$mkdirprog $prefixes") ||
+	  test -d "$dstdir" || exit 1
+	obsolete_mkdir_used=true
+      fi
+    fi
+  fi
+
+  if test -n "$dir_arg"; then
+    { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
+    { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
+    { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
+      test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
+  else
+
+    # Make a couple of temp file names in the proper directory.
+    dsttmp=$dstdir/_inst.$$_
+    rmtmp=$dstdir/_rm.$$_
+
+    # Trap to clean up those temp files at exit.
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
+
+    # Copy the file name to the temp name.
+    (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
+
+    # and set any options; do chmod last to preserve setuid bits.
+    #
+    # If any of these fail, we abort the whole thing.  If we want to
+    # ignore errors from any of these, just make sure not to ignore
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
+    #
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
+      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
+      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
+      && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
+
+    # Now rename the file to the real destination.
+    { $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null \
+      || {
+	   # The rename failed, perhaps because mv can't rename something else
+	   # to itself, or perhaps because mv is so ancient that it does not
+	   # support -f.
+
+	   # Now remove or move aside any old file at destination location.
+	   # We try this two ways since rm can't unlink itself on some
+	   # systems and the destination file might be busy for other
+	   # reasons.  In this case, the final cleanup might fail but the new
+	   # file should still install successfully.
+	   {
+	     if test -f "$dst"; then
+	       $doit $rmcmd -f "$dst" 2>/dev/null \
+	       || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null \
+		     && { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }; }\
+	       || {
+		 echo "$0: cannot unlink or rename $dst" >&2
+		 (exit 1); exit 1
+	       }
+	     else
+	       :
+	     fi
+	   } &&
+
+	   # Now rename the file to the real destination.
+	   $doit $mvcmd "$dsttmp" "$dst"
+	 }
+    } || exit 1
+
+    trap '' 0
+  fi
+done
 
 # Local variables:
 # eval: (add-hook 'write-file-hooks 'time-stamp)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
new file mode 100644
index 0000000..4c97a62
--- /dev/null
+++ b/lib/CMakeLists.txt
@@ -0,0 +1,129 @@
+# $NiH$
+
+INCLUDE(CheckFunctionExists)
+
+INSTALL(FILES zip.h DESTINATION include)
+
+# from http://www.cmake.org/Wiki/CMakeMacroLibtoolFile
+MACRO(GET_TARGET_PROPERTY_WITH_DEFAULT _variable _target _property _default_value)
+  
+  GET_TARGET_PROPERTY (${_variable} ${_target} ${_property})
+  IF (${_variable} STREQUAL NOTFOUND)
+    SET (${_variable} ${_default_value})
+  ENDIF (${_variable} STREQUAL NOTFOUND)
+  
+ENDMACRO (GET_TARGET_PROPERTY_WITH_DEFAULT)
+  
+MACRO(CREATE_LIBTOOL_FILE _target _install_DIR)
+  GET_TARGET_PROPERTY(_target_location ${_target} LOCATION)
+  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_static_lib ${_target} STATIC_LIB "")
+  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dependency_libs ${_target} LT_DEPENDENCY_LIBS "")
+  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_current ${_target} LT_VERSION_CURRENT 0)
+  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_age ${_target} LT_VERSION_AGE 0)
+  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_revision ${_target} LT_VERSION_REVISION 0)
+  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_installed ${_target} LT_INSTALLED yes)
+  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_shouldnotlink ${_target} LT_SHOULDNOTLINK yes)
+  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlopen ${_target} LT_DLOPEN "")
+  GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlpreopen ${_target} LT_DLPREOPEN "")
+  GET_FILENAME_COMPONENT(_laname ${_target_location} NAME_WE)
+  GET_FILENAME_COMPONENT(_soname ${_target_location} NAME)
+  SET(_laname ${_laname}.la)
+  FILE(WRITE ${_laname} "# ${_laname} - a libtool library file, generated by cmake \n")
+  FILE(APPEND ${_laname} "# The name that we can dlopen(3).\n")
+  FILE(APPEND ${_laname} "dlname='${_soname}'\n")
+  FILE(APPEND ${_laname} "# Names of this library\n")
+  FILE(APPEND ${_laname} "library_names='${_soname}.${_target_current}.${_target_age}.${_target_revision} ${_soname}.${_target_current} ${_soname}'\n")
+  FILE(APPEND ${_laname} "# The name of the static archive\n")
+  FILE(APPEND ${_laname} "old_library='${_target_static_lib}'\n")
+  FILE(APPEND ${_laname} "# Libraries that this one depends upon.\n")
+  FILE(APPEND ${_laname} "dependency_libs='${_target_dependency_libs}'\n")
+  FILE(APPEND ${_laname} "# Version information.\n")
+  FILE(APPEND ${_laname} "current=${_target_current}\n")
+  FILE(APPEND ${_laname} "age=${_target_age}\n")
+  FILE(APPEND ${_laname} "revision=${_target_revision}\n")
+  FILE(APPEND ${_laname} "# Is this an already installed library?\n")
+  FILE(APPEND ${_laname} "installed=${_target_installed}\n")
+  FILE(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\n")
+  FILE(APPEND ${_laname} "shouldnotlink=${_target_shouldnotlink}\n")
+  FILE(APPEND ${_laname} "# Files to dlopen/dlpreopen\n")
+  FILE(APPEND ${_laname} "dlopen='${_target_dlopen}'\n")
+  FILE(APPEND ${_laname} "dlpreopen='${_target_dlpreopen}'\n")
+  FILE(APPEND ${_laname} "# Directory that this library needs to be installed in:\n")
+  FILE(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}/${_install_DIR}'\n")
+  INSTALL( FILES ${_laname} ${_soname}
+    DESTINATION ${CMAKE_INSTALL_PREFIX}${_install_DIR})
+ENDMACRO(CREATE_LIBTOOL_FILE)
+ 
+SET(LIBZIP_SOURCES
+  zip_add.c
+  zip_add_dir.c
+  zip_close.c
+  zip_delete.c
+  zip_dirent.c
+  zip_entry_free.c
+  zip_entry_new.c
+  ${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c
+  zip_error.c
+  zip_error_clear.c
+  zip_error_get.c
+  zip_error_get_sys_type.c
+  zip_error_strerror.c
+  zip_error_to_str.c
+  zip_fclose.c
+  zip_file_error_clear.c
+  zip_file_error_get.c
+  zip_file_get_offset.c
+  zip_file_strerror.c
+  zip_fopen.c
+  zip_fopen_index.c
+  zip_fread.c
+  zip_free.c
+  zip_get_archive_comment.c
+  zip_get_file_comment.c
+  zip_get_num_files.c
+  zip_get_name.c
+  zip_memdup.c
+  zip_name_locate.c
+  zip_new.c
+  zip_open.c
+  zip_rename.c
+  zip_replace.c
+  zip_set_archive_comment.c
+  zip_set_file_comment.c
+  zip_source_buffer.c
+  zip_source_file.c
+  zip_source_filep.c
+  zip_source_free.c
+  zip_source_function.c
+  zip_source_zip.c
+  zip_set_name.c
+  zip_stat.c
+  zip_stat_index.c
+  zip_stat_init.c
+  zip_strerror.c
+  zip_unchange.c
+  zip_unchange_all.c
+  zip_unchange_archive.c
+  zip_unchange_data.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
+  ${CMAKE_CURRENT_BINARY_DIR}/..)
+
+# XXX: distribute instead?
+ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c
+  COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/make_zip_err_str.sh
+    ${CMAKE_CURRENT_SOURCE_DIR}/zip.h
+    ${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c
+  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/zip.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/make_zip_err_str.sh
+)
+CHECK_FUNCTION_EXISTS(mkstemp HAVE_MKSTEMP)
+IF(NOT HAVE_MKSTEMP)
+  SET(LIBZIP_EXTRA_FILES mkstemp.c)
+ENDIF(NOT HAVE_MKSTEMP)
+
+ADD_LIBRARY(zip SHARED ${LIBZIP_SOURCES} ${LIBZIP_EXTRA_FILES})
+SET_TARGET_PROPERTIES(zip PROPERTIES VERSION 1.0 SOVERSION 1 )
+TARGET_LINK_LIBRARIES(zip z)
+#CREATE_LIBTOOL_FILE(zip lib)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index f7441a9..7ec890a 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -2,55 +2,65 @@
 noinst_HEADERS = zipint.h
 include_HEADERS = zip.h
 
-libzip_la_LDFLAGS=-version-info 0:5
+libzip_la_LDFLAGS=-version-info 1:0
+libzip_la_LIBADD=@LIBOBJS@
 
 libzip_la_SOURCES=\
 	zip_add.c \
-	zip_add_data.c \
-	zip_add_file.c \
-	zip_add_filep.c \
-	zip_add_zip.c \
+	zip_add_dir.c \
 	zip_close.c \
 	zip_delete.c \
 	zip_dirent.c \
+	zip_entry_free.c \
+	zip_entry_new.c \
 	zip_err_str.c \
 	zip_error.c \
-	zip_error_str.c \
+	zip_error_clear.c \
+	zip_error_get.c \
+	zip_error_get_sys_type.c \
 	zip_error_strerror.c \
-	zip_error_sys_type.c \
+	zip_error_to_str.c \
 	zip_fclose.c \
-	zip_file_get_error.c \
+	zip_file_error_clear.c \
+	zip_file_error_get.c \
 	zip_file_get_offset.c \
 	zip_file_strerror.c \
 	zip_fopen.c \
 	zip_fopen_index.c \
 	zip_fread.c \
 	zip_free.c \
-	zip_free_entry.c \
-	zip_get_error.c \
+	zip_get_archive_comment.c \
+	zip_get_file_comment.c \
 	zip_get_num_files.c \
 	zip_get_name.c \
+	zip_memdup.c \
 	zip_name_locate.c \
 	zip_new.c \
-	zip_new_entry.c \
 	zip_open.c \
 	zip_rename.c \
 	zip_replace.c \
-	zip_replace_data.c \
-	zip_replace_file.c \
-	zip_replace_filep.c \
-	zip_replace_zip.c \
+	zip_set_archive_comment.c \
+	zip_set_file_comment.c \
+	zip_source_buffer.c \
+	zip_source_file.c \
+	zip_source_filep.c \
+	zip_source_free.c \
+	zip_source_function.c \
+	zip_source_zip.c \
 	zip_set_name.c \
 	zip_stat.c \
 	zip_stat_index.c \
+	zip_stat_init.c \
 	zip_strerror.c \
 	zip_unchange.c \
 	zip_unchange_all.c \
+	zip_unchange_archive.c \
 	zip_unchange_data.c
 
 BUILT_SOURCES=zip_err_str.c
 
-EXTRA_DIST=make_zip_err_str.sh
+EXTRA_DIST=	CMakeLists.txt \
+		make_zip_err_str.sh
 
 zip_err_str.c: zip.h make_zip_err_str.sh
-	$(srcdir)/make_zip_err_str.sh $(srcdir)/zip.h zip_err_str.c
+	sh $(srcdir)/make_zip_err_str.sh $(srcdir)/zip.h zip_err_str.c
diff --git a/lib/make_zip_err_str.sh b/lib/make_zip_err_str.sh
index 1c8ce0c..18ec5d1 100755
--- a/lib/make_zip_err_str.sh
+++ b/lib/make_zip_err_str.sh
@@ -1,5 +1,39 @@
 #!/bin/sh
 
+#  $NiH: make_zip_err_str.sh,v 1.7 2004/04/25 16:20:16 dillo Exp $
+#
+#  make_zip_err_str.sh: create zip_err_str.c from zip.h
+#  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+#
+#  This file is part of libzip, a library to manipulate ZIP archives.
+#  The authors can be contacted at <nih@giga.or.at>
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#  1. Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#  3. The names of the authors may not be used to endorse or promote
+#     products derived from this software without specific prior
+#     written permission.
+# 
+#  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+#  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+#  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+#  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+#  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+#  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
 if [ "$#" -ne 2 ]
 then
     echo "Usage: $0 in_file out_file" >&2
@@ -13,9 +47,17 @@
     exit 1
 fi
 
+rcsid=`echo '$NiH: make_zip_err_str.sh,v 1.7 2004/04/25 16:20:16 dillo Exp $' | tr -d '$'`
+inrcsid=`sed -n 's/^  \$\([^$]*[^ ]\) *\$$/\1/p' "$1"`
+
 cat <<EOF >> "$2.$$" || exit 1
-/* This file was generated automatically by $0
-   from $1; make changes there. */
+/*
+   This file was generated automatically by $0
+   from $1; make changes there.
+
+	$rcsid
+	$inrcsid
+ */
 
 #include "zip.h"
 #include "zipint.h"
@@ -25,7 +67,7 @@
 const char * const _zip_err_str[] = {
 EOF
 
-sed -n  '/^#define ZERR_/ s/.*\/\* . \([^*]*\) \*\//    "\1",/p' "$1" \
+sed -n  '/^#define ZIP_ER_/ s/.*\/\* . \([^*]*\) \*\//    "\1",/p' "$1" \
     >> "$2.$$" || exit 1
 
 cat <<EOF >> "$2.$$" || exit 1
@@ -35,12 +77,12 @@
 
 #define N ZIP_ET_NONE
 #define S ZIP_ET_SYS
-#define Z ZIP_ET_ZIP
+#define Z ZIP_ET_ZLIB
 
 const int _zip_err_type[] = {
 EOF
 
-sed -n  '/^#define ZERR_/ s/.*\/\* \(.\) \([^*]*\) \*\//    \1,/p' "$1" \
+sed -n  '/^#define ZIP_ER_/ s/.*\/\* \(.\) \([^*]*\) \*\//    \1,/p' "$1" \
     >> "$2.$$" || exit 1
 
 echo '};' >> "$2.$$" || exit 1
diff --git a/lib/mkstemp.c b/lib/mkstemp.c
new file mode 100644
index 0000000..ba68860
--- /dev/null
+++ b/lib/mkstemp.c
@@ -0,0 +1,134 @@
+/* $NiH: mkstemp.c,v 1.3 2006/04/23 14:51:45 wiz Exp $ */
+
+/* Adapted from NetBSB libc by Dieter Baron */
+
+/*	NetBSD: gettemp.c,v 1.13 2003/12/05 00:57:36 uebayasi Exp 	*/
+
+/*
+ * Copyright (c) 1987, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+_zip_mkstemp(char *path)
+{
+	int fd;   
+	char *start, *trv;
+	struct stat sbuf;
+	pid_t pid;
+
+	/* To guarantee multiple calls generate unique names even if
+	   the file is not created. 676 different possibilities with 7
+	   or more X's, 26 with 6 or less. */
+	static char xtra[2] = "aa";
+	int xcnt = 0;
+
+	pid = getpid();
+
+	/* Move to end of path and count trailing X's. */
+	for (trv = path; *trv; ++trv)
+		if (*trv == 'X')
+			xcnt++;
+		else
+			xcnt = 0;	
+
+	/* Use at least one from xtra.  Use 2 if more than 6 X's. */
+	if (*(trv - 1) == 'X')
+		*--trv = xtra[0];
+	if (xcnt > 6 && *(trv - 1) == 'X')
+		*--trv = xtra[1];
+
+	/* Set remaining X's to pid digits with 0's to the left. */
+	while (*--trv == 'X') {
+		*trv = (pid % 10) + '0';
+		pid /= 10;
+	}
+
+	/* update xtra for next call. */
+	if (xtra[0] != 'z')
+		xtra[0]++;
+	else {
+		xtra[0] = 'a';
+		if (xtra[1] != 'z')
+			xtra[1]++;
+		else
+			xtra[1] = 'a';
+	}
+
+	/*
+	 * check the target directory; if you have six X's and it
+	 * doesn't exist this runs for a *very* long time.
+	 */
+	for (start = trv + 1;; --trv) {
+		if (trv <= path)
+			break;
+		if (*trv == '/') {
+			*trv = '\0';
+			if (stat(path, &sbuf))
+				return (0);
+			if (!S_ISDIR(sbuf.st_mode)) {
+				errno = ENOTDIR;
+				return (0);
+			}
+			*trv = '/';
+			break;
+		}
+	}
+
+	for (;;) {
+		if ((fd = open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)
+			return (fd);
+		if (errno != EEXIST)
+			return (0);
+
+		/* tricky little algorithm for backward compatibility */
+		for (trv = start;;) {
+			if (!*trv)
+				return (0);
+			if (*trv == 'z')
+				*trv++ = 'a';
+			else {
+				if (isdigit((unsigned char)*trv))
+					*trv = 'a';
+				else
+					++*trv;
+				break;
+			}
+		}
+	}
+	/*NOTREACHED*/
+}
diff --git a/lib/zip.h b/lib/zip.h
index 03c34bf..9fe5c1b 100644
--- a/lib/zip.h
+++ b/lib/zip.h
@@ -2,10 +2,10 @@
 #define _HAD_ZIP_H
 
 /*
-  $NiH: zip.h,v 1.35.4.5 2004/04/08 16:53:07 dillo Exp $
+  $NiH: zip.h,v 1.59 2006/10/04 15:21:09 dillo Exp $
 
   zip.h -- exported declarations.
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -38,9 +38,12 @@
 
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include <sys/types.h>
 #include <stdio.h>
-#include <zlib.h>
 #include <time.h>
 
 /* flags for zip_open */
@@ -54,44 +57,42 @@
 
 #define ZIP_FL_NOCASE		1 /* ignore case on name lookup */
 #define ZIP_FL_NODIR		2 /* ignore directory component */
-#define ZIP_FL_COMPRESSED	4 /* read compressed data (XXX: rename) */
+#define ZIP_FL_COMPRESSED	4 /* read compressed data */
 #define ZIP_FL_UNCHANGED	8 /* use original data, ignoring changes */
 
-/* flags for zip_add and zip_replace */
-
-#define ZIP_CH_ISCOMP	1	/* data returned by ch_func is compressed */
-
 /* libzip error codes */
 
-#define ZERR_OK               0  /* N No error */
-#define ZERR_MULTIDISK        1  /* N Multi-disk zip archives not supported */
-#define ZERR_RENAME           2  /* S Renaming temporary file failed */
-#define ZERR_CLOSE            3  /* S Closing zip archive failed */
-#define ZERR_SEEK             4  /* S Seek error */
-#define ZERR_READ             5  /* S Read error */
-#define ZERR_WRITE            6  /* S Write error */
-#define ZERR_CRC              7  /* N CRC error */
-#define ZERR_ZIPCLOSED        8  /* N Containing zip archive was closed */
-#define ZERR_NOENT            9  /* N No such file */
-#define ZERR_EXISTS          10  /* N File already exists */
-#define ZERR_OPEN            11  /* S Can't open file */
-#define ZERR_TMPOPEN         12  /* S Failure to create temporary file */
-#define ZERR_ZLIB            13  /* Z Zlib error */
-#define ZERR_MEMORY          14  /* N Malloc failure */
-#define ZERR_CHANGED         15  /* N Entry has been changed */
-#define ZERR_COMPNOTSUPP     16  /* N Compression method not supported */
-#define ZERR_EOF             17  /* N Premature EOF */
-#define ZERR_INVAL           18  /* N Invalid argument */
-#define ZERR_NOZIP           19  /* N Not a zip archive */
-#define ZERR_INTERNAL        20  /* N Internal error */
-#define ZERR_INCONS	     21  /* N Zip archive inconsistent */
+#define ZIP_ER_OK             0  /* N No error */
+#define ZIP_ER_MULTIDISK      1  /* N Multi-disk zip archives not supported */
+#define ZIP_ER_RENAME         2  /* S Renaming temporary file failed */
+#define ZIP_ER_CLOSE          3  /* S Closing zip archive failed */
+#define ZIP_ER_SEEK           4  /* S Seek error */
+#define ZIP_ER_READ           5  /* S Read error */
+#define ZIP_ER_WRITE          6  /* S Write error */
+#define ZIP_ER_CRC            7  /* N CRC error */
+#define ZIP_ER_ZIPCLOSED      8  /* N Containing zip archive was closed */
+#define ZIP_ER_NOENT          9  /* N No such file */
+#define ZIP_ER_EXISTS        10  /* N File already exists */
+#define ZIP_ER_OPEN          11  /* S Can't open file */
+#define ZIP_ER_TMPOPEN       12  /* S Failure to create temporary file */
+#define ZIP_ER_ZLIB          13  /* Z Zlib error */
+#define ZIP_ER_MEMORY        14  /* N Malloc failure */
+#define ZIP_ER_CHANGED       15  /* N Entry has been changed */
+#define ZIP_ER_COMPNOTSUPP   16  /* N Compression method not supported */
+#define ZIP_ER_EOF           17  /* N Premature EOF */
+#define ZIP_ER_INVAL         18  /* N Invalid argument */
+#define ZIP_ER_NOZIP         19  /* N Not a zip archive */
+#define ZIP_ER_INTERNAL      20  /* N Internal error */
+#define ZIP_ER_INCONS        21  /* N Zip archive inconsistent */
+#define ZIP_ER_REMOVE        22  /* S Can't remove file */
+#define ZIP_ER_DELETED       23  /* N Entry has been deleted */
 
 
 /* type of system error value */
 
 #define ZIP_ET_NONE	      0  /* sys_err unused */
 #define ZIP_ET_SYS	      1  /* sys_err is errno */
-#define ZIP_ET_ZIP	      2  /* sys_err is zlib error code */
+#define ZIP_ET_ZLIB	      2  /* sys_err is zlib error code */
 
 /* compression methods */
 
@@ -103,21 +104,43 @@
 #define ZIP_CM_REDUCE_3	       4  /* reduced with factor 3 */
 #define ZIP_CM_REDUCE_4	       5  /* reduced with factor 4 */
 #define ZIP_CM_IMPLODE	       6  /* imploded */
+/* 7 - Reserved for Tokenizing compression algorithm */
 #define ZIP_CM_DEFLATE	       8  /* deflated */
 #define ZIP_CM_DEFLATE64       9  /* deflate64 */
 #define ZIP_CM_PKWARE_IMPLODE 10  /* PKWARE imploding */
+/* 11 - Reserved by PKWARE */
+#define ZIP_CM_BZIP2          12  /* compressed using BZIP2 algorithm */
+
+/* encryption methods */
+
+#define ZIP_EM_NONE	       0  /* not encrypted */
+#define ZIP_EM_TRAD_PKWARE     1  /* traditional PKWARE encryption */
+#if 0 /* Strong Encryption Header not parsed yet */
+#define ZIP_EM_DES        0x6601  /* strong encryption: DES */
+#define ZIP_EM_RC2_OLD    0x6602  /* strong encryption: RC2, version < 5.2 */
+#define ZIP_EM_3DES_168   0x6603
+#define ZIP_EM_3DES_112   0x6609
+#define ZIP_EM_AES_128    0x660e
+#define ZIP_EM_AES_192    0x660f
+#define ZIP_EM_AES_256    0x6610
+#define ZIP_EM_RC2        0x6702  /* strong encryption: RC2, version >= 5.2 */
+#define ZIP_EM_RC4        0x6801
+#endif
+#define ZIP_EM_UNKNOWN    0xffff  /* unknown algorithm */
 
 
 
-enum zip_cmd {
-    ZIP_CMD_INIT,	/* prepare for reading */
-    ZIP_CMD_READ, 	/* read data */
-    ZIP_CMD_CLOSE,	/* close and cleanup */
-    ZIP_CMD_STAT	/* for compressed data */
+enum zip_source_cmd {
+    ZIP_SOURCE_OPEN,	/* prepare for reading */
+    ZIP_SOURCE_READ, 	/* read data */
+    ZIP_SOURCE_CLOSE,	/* reading is done */
+    ZIP_SOURCE_STAT,	/* get meta information */
+    ZIP_SOURCE_ERROR,	/* get error information */
+    ZIP_SOURCE_FREE	/* cleanup and free resources */
 };
 
-typedef ssize_t (*zip_read_func)(void *state, void *data,
-				 size_t len, enum zip_cmd cmd);
+typedef ssize_t (*zip_source_callback)(void *state, void *data,
+				       size_t len, enum zip_source_cmd cmd);
 
 struct zip_stat {
     const char *name;			/* name of the file */
@@ -127,44 +150,58 @@
     off_t size;				/* size of file (uncompressed) */
     off_t comp_size;			/* size of file (compressed) */
     unsigned short comp_method;		/* compression method used */
+    unsigned short encryption_method;	/* encryption method used */
 };
 
 struct zip;
 struct zip_file;
+struct zip_source;
 
 
 
-int zip_add(struct zip *, const char *, zip_read_func, void *, int);
-int zip_add_data(struct zip *, const char *, const void *, off_t, int);
-int zip_add_file(struct zip *, const char *, const char *, off_t, off_t);
-int zip_add_filep(struct zip *, const char *, FILE *, off_t, off_t);
-int zip_add_zip(struct zip *, const char *, struct zip *, int, int,
-		off_t, off_t);
+int zip_add(struct zip *, const char *, struct zip_source *);
+int zip_add_dir(struct zip *, const char *);
 int zip_close(struct zip *);
 int zip_delete(struct zip *, int);
-int zip_error_str(char *, size_t, int, int);
-int zip_error_sys_type(int);
+void zip_error_clear(struct zip *);
+void zip_error_get(struct zip *, int *, int *);
+int zip_error_get_sys_type(int);
+int zip_error_to_str(char *, size_t, int, int);
 int zip_fclose(struct zip_file *);
-void zip_file_get_error(struct zip_file *, int *, int *);
+void zip_file_error_clear(struct zip_file *);
+void zip_file_error_get(struct zip_file *, int *, int *);
 const char *zip_file_strerror(struct zip_file *);
 struct zip_file *zip_fopen(struct zip *, const char *, int);
 struct zip_file *zip_fopen_index(struct zip *, int, int);
 ssize_t zip_fread(struct zip_file *, void *, size_t);
-void zip_get_error(struct zip *, int *, int *);
-const char *zip_get_name(struct zip *, int);
+const char *zip_get_archive_comment(struct zip *, int *, int);
+const char *zip_get_file_comment(struct zip *, int, int *, int);
+const char *zip_get_name(struct zip *, int, int);
 int zip_get_num_files(struct zip *);
 int zip_name_locate(struct zip *, const char *, int);
 struct zip *zip_open(const char *, int, int *);
 int zip_rename(struct zip *, int, const char *);
-int zip_replace(struct zip *, int, zip_read_func, void *, int);
-int zip_replace_data(struct zip *, int, const void *, off_t, int);
-int zip_replace_file(struct zip *, int, const char *, off_t, off_t);
-int zip_replace_filep(struct zip *, int, FILE *, off_t, off_t);
-int zip_replace_zip(struct zip *, int, struct zip *, int, int, off_t, off_t);
+int zip_replace(struct zip *, int, struct zip_source *);
+int zip_set_archive_comment(struct zip *, const char *, int);
+int zip_set_file_comment(struct zip *, int, const char *, int);
+struct zip_source *zip_source_buffer(struct zip *, const void *, off_t, int);
+struct zip_source *zip_source_file(struct zip *, const char *, off_t, off_t);
+struct zip_source *zip_source_filep(struct zip *, FILE *, off_t, off_t);
+void zip_source_free(struct zip_source *);
+struct zip_source *zip_source_function(struct zip *,
+				       zip_source_callback, void *);
+struct zip_source *zip_source_zip(struct zip *, struct zip *, int, int,
+				  off_t, off_t);
 int zip_stat(struct zip *, const char *, int, struct zip_stat *);
 int zip_stat_index(struct zip *, int, int, struct zip_stat *);
+void zip_stat_init(struct zip_stat *);
 const char *zip_strerror(struct zip *);
 int zip_unchange(struct zip *, int);
 int zip_unchange_all(struct zip *);
+int zip_unchange_archive(struct zip *);
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* _HAD_ZIP_H */
diff --git a/lib/zip_add.c b/lib/zip_add.c
index c27fbe7..76ec6cb 100644
--- a/lib/zip_add.c
+++ b/lib/zip_add.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_add.c,v 1.9 2003/10/02 14:13:28 dillo Exp $
+  $NiH: zip_add.c,v 1.13 2004/11/17 21:55:09 wiz Exp $
 
   zip_add.c -- add file via callback function
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -41,13 +41,12 @@
 
 
 int
-zip_add(struct zip *zf, const char *name,
-	zip_read_func fn, void *state, int flags)
+zip_add(struct zip *za, const char *name, struct zip_source *source)
 {
-    if (name == NULL) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
+    if (name == NULL || source == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
 	return -1;
     }
 	
-    return _zip_replace(zf, -1, name, fn, state, flags);
+    return _zip_replace(za, -1, name, source);
 }
diff --git a/lib/zip_add_data.c b/lib/zip_add_data.c
deleted file mode 100644
index a4b0b81..0000000
--- a/lib/zip_add_data.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-  $NiH: zip_add_data.c,v 1.6 2003/10/02 14:13:28 dillo Exp $
-
-  zip_add_data.c -- add file from buffer
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
-
-  This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-  1. Redistributions of source code must retain the above copyright
-     notice, this list of conditions and the following disclaimer.
-  2. Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in
-     the documentation and/or other materials provided with the
-     distribution.
-  3. The names of the authors may not be used to endorse or promote
-     products derived from this software without specific prior
-     written permission.
- 
-  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
-  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
-  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-
-#include "zip.h"
-#include "zipint.h"
-
-
-
-int
-zip_add_data(struct zip *zf, const char *name,
-	     const void *data, off_t len, int freep)
-{
-    if (name == NULL) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
-	return -1;
-    }
-
-    return _zip_replace_data(zf, -1, name, data, len, freep);
-}
diff --git a/lib/zip_error_str.c b/lib/zip_add_dir.c
similarity index 67%
copy from lib/zip_error_str.c
copy to lib/zip_add_dir.c
index a22a673..d258408 100644
--- a/lib/zip_error_str.c
+++ b/lib/zip_add_dir.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_error_str.c,v 1.1 2003/10/06 02:50:05 dillo Exp $
+  $NiH: zip_add.c,v 1.14 2004/11/18 15:04:04 wiz Exp $
 
-  zip_error_str.c -- get string representation of zip error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_add_dir.c -- add directory
+  Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -35,8 +35,6 @@
 
 
 
-#include <errno.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -46,28 +44,40 @@
 
 
 int
-zip_error_str(char *buf, size_t len, int ze, int se)
+zip_add_dir(struct zip *za, const char *name)
 {
-    const char *zs, *ss;
+    int len, ret;
+    char *s;
+    struct zip_source *source;
 
-    if (ze < 0 || ze >= _zip_nerr_str)
-	return snprintf(buf, len, "Unknown error %d", ze);
-
-    zs = _zip_err_str[ze];
-	
-    switch (_zip_err_type[ze]) {
-    case ZIP_ET_SYS:
-	ss = strerror(se);
-	break;
-	
-    case ZIP_ET_ZIP:
-	ss = zError(se);
-	break;
-	
-    default:
-	ss = NULL;
+    if (name == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+	return -1;
     }
 
-    return snprintf(buf, len, "%s%s%s",
-		    zs, (ss ? ": " : ""), (ss ? ss : ""));
+    s = NULL;
+    len = strlen(name);
+
+    if (name[len-1] != '/') {
+	if ((s=(char *)malloc(len+2)) == NULL) {
+	    _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	    return -1;
+	}
+	strcpy(s, name);
+	s[len] = '/';
+	s[len+1] = '\0';
+    }
+
+    if ((source=zip_source_buffer(za, NULL, 0, 0)) == NULL) {
+	free(s);
+	return -1;
+    }
+	
+    ret = _zip_replace(za, -1, s ? s : name, source);
+
+    free(s);
+    if (ret < 0)
+	zip_source_free(source);
+
+    return ret;
 }
diff --git a/lib/zip_add_file.c b/lib/zip_add_file.c
deleted file mode 100644
index b596f12..0000000
--- a/lib/zip_add_file.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-  $NiH: zip_add_file.c,v 1.7 2003/10/02 14:13:28 dillo Exp $
-
-  zip_add_file.c -- add file from file system
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
-
-  This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-  1. Redistributions of source code must retain the above copyright
-     notice, this list of conditions and the following disclaimer.
-  2. Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in
-     the documentation and/or other materials provided with the
-     distribution.
-  3. The names of the authors may not be used to endorse or promote
-     products derived from this software without specific prior
-     written permission.
- 
-  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
-  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
-  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-
-#include "zip.h"
-#include "zipint.h"
-
-
-
-int
-zip_add_file(struct zip *zf, const char *name,
-	     const char *fname, off_t start, off_t len)
-{
-    if (name == NULL) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
-	return -1;
-    }
-
-    return _zip_replace_file(zf, -1, name, fname, start, len);
-}
diff --git a/lib/zip_add_zip.c b/lib/zip_add_zip.c
deleted file mode 100644
index d1c0d11..0000000
--- a/lib/zip_add_zip.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-  $NiH: zip_add_zip.c,v 1.7.4.1 2004/03/20 09:54:04 dillo Exp $
-
-  zip_add_zip.c -- add file from zip file
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
-
-  This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-  1. Redistributions of source code must retain the above copyright
-     notice, this list of conditions and the following disclaimer.
-  2. Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in
-     the documentation and/or other materials provided with the
-     distribution.
-  3. The names of the authors may not be used to endorse or promote
-     products derived from this software without specific prior
-     written permission.
- 
-  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
-  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
-  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-
-#include "zip.h"
-#include "zipint.h"
-
-
-
-int
-zip_add_zip(struct zip *zf, const char *name,
-	    struct zip *srczf, int srcidx, int flags, off_t start, off_t len)
-{
-    if (name == NULL) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
-	return -1;
-    }
-
-    return _zip_replace_zip(zf, -1, name, srczf, srcidx, flags, start, len);
-}
diff --git a/lib/zip_close.c b/lib/zip_close.c
index 245f331..75d20a7 100644
--- a/lib/zip_close.c
+++ b/lib/zip_close.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_close.c,v 1.37.4.8 2004/04/10 23:50:10 dillo Exp $
+  $NiH: zip_close.c,v 1.65 2007/02/28 10:44:15 wiz Exp $
 
   zip_close.c -- close zip archive and update changes
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2004, 2005, 2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -39,7 +39,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -47,72 +46,65 @@
 #include "zipint.h"
 
 static int add_data(struct zip *, int, struct zip_dirent *, FILE *);
-static int add_data_comp(zip_read_func, void *, struct zip_dirent *, FILE *,
-			 struct zip_error *);
-static int add_data_uncomp(zip_read_func, void *, struct zip_dirent *, FILE *,
-			   struct zip_error *);
+static int add_data_comp(zip_source_callback, void *, struct zip_stat *,
+			 FILE *, struct zip_error *);
+static int add_data_uncomp(zip_source_callback, void *, struct zip_stat *,
+			   FILE *, struct zip_error *);
+static void ch_set_error(struct zip_error *, zip_source_callback, void *);
 static int copy_data(FILE *, off_t, FILE *, struct zip_error *);
+static int _zip_cdir_set_comment(struct zip_cdir *, struct zip *);
+static int _zip_changed(struct zip *, int *);
+static char *_zip_create_temp_output(struct zip *, FILE **);
 
 
 
 int
 zip_close(struct zip *za)
 {
-    int changed, survivors;
-    int i, j, count, tfd, ret, error;
+    int survivors;
+    int i, j, error;
     char *temp;
-    FILE *tfp;
+    FILE *out;
     mode_t mask;
     struct zip_cdir *cd;
     struct zip_dirent de;
+    int reopen_on_error;
 
-    changed = survivors = 0;
-    for (i=0; i<za->nentry; i++) {
-	if (za->entry[i].state != ZIP_ST_UNCHANGED)
-	    changed = 1;
-	if (za->entry[i].state != ZIP_ST_DELETED)
-	    survivors++;
-    }
+    reopen_on_error = 0;
 
-    if (!changed) {
+    if (za == NULL)
+	return -1;
+
+    if (!_zip_changed(za, &survivors)) {
 	_zip_free(za);
 	return 0;
     }
 
     /* don't create zip files with no entries */
     if (survivors == 0) {
-	ret = 0;
-	if (za->zn)
-	    ret = remove(za->zn);
+	if (za->zn) {
+	    if (remove(za->zn) != 0) {
+		_zip_error_set(&za->error, ZIP_ER_REMOVE, errno);
+		return -1;
+	    }
+	}
 	_zip_free(za);
-	/* XXX: inconsistent: za freed, returned -1 */
-	return ret;
+	return 0;
     }	       
 	
     if ((cd=_zip_cdir_new(survivors, &za->error)) == NULL)
 	return -1;
 
-    if ((temp=malloc(strlen(za->zn)+8)) == NULL) {
-	_zip_error_set(&za->error, ZERR_MEMORY, 0);
+    for (i=0; i<survivors; i++)
+	_zip_dirent_init(&cd->entry[i]);
+
+    if (_zip_cdir_set_comment(cd, za) == -1) {
 	_zip_cdir_free(cd);
 	return -1;
     }
 
-    sprintf(temp, "%s.XXXXXX", za->zn);
-
-    if ((tfd=mkstemp(temp)) == -1) {
-	_zip_error_set(&za->error, ZERR_TMPOPEN, errno);
+    if ((temp=_zip_create_temp_output(za, &out)) == NULL) {
 	_zip_cdir_free(cd);
-	free(temp);
-	return -1;
-    }
-    
-    if ((tfp=fdopen(tfd, "r+b")) == NULL) {
-	_zip_error_set(&za->error, ZERR_TMPOPEN, errno);
-	_zip_cdir_free(cd);
-	close(tfd);
-	remove(temp);
-	free(temp);
 	return -1;
     }
 
@@ -121,9 +113,13 @@
 	if (za->entry[i].state == ZIP_ST_DELETED)
 	    continue;
 
+	/* create new local directory entry */
 	if (ZIP_ENTRY_DATA_CHANGED(za->entry+i)) {
 	    _zip_dirent_init(&de);
-	    memcpy(cd->entry+j, &de, sizeof(cd->entry[i]));
+	    /* use it as central directory entry */
+	    memcpy(cd->entry+j, &de, sizeof(cd->entry[j]));
+
+	    /* set/update file name */
 	    if (za->entry[i].ch_filename == NULL) {
 		if (za->entry[i].state == ZIP_ST_REPLACED) {
 		    de.filename = strdup(za->cdir->entry[i].filename);
@@ -140,8 +136,9 @@
 	    }
 	}
 	else {
-	    if (fseek(za->zp, za->cdir->entry[i].offset, SEEK_SET) != 0) {
-		_zip_error_set(&za->error, ZERR_SEEK, errno);
+	    /* copy existing directory entries */
+	    if (fseeko(za->zp, za->cdir->entry[i].offset, SEEK_SET) != 0) {
+		_zip_error_set(&za->error, ZIP_ER_SEEK, errno);
 		error = 1;
 		break;
 	    }
@@ -149,37 +146,53 @@
 		error = 1;
 		break;
 	    }
-	    memcpy(cd->entry+j, za->cdir->entry+i, sizeof(cd->entry[i]));
+	    if (de.bitflags & ZIP_GPBF_DATA_DESCRIPTOR) {
+		de.crc = za->cdir->entry[i].crc;
+		de.comp_size = za->cdir->entry[i].comp_size;
+		de.uncomp_size = za->cdir->entry[i].uncomp_size;
+		de.bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR;
+	    }
+	    memcpy(cd->entry+j, za->cdir->entry+i, sizeof(cd->entry[j]));
 	}
 
 	if (za->entry[i].ch_filename) {
 	    free(de.filename);
-	    de.filename = strdup(za->entry[i].ch_filename);
+	    if ((de.filename=strdup(za->entry[i].ch_filename)) == NULL) {
+		error = 1;
+		break;
+	    }
 	    de.filename_len = strlen(de.filename);
 	    cd->entry[j].filename = za->entry[i].ch_filename;
 	    cd->entry[j].filename_len = de.filename_len;
 	}
 
-	cd->entry[j].offset = ftell(tfp);
+	if (za->entry[i].ch_comment_len != -1) {
+	    /* as the rest of cd entries, its malloc/free is done by za */
+	    cd->entry[j].comment = za->entry[i].ch_comment;
+	    cd->entry[j].comment_len = za->entry[i].ch_comment_len;
+	}
+
+	cd->entry[j].offset = ftello(out);
 
 	if (ZIP_ENTRY_DATA_CHANGED(za->entry+i)) {
-	    de.last_mod = za->entry[i].ch_mtime;
-	    if (add_data(za, i, &de, tfp) < 0) {
-		error -1;
+	    if (add_data(za, i, &de, out) < 0) {
+		error = 1;
 		break;
 	    }
+	    cd->entry[j].last_mod = de.last_mod;
 	    cd->entry[j].comp_method = de.comp_method;
 	    cd->entry[j].comp_size = de.comp_size;
 	    cd->entry[j].uncomp_size = de.uncomp_size;
 	    cd->entry[j].crc = de.crc;
 	}
 	else {
-	    if (_zip_dirent_write(&de, tfp, 1, &za->error) < 0) {
+	    if (_zip_dirent_write(&de, out, 1, &za->error) < 0) {
 		error = 1;
 		break;
 	    }
 	    /* we just read the local dirent, file is at correct position */
-	    if (copy_data(za->zp, de.uncomp_size, tfp, &za->error) < 0) {
+	    if (copy_data(za->zp, cd->entry[j].comp_size, out,
+			  &za->error) < 0) {
 		error = 1;
 		break;
 	    }
@@ -191,44 +204,50 @@
     }
 
     if (!error) {
-	if (_zip_cdir_write(cd, tfp, &za->error) < 0)
+	if (_zip_cdir_write(cd, out, &za->error) < 0)
 	    error = 1;
     }
     
-    /* pointers in cd are owned by za */
+    /* pointers in cd entries are owned by za */
     cd->nentry = 0;
     _zip_cdir_free(cd);
 
     if (error) {
 	_zip_dirent_finalize(&de);
-	fclose(tfp);
+	fclose(out);
 	remove(temp);
 	free(temp);
 	return -1;
     }
 
-    if (fclose(tfp) != 0) {
-	/* XXX: handle fclose(tfp) error */
+    if (fclose(out) != 0) {
+	_zip_error_set(&za->error, ZIP_ER_CLOSE, errno);
 	remove(temp);
 	free(temp);
 	return -1;
     }
     
-    if (rename(temp, za->zn) != 0) {
-	_zip_error_set(&za->error, ZERR_RENAME, errno);
-	remove(temp);
-	free(temp);
-	return -1;
-    }
     if (za->zp) {
 	fclose(za->zp);
 	za->zp = NULL;
+	reopen_on_error = 1;
+    }
+    if (rename(temp, za->zn) != 0) {
+	_zip_error_set(&za->error, ZIP_ER_RENAME, errno);
+	remove(temp);
+	free(temp);
+	if (reopen_on_error) {
+	    /* ignore errors, since we're already in an error case */
+	    za->zp = fopen(za->zn, "rb");
+	}
+	return -1;
     }
     mask = umask(0);
     umask(mask);
     chmod(za->zn, 0666&~mask);
 
     _zip_free(za);
+    free(temp);
     
     return 0;
 }
@@ -239,51 +258,60 @@
 add_data(struct zip *za, int idx, struct zip_dirent *de, FILE *ft)
 {
     off_t offstart, offend;
-    zip_read_func rf;
+    zip_source_callback cb;
     void *ud;
+    struct zip_stat st;
     
-    rf = za->entry[idx].ch_func;
-    ud = za->entry[idx].ch_data;
+    cb = za->entry[idx].source->f;
+    ud = za->entry[idx].source->ud;
 
-    if (rf(ud, NULL, 0, ZIP_CMD_INIT) < 0) {
-	/* XXX: set error */
+    if (cb(ud, &st, sizeof(st), ZIP_SOURCE_STAT) < (ssize_t)sizeof(st)) {
+	ch_set_error(&za->error, cb, ud);
 	return -1;
     }
 
-    offstart = ftell(ft);
+    if (cb(ud, NULL, 0, ZIP_SOURCE_OPEN) < 0) {
+	ch_set_error(&za->error, cb, ud);
+	return -1;
+    }
+
+    offstart = ftello(ft);
 
     if (_zip_dirent_write(de, ft, 1, &za->error) < 0)
 	return -1;
 
-    if (za->entry[idx].ch_flags & ZIP_CH_ISCOMP) {
-	if (add_data_comp(rf, ud, de, ft, &za->error) < 0)
+    if (st.comp_method != ZIP_CM_STORE) {
+	if (add_data_comp(cb, ud, &st, ft, &za->error) < 0)
 	    return -1;
     }
     else {
-	if (add_data_uncomp(rf, ud, de, ft, &za->error) < 0)
+	if (add_data_uncomp(cb, ud, &st, ft, &za->error) < 0)
 	    return -1;
     }
 
-#if 0
-    /* XXX: this is also called in _zip_free */
-    if (rf(ud, NULL, 0, ZIP_CMD_CLOSE) < 0) {
-	/* XXX: set error */
+    if (cb(ud, NULL, 0, ZIP_SOURCE_CLOSE) < 0) {
+	ch_set_error(&za->error, cb, ud);
 	return -1;
     }
-#endif
 
-    offend = ftell(ft);
+    offend = ftello(ft);
 
-    if (fseek(ft, offstart, SEEK_SET) < 0) {
-	_zip_error_set(&za->error, ZERR_SEEK, errno);
+    if (fseeko(ft, offstart, SEEK_SET) < 0) {
+	_zip_error_set(&za->error, ZIP_ER_SEEK, errno);
 	return -1;
     }
     
+    de->comp_method = st.comp_method;
+    de->last_mod = st.mtime;
+    de->crc = st.crc;
+    de->uncomp_size = st.size;
+    de->comp_size = st.comp_size;
+
     if (_zip_dirent_write(de, ft, 1, &za->error) < 0)
 	return -1;
     
-    if (fseek(ft, offend, SEEK_SET) < 0) {
-	_zip_error_set(&za->error, ZERR_SEEK, errno);
+    if (fseeko(ft, offend, SEEK_SET) < 0) {
+	_zip_error_set(&za->error, ZIP_ER_SEEK, errno);
 	return -1;
     }
 
@@ -293,56 +321,44 @@
 
 
 static int
-add_data_comp(zip_read_func rf, void *ud, struct zip_dirent *de, FILE *ft,
+add_data_comp(zip_source_callback cb, void *ud, struct zip_stat *st,FILE *ft,
 	      struct zip_error *error)
 {
-    char buf[8192];
+    char buf[BUFSIZE];
     ssize_t n;
-    struct zip_stat st;
 
-    if (rf(ud, &st, sizeof(st), ZIP_CMD_STAT) < 0) {
-	/* XXX: set error */
-	return -1;
-    }
-
-    de->comp_size = 0;
-    while ((n=rf(ud, buf, sizeof(buf), ZIP_CMD_READ)) > 0) {
-	if (fwrite(buf, 1, n, ft) != n) {
-	    _zip_error_set(error, ZERR_WRITE, errno);
+    st->comp_size = 0;
+    while ((n=cb(ud, buf, sizeof(buf), ZIP_SOURCE_READ)) > 0) {
+	if (fwrite(buf, 1, n, ft) != (size_t)n) {
+	    _zip_error_set(error, ZIP_ER_WRITE, errno);
 	    return -1;
 	}
 	
-	de->comp_size += n;
+	st->comp_size += n;
     }
     if (n < 0) {
-	/* XXX: set error */
+	ch_set_error(error, cb, ud);
 	return -1;
     }	
 
-    de->comp_method = st.comp_method;
-    /* de->last_mod = st.mtime; */
-    de->crc = st.crc;
-    de->uncomp_size = st.size;
-
     return 0;
 }
 
 
 
 static int
-add_data_uncomp(zip_read_func rf, void *ud, struct zip_dirent *de, FILE *ft,
-		struct zip_error *error)
+add_data_uncomp(zip_source_callback cb, void *ud, struct zip_stat *st,
+		FILE *ft, struct zip_error *error)
 {
-    char b1[8192], b2[8192];
+    char b1[BUFSIZE], b2[BUFSIZE];
     int end, flush, ret;
     ssize_t n;
+    size_t n2;
     z_stream zstr;
 
-    /* ZIP_CMD_STAT for mtime? */
-
-    de->comp_method = ZIP_CM_DEFLATE;
-    de->comp_size = de->uncomp_size = 0;
-    de->crc = crc32(0, NULL, 0);
+    st->comp_method = ZIP_CM_DEFLATE;
+    st->comp_size = st->size = 0;
+    st->crc = crc32(0, NULL, 0);
 
     zstr.zalloc = Z_NULL;
     zstr.zfree = Z_NULL;
@@ -354,7 +370,7 @@
     deflateInit2(&zstr, Z_BEST_COMPRESSION, Z_DEFLATED, -15, 9,
 		 Z_DEFAULT_STRATEGY);
 
-    zstr.next_out = b2;
+    zstr.next_out = (Bytef *)b2;
     zstr.avail_out = sizeof(b2);
     zstr.avail_in = 0;
 
@@ -362,16 +378,16 @@
     end = 0;
     while (!end) {
 	if (zstr.avail_in == 0 && !flush) {
-	    if ((n=rf(ud, b1, sizeof(b1), ZIP_CMD_READ)) < 0) {
-		/* XXX: set error */
+	    if ((n=cb(ud, b1, sizeof(b1), ZIP_SOURCE_READ)) < 0) {
+		ch_set_error(error, cb, ud);
 		deflateEnd(&zstr);
 		return -1;
 	    }
 	    if (n > 0) {
 		zstr.avail_in = n;
-		zstr.next_in = b1;
-		de->uncomp_size += n;
-		de->crc = crc32(de->crc, b1, n);
+		zstr.next_in = (Bytef *)b1;
+		st->size += n;
+		st->crc = crc32(st->crc, (Bytef *)b1, n);
 	    }
 	    else
 		flush = Z_FINISH;
@@ -379,21 +395,21 @@
 
 	ret = deflate(&zstr, flush);
 	if (ret != Z_OK && ret != Z_STREAM_END) {
-	    _zip_error_set(error, ZERR_ZLIB, ret);
+	    _zip_error_set(error, ZIP_ER_ZLIB, ret);
 	    return -1;
 	}
 	
 	if (zstr.avail_out != sizeof(b2)) {
-	    n = sizeof(b2) - zstr.avail_out;
+	    n2 = sizeof(b2) - zstr.avail_out;
 	    
-	    if (fwrite(b2, 1, n, ft) != n) {
-		_zip_error_set(error, ZERR_WRITE, errno);
+	    if (fwrite(b2, 1, n2, ft) != n2) {
+		_zip_error_set(error, ZIP_ER_WRITE, errno);
 		return -1;
 	    }
 	
-	    zstr.next_out = b2;
+	    zstr.next_out = (Bytef *)b2;
 	    zstr.avail_out = sizeof(b2);
-	    de->comp_size += n;
+	    st->comp_size += n2;
 	}
 
 	if (ret == Z_STREAM_END) {
@@ -407,10 +423,27 @@
 
 
 
+static void
+ch_set_error(struct zip_error *error, zip_source_callback cb, void *ud)
+{
+    int e[2];
+
+    if ((cb(ud, e, sizeof(e), ZIP_SOURCE_ERROR)) < (ssize_t)sizeof(e)) {
+	error->zip_err = ZIP_ER_INTERNAL;
+	error->sys_err = 0;
+    }
+    else {
+	error->zip_err = e[0];
+	error->sys_err = e[1];
+    }
+}
+
+
+
 static int
 copy_data(FILE *fs, off_t len, FILE *ft, struct zip_error *error)
 {
-    char buf[8192];
+    char buf[BUFSIZE];
     int n, nn;
 
     if (len == 0)
@@ -419,12 +452,16 @@
     while (len > 0) {
 	nn = len > sizeof(buf) ? sizeof(buf) : len;
 	if ((n=fread(buf, 1, nn, fs)) < 0) {
-	    _zip_error_set(error, ZERR_READ, errno);
+	    _zip_error_set(error, ZIP_ER_READ, errno);
+	    return -1;
+	}
+	else if (n == 0) {
+	    _zip_error_set(error, ZIP_ER_EOF, 0);
 	    return -1;
 	}
 
-	if (fwrite(buf, 1, n, ft) != n) {
-	    _zip_error_set(error, ZERR_WRITE, errno);
+	if (fwrite(buf, 1, n, ft) != (size_t)n) {
+	    _zip_error_set(error, ZIP_ER_WRITE, errno);
 	    return -1;
 	}
 	
@@ -433,3 +470,86 @@
 
     return 0;
 }
+
+
+
+static int
+_zip_cdir_set_comment(struct zip_cdir *dest, struct zip *src)
+{
+    if (src->ch_comment_len != -1) {
+	dest->comment = _zip_memdup(src->ch_comment,
+				    src->ch_comment_len, &src->error);
+	if (dest->comment == NULL)
+	    return -1;
+	dest->comment_len = src->ch_comment_len;
+    } else {
+	if (src->cdir && src->cdir->comment) {
+	    dest->comment = _zip_memdup(src->cdir->comment,
+					src->cdir->comment_len, &src->error);
+	    if (dest->comment == NULL)
+		return -1;
+	    dest->comment_len = src->cdir->comment_len;
+	}
+    }
+
+    return 0;
+}
+
+
+
+static int
+_zip_changed(struct zip *za, int *survivorsp)
+{
+    int changed, i, survivors;
+
+    changed = survivors = 0;
+
+    if (za->ch_comment_len != -1)
+	changed = 1;
+
+    for (i=0; i<za->nentry; i++) {
+	if ((za->entry[i].state != ZIP_ST_UNCHANGED)
+	    || (za->entry[i].ch_comment_len != -1))
+	    changed = 1;
+	if (za->entry[i].state != ZIP_ST_DELETED)
+	    survivors++;
+    }
+
+    *survivorsp = survivors;
+
+    return changed;
+}
+
+
+
+static char *
+_zip_create_temp_output(struct zip *za, FILE **outp)
+{
+    char *temp;
+    int tfd;
+    FILE *tfp;
+    
+    if ((temp=(char *)malloc(strlen(za->zn)+8)) == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	return NULL;
+    }
+
+    sprintf(temp, "%s.XXXXXX", za->zn);
+
+    if ((tfd=mkstemp(temp)) == -1) {
+	_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
+	free(temp);
+	return NULL;
+    }
+    
+    if ((tfp=fdopen(tfd, "r+b")) == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_TMPOPEN, errno);
+	close(tfd);
+	remove(temp);
+	free(temp);
+	return NULL;
+    }
+
+    *outp = tfp;
+    return temp;
+}
diff --git a/lib/zip_delete.c b/lib/zip_delete.c
index 2dba08f..68cee93 100644
--- a/lib/zip_delete.c
+++ b/lib/zip_delete.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_delete.c,v 1.11 2003/10/06 16:37:40 dillo Exp $
+  $NiH: zip_delete.c,v 1.16 2005/06/09 19:27:16 wiz Exp $
 
   zip_delete.c -- delete file from zip archive
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -41,17 +41,19 @@
 
 
 int
-zip_delete(struct zip *zf, int idx)
+zip_delete(struct zip *za, int idx)
 {
-    if (idx < 0 || idx >= zf->nentry) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
+    if (idx < 0 || idx >= za->nentry) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
 	return -1;
     }
 
-    if (zip_unchange(zf, idx) != 0)
+    /* allow duplicate file names, because the file will
+     * be removed directly afterwards */
+    if (_zip_unchange(za, idx, 1) != 0)
 	return -1;
 
-    zf->entry[idx].state = ZIP_ST_DELETED;
+    za->entry[idx].state = ZIP_ST_DELETED;
 
     return 0;
 }
diff --git a/lib/zip_dirent.c b/lib/zip_dirent.c
index a4becfc..b8258f1 100644
--- a/lib/zip_dirent.c
+++ b/lib/zip_dirent.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_dirent.c,v 1.1.2.9 2004/04/10 23:51:27 dillo Exp $
+  $NiH: zip_dirent.c,v 1.10 2007/03/03 13:48:08 wiz Exp $
 
   zip_dirent.c -- read directory entry (local or central), clean dirent
-  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -39,7 +39,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -47,9 +46,9 @@
 #include "zipint.h"
 
 static time_t _zip_d2u_time(int, int);
-static char *_zip_readfpstr(FILE *, int, int, struct zip_error *);
+static char *_zip_readfpstr(FILE *, unsigned int, int, struct zip_error *);
 static char *_zip_readstr(unsigned char **, int, int, struct zip_error *);
-static void _zip_u2d_time(time_t, int *, int *);
+static void _zip_u2d_time(time_t, unsigned short *, unsigned short *);
 static void _zip_write2(unsigned short, FILE *);
 static void _zip_write4(unsigned int, FILE *);
 
@@ -77,13 +76,14 @@
 {
     struct zip_cdir *cd;
     
-    if ((cd=malloc(sizeof(*cd))) == NULL) {
-	_zip_error_set(error, ZERR_MEMORY, 0);
+    if ((cd=(struct zip_cdir *)malloc(sizeof(*cd))) == NULL) {
+	_zip_error_set(error, ZIP_ER_MEMORY, 0);
 	return NULL;
     }
 
-    if ((cd->entry=malloc(sizeof(*(cd->entry))*nentry)) == NULL) {
-	_zip_error_set(error, ZERR_MEMORY, 0);
+    if ((cd->entry=(struct zip_dirent *)malloc(sizeof(*(cd->entry))*nentry))
+	== NULL) {
+	_zip_error_set(error, ZIP_ER_MEMORY, 0);
 	free(cd);
 	return NULL;
     }
@@ -105,27 +105,27 @@
 {
     int i;
 
-    cd->offset = ftell(fp);
+    cd->offset = ftello(fp);
 
     for (i=0; i<cd->nentry; i++) {
 	if (_zip_dirent_write(cd->entry+i, fp, 0, error) != 0)
 	    return -1;
     }
 
-    cd->size = ftell(fp) - cd->offset;
+    cd->size = ftello(fp) - cd->offset;
     
     /* clearerr(fp); */
     fwrite(EOCD_MAGIC, 1, 4, fp);
     _zip_write4(0, fp);
-    _zip_write2(cd->nentry, fp);
-    _zip_write2(cd->nentry, fp);
+    _zip_write2((unsigned short)cd->nentry, fp);
+    _zip_write2((unsigned short)cd->nentry, fp);
     _zip_write4(cd->size, fp);
     _zip_write4(cd->offset, fp);
     _zip_write2(cd->comment_len, fp);
     fwrite(cd->comment, 1, cd->comment_len, fp);
 
     if (ferror(fp)) {
-	_zip_error_set(error, ZERR_WRITE, errno);
+	_zip_error_set(error, ZIP_ER_WRITE, errno);
 	return -1;
     }
 
@@ -150,8 +150,8 @@
 void
 _zip_dirent_init(struct zip_dirent *de)
 {
-    de->version_madeby = 0; /* XXX */
-    de->version_needed = 0; /* XXX */
+    de->version_madeby = 0;
+    de->version_needed = 20; /* 2.0 */
     de->bitflags = 0;
     de->comp_method = 0;
     de->last_mod = 0;
@@ -188,13 +188,13 @@
 
 int
 _zip_dirent_read(struct zip_dirent *zde, FILE *fp,
-		 unsigned char **bufp, int left, int localp,
+		 unsigned char **bufp, unsigned int left, int localp,
 		 struct zip_error *error)
 {
     unsigned char buf[CDENTRYSIZE];
     unsigned char *cur;
     unsigned short dostime, dosdate;
-    int size;
+    unsigned int size;
 
     if (localp)
 	size = LENTRYSIZE;
@@ -205,14 +205,14 @@
 	/* use data from buffer */
 	cur = *bufp;
 	if (left < size) {
-	    _zip_error_set(error, ZERR_NOZIP, 0);
+	    _zip_error_set(error, ZIP_ER_NOZIP, 0);
 	    return -1;
 	}
     }
     else {
 	/* read entry from disk */
 	if ((fread(buf, 1, size, fp)<size)) {
-	    _zip_error_set(error, ZERR_READ, errno);
+	    _zip_error_set(error, ZIP_ER_READ, errno);
 	    return -1;
 	}
 	left = size;
@@ -220,7 +220,7 @@
     }
 
     if (memcmp(cur, (localp ? LOCAL_MAGIC : CENTRAL_MAGIC), 4) != 0) {
-	/* XXX: zip_err = ZERR_NOZIP; */
+	_zip_error_set(error, ZIP_ER_NOZIP, 0);
 	return -1;
     }
     cur += 4;
@@ -269,7 +269,7 @@
     if (bufp) {
 	if (left < CDENTRYSIZE + (zde->filename_len+zde->extrafield_len
 				  +zde->comment_len)) {
-	    _zip_error_set(error, ZERR_NOZIP, 0);
+	    _zip_error_set(error, ZIP_ER_NOZIP, 0);
 	    return -1;
 	}
 
@@ -335,7 +335,7 @@
 _zip_dirent_write(struct zip_dirent *zde, FILE *fp, int localp,
 		  struct zip_error *error)
 {
-    int dostime, dosdate;
+    unsigned short dostime, dosdate;
 
     fwrite(localp ? LOCAL_MAGIC : CENTRAL_MAGIC, 1, 4, fp);
 
@@ -376,7 +376,7 @@
     }
 
     if (ferror(fp)) {
-	_zip_error_set(error, ZERR_WRITE, errno);
+	_zip_error_set(error, ZIP_ER_WRITE, errno);
 	return -1;
     }
 
@@ -393,6 +393,8 @@
 
     now = time(NULL);
     tm = localtime(&now);
+    /* let mktime decide if DST is in effect */
+    tm->tm_isdst = -1;
     
     tm->tm_year = ((ddate>>9)&127) + 1980 - 1900;
     tm->tm_mon = ((ddate>>5)&15) - 1;
@@ -434,29 +436,28 @@
 
 
 static char *
-_zip_readfpstr(FILE *fp, int len, int nulp, struct zip_error *error)
+_zip_readfpstr(FILE *fp, unsigned int len, int nulp, struct zip_error *error)
 {
     char *r, *o;
 
-    r = (char *)malloc(nulp?len+1:len);
+    r = (char *)malloc(nulp ? len+1 : len);
     if (!r) {
-	_zip_error_set(error, ZERR_MEMORY, 0);
+	_zip_error_set(error, ZIP_ER_MEMORY, 0);
 	return NULL;
     }
 
     if (fread(r, 1, len, fp)<len) {
 	free(r);
-	_zip_error_set(error, ZERR_READ, errno);
+	_zip_error_set(error, ZIP_ER_READ, errno);
 	return NULL;
     }
 
     if (nulp) {
-	/* elephant */
-	/* XXX: what does this do? */
+	/* replace any in-string NUL characters with spaces */
 	r[len] = 0;
-	o = r-1;
-	while (((o=memchr(o+1, 0, r+len-(o+1))) < r+len) && o)
-	       *o = ' ';
+	for (o=r; o<r+len; o++)
+	    if (*o == '\0')
+		*o = ' ';
     }
     
     return r;
@@ -469,9 +470,9 @@
 {
     char *r, *o;
 
-    r = (char *)malloc(nulp?len+1:len);
+    r = (char *)malloc(nulp ? len+1 : len);
     if (!r) {
-	_zip_error_set(error, ZERR_MEMORY, 0);
+	_zip_error_set(error, ZIP_ER_MEMORY, 0);
 	return NULL;
     }
     
@@ -479,12 +480,11 @@
     *buf += len;
 
     if (nulp) {
-	/* elephant */
-	/* XXX: what does this do? */
+	/* replace any in-string NUL characters with spaces */
 	r[len] = 0;
-	o = r-1;
-	while (((o=memchr(o+1, 0, r+len-(o+1))) < r+len) && o)
-	       *o = ' ';
+	for (o=r; o<r+len; o++)
+	    if (*o == '\0')
+		*o = ' ';
     }
 
     return r;
@@ -517,7 +517,7 @@
 
 
 static void
-_zip_u2d_time(time_t time, int *dtime, int *ddate)
+_zip_u2d_time(time_t time, unsigned short *dtime, unsigned short *ddate)
 {
     struct tm *tm;
 
diff --git a/lib/zip_free_entry.c b/lib/zip_entry_free.c
similarity index 81%
rename from lib/zip_free_entry.c
rename to lib/zip_entry_free.c
index 033061b..70d713a 100644
--- a/lib/zip_free_entry.c
+++ b/lib/zip_entry_free.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_free_entry.c,v 1.9.4.2 2004/03/22 14:17:33 dillo Exp $
+  $NiH: zip_entry_free.c,v 1.1 2004/11/30 21:37:01 wiz Exp $
 
-  zip_free_entry.c -- free struct zip_entry
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_entry_free.c -- free struct zip_entry
+  Copyright (C) 1999, 2003, 2004, 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -42,17 +42,14 @@
 
 
 
-int
-_zip_free_entry(struct zip_entry *ze)
+void
+_zip_entry_free(struct zip_entry *ze)
 {
-    int ret;
-
-    ret = 0;
-    
     free(ze->ch_filename);
-    
-    if (ze->ch_func)
-	ret = ze->ch_func(ze->ch_data, NULL, 0, ZIP_CMD_CLOSE);
+    ze->ch_filename = NULL;
+    free(ze->ch_comment);
+    ze->ch_comment = NULL;
+    ze->ch_comment_len = -1;
 
-    return ret;
+    _zip_unchange_data(ze);
 }
diff --git a/lib/zip_new_entry.c b/lib/zip_entry_new.c
similarity index 74%
rename from lib/zip_new_entry.c
rename to lib/zip_entry_new.c
index 1bb7405..d2a92dd 100644
--- a/lib/zip_new_entry.c
+++ b/lib/zip_entry_new.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_new_entry.c,v 1.7.4.3 2004/04/06 20:30:06 dillo Exp $
+  $NiH: zip_entry_new.c,v 1.1 2004/11/30 21:42:22 wiz Exp $
 
-  zip_new_entry.c -- create and init struct zip_entry
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_entry_new.c -- create and init struct zip_entry
+  Copyright (C) 1999, 2003, 2004, 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -43,40 +43,39 @@
 
 
 struct zip_entry *
-_zip_new_entry(struct zip *zf)
+_zip_entry_new(struct zip *za)
 {
     struct zip_entry *ze;
-    if (!zf) {
+    if (!za) {
 	ze = (struct zip_entry *)malloc(sizeof(struct zip_entry));
 	if (!ze) {
-	    _zip_error_set(&zf->error, ZERR_MEMORY, 0);
+	    _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
 	    return NULL;
 	}
     }
     else {
-	if (zf->nentry >= zf->nentry_alloc-1) {
-	    zf->nentry_alloc += 16;
-	    zf->entry = (struct zip_entry *)realloc(zf->entry,
+	if (za->nentry >= za->nentry_alloc-1) {
+	    za->nentry_alloc += 16;
+	    za->entry = (struct zip_entry *)realloc(za->entry,
 						    sizeof(struct zip_entry)
-						    * zf->nentry_alloc);
-	    if (!zf->entry) {
-		_zip_error_set(&zf->error, ZERR_MEMORY, 0);
+						    * za->nentry_alloc);
+	    if (!za->entry) {
+		_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
 		return NULL;
 	    }
 	}
-	ze = zf->entry+zf->nentry;
+	ze = za->entry+za->nentry;
     }
 
     ze->state = ZIP_ST_UNCHANGED;
 
     ze->ch_filename = NULL;
-    ze->ch_func = NULL;
-    ze->ch_data = NULL;
-    ze->ch_flags = 0;
-    ze->ch_mtime = -1;
+    ze->ch_comment = NULL;
+    ze->ch_comment_len = -1;
+    ze->source = NULL;
 
-    if (zf)
-	zf->nentry++;
+    if (za)
+	za->nentry++;
 
     return ze;
 }
diff --git a/lib/zip_error.c b/lib/zip_error.c
index 6d8fbb3..6d2cd00 100644
--- a/lib/zip_error.c
+++ b/lib/zip_error.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_error.c,v 1.3 2003/10/06 16:37:40 dillo Exp $
+  $NiH: zip_error.c,v 1.7 2005/06/09 19:57:09 dillo Exp $
 
   zip_error.c -- struct zip_error helper functions
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -43,6 +43,15 @@
 
 
 void
+_zip_error_clear(struct zip_error *err)
+{
+    err->zip_err = ZIP_ER_OK;
+    err->sys_err = 0;
+}
+
+
+
+void
 _zip_error_copy(struct zip_error *dst, struct zip_error *src)
 {
     dst->zip_err = src->zip_err;
@@ -65,9 +74,12 @@
 {
     if (zep)
 	*zep = err->zip_err;
-    /* XXX: only if valid? */
-    if (sep)
-	*sep = err->sys_err;
+    if (sep) {
+	if (zip_error_get_sys_type(err->zip_err) != ZIP_ET_NONE)
+	    *sep = err->sys_err;
+	else
+	    *sep = 0;
+    }
 }
 
 
@@ -75,7 +87,7 @@
 void
 _zip_error_init(struct zip_error *err)
 {
-    err->zip_err = 0;
+    err->zip_err = ZIP_ER_OK;
     err->sys_err = 0;
     err->str = NULL;
 }
diff --git a/lib/zip_get_error.c b/lib/zip_error_clear.c
similarity index 89%
copy from lib/zip_get_error.c
copy to lib/zip_error_clear.c
index 5545565..9e1639b 100644
--- a/lib/zip_get_error.c
+++ b/lib/zip_error_clear.c
@@ -1,8 +1,8 @@
 /*
   $NiH$
 
-  zip_get_error.c -- get zip error
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_error_clear.c -- clear zip error
+  Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -41,7 +41,7 @@
 
 
 void
-zip_get_error(struct zip *za, int *zep, int *sep)
+zip_error_clear(struct zip *za)
 {
-    _zip_error_get(&za->error, zep, sep);
+    _zip_error_clear(&za->error);
 }
diff --git a/lib/zip_get_error.c b/lib/zip_error_get.c
similarity index 91%
rename from lib/zip_get_error.c
rename to lib/zip_error_get.c
index 5545565..4111d9c 100644
--- a/lib/zip_get_error.c
+++ b/lib/zip_error_get.c
@@ -1,7 +1,7 @@
 /*
-  $NiH$
+  $NiH: zip_error_get.c,v 1.1 2003/10/06 02:50:06 dillo Exp $
 
-  zip_get_error.c -- get zip error
+  zip_error_get.c -- get zip error
   Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
@@ -41,7 +41,7 @@
 
 
 void
-zip_get_error(struct zip *za, int *zep, int *sep)
+zip_error_get(struct zip *za, int *zep, int *sep)
 {
     _zip_error_get(&za->error, zep, sep);
 }
diff --git a/lib/zip_error_sys_type.c b/lib/zip_error_get_sys_type.c
similarity index 91%
rename from lib/zip_error_sys_type.c
rename to lib/zip_error_get_sys_type.c
index 7c1c899..708d774 100644
--- a/lib/zip_error_sys_type.c
+++ b/lib/zip_error_get_sys_type.c
@@ -1,7 +1,7 @@
 /*
-  $NiH$
+  $NiH: zip_error_get_sys_type.c,v 1.1 2003/10/06 02:50:06 dillo Exp $
 
-  zip_error_sys_type.c -- return type of system error code
+  zip_error_get_sys_type.c -- return type of system error code
   Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
@@ -41,7 +41,7 @@
 
 
 int
-zip_error_sys_type(int ze)
+zip_error_get_sys_type(int ze)
 {
     if (ze < 0 || ze >= _zip_nerr_str)
 	return 0;
diff --git a/lib/zip_error_strerror.c b/lib/zip_error_strerror.c
index fae7c1c..521a83f 100644
--- a/lib/zip_error_strerror.c
+++ b/lib/zip_error_strerror.c
@@ -1,5 +1,5 @@
 /*
-  $NiH: zip_error_strerror.c,v 1.1 2003/10/05 16:05:22 dillo Exp $
+  $NiH: zip_error_strerror.c,v 1.4 2006/02/21 09:41:00 dillo Exp $
 
   zip_error_sterror.c -- get string representation of struct zip_error
   Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
@@ -66,7 +66,7 @@
 	    ss = strerror(err->sys_err);
 	    break;
 
-	case ZIP_ET_ZIP:
+	case ZIP_ET_ZLIB:
 	    ss = zError(err->sys_err);
 	    break;
 
@@ -78,8 +78,9 @@
     if (ss == NULL)
 	return zs;
     else {
-	if ((s=malloc(strlen(ss) + (zs ? strlen(zs)+2 : 0) + 1)) == NULL)
-	    return _zip_err_str[ZERR_MEMORY];
+	if ((s=(char *)malloc(strlen(ss)
+			      + (zs ? strlen(zs)+2 : 0) + 1)) == NULL)
+	    return _zip_err_str[ZIP_ER_MEMORY];
 	
 	sprintf(s, "%s%s%s",
 		(zs ? zs : ""),
@@ -87,6 +88,6 @@
 		ss);
 	err->str = s;
 
-	return ss;
+	return s;
     }
 }
diff --git a/lib/zip_error_str.c b/lib/zip_error_to_str.c
similarity index 87%
rename from lib/zip_error_str.c
rename to lib/zip_error_to_str.c
index a22a673..a88b749 100644
--- a/lib/zip_error_str.c
+++ b/lib/zip_error_to_str.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_error_str.c,v 1.1 2003/10/06 02:50:05 dillo Exp $
+  $NiH: zip_error_to_str.c,v 1.4 2004/11/17 21:55:10 wiz Exp $
 
-  zip_error_str.c -- get string representation of zip error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_error_to_str.c -- get string representation of zip error code
+  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -46,7 +46,7 @@
 
 
 int
-zip_error_str(char *buf, size_t len, int ze, int se)
+zip_error_to_str(char *buf, size_t len, int ze, int se)
 {
     const char *zs, *ss;
 
@@ -60,7 +60,7 @@
 	ss = strerror(se);
 	break;
 	
-    case ZIP_ET_ZIP:
+    case ZIP_ET_ZLIB:
 	ss = zError(se);
 	break;
 	
diff --git a/lib/zip_fclose.c b/lib/zip_fclose.c
index 5fd4192..7661185 100644
--- a/lib/zip_fclose.c
+++ b/lib/zip_fclose.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_fclose.c,v 1.8 2003/10/03 11:53:28 dillo Exp $
+  $NiH: zip_fclose.c,v 1.13 2005/01/11 19:52:24 wiz Exp $
 
   zip_fclose.c -- close file in zip archive
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -43,29 +43,32 @@
 
 
 int
-zip_fclose(struct zip_file *zff)
+zip_fclose(struct zip_file *zf)
 {
     int i, ret;
     
-    if (zff->zstr)
-	inflateEnd(zff->zstr);
-    free(zff->buffer);
-    free(zff->zstr);
+    if (zf->zstr)
+	inflateEnd(zf->zstr);
+    free(zf->buffer);
+    free(zf->zstr);
 
-    for (i=0; i<zff->zf->nfile; i++) {
-	if (zff->zf->file[i] == zff) {
-	    zff->zf->file[i] = zff->zf->file[zff->zf->nfile-1];
-	    zff->zf->nfile--;
+    for (i=0; i<zf->za->nfile; i++) {
+	if (zf->za->file[i] == zf) {
+	    zf->za->file[i] = zf->za->file[zf->za->nfile-1];
+	    zf->za->nfile--;
 	    break;
 	}
     }
 
-    /* if EOF, compare CRC */
-    if (zff->flags & ZIP_ZF_EOF)
-	ret = (zff->crc_orig == zff->crc);
-    else
-	ret = zff->error.zip_err;
+    ret = 0;
+    if (zf->error.zip_err)
+	ret = zf->error.zip_err;
+    else if ((zf->flags & ZIP_ZF_CRC) && (zf->flags & ZIP_ZF_EOF)) {
+	/* if EOF, compare CRC */
+	if (zf->crc_orig != zf->crc)
+	    ret = ZIP_ER_CRC;
+    }
 
-    free(zff);
+    free(zf);
     return ret;
 }
diff --git a/lib/zip_error_sys_type.c b/lib/zip_file_error_clear.c
similarity index 85%
copy from lib/zip_error_sys_type.c
copy to lib/zip_file_error_clear.c
index 7c1c899..f7ae20d 100644
--- a/lib/zip_error_sys_type.c
+++ b/lib/zip_file_error_clear.c
@@ -1,8 +1,8 @@
 /*
-  $NiH$
+  $NiH: zip_file_error_clear.c,v 1.3 2006/10/04 18:26:42 dillo Exp $
 
-  zip_error_sys_type.c -- return type of system error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_file_error_clear.c -- clear zip file error
+  Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -40,11 +40,8 @@
 
 
 
-int
-zip_error_sys_type(int ze)
+void
+zip_file_error_clear(struct zip_file *zf)
 {
-    if (ze < 0 || ze >= _zip_nerr_str)
-	return 0;
-
-    return _zip_err_type[ze];
+    _zip_error_clear(&zf->error);
 }
diff --git a/lib/zip_file_get_error.c b/lib/zip_file_error_get.c
similarity index 90%
rename from lib/zip_file_get_error.c
rename to lib/zip_file_error_get.c
index f9f36a6..bda59f4 100644
--- a/lib/zip_file_get_error.c
+++ b/lib/zip_file_error_get.c
@@ -1,7 +1,7 @@
 /*
-  $NiH$
+  $NiH: zip_file_error_get.c,v 1.1 2003/10/06 02:50:06 dillo Exp $
 
-  zip_file_get_error.c -- get zip file error
+  zip_file_error_get.c -- get zip file error
   Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
@@ -41,7 +41,7 @@
 
 
 void
-zip_file_get_error(struct zip_file *zf, int *zep, int *sep)
+zip_file_error_get(struct zip_file *zf, int *zep, int *sep)
 {
     _zip_error_get(&zf->error, zep, sep);
 }
diff --git a/lib/zip_file_get_offset.c b/lib/zip_file_get_offset.c
index fa0e585..f0f4f3f 100644
--- a/lib/zip_file_get_offset.c
+++ b/lib/zip_file_get_offset.c
@@ -1,5 +1,5 @@
 /*
-  $NiH: zip_file_get_offset.c,v 1.1.2.1 2004/03/23 17:14:49 dillo Exp $
+  $NiH: zip_file_get_offset.c,v 1.4 2006/04/23 14:51:45 wiz Exp $
 
   zip_file_get_offset.c -- get offset of file data in archive.
   Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
@@ -39,7 +39,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -62,8 +61,8 @@
 
     offset = za->cdir->entry[idx].offset;
 
-    if (fseek(za->zp, offset, SEEK_SET) != 0) {
-	_zip_error_set(&za->error, ZERR_SEEK, errno);
+    if (fseeko(za->zp, offset, SEEK_SET) != 0) {
+	_zip_error_set(&za->error, ZIP_ER_SEEK, errno);
 	return 0;
     }
 
diff --git a/lib/zip_fopen.c b/lib/zip_fopen.c
index f7dc6a5..1fca478 100644
--- a/lib/zip_fopen.c
+++ b/lib/zip_fopen.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_fopen.c,v 1.8 2003/10/06 16:37:40 dillo Exp $
+  $NiH: zip_fopen.c,v 1.11 2005/01/11 18:38:16 wiz Exp $
 
-  zip_fopen.c -- open file in zip archvie for reading
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_fopen.c -- open file in zip archive for reading
+  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
diff --git a/lib/zip_fopen_index.c b/lib/zip_fopen_index.c
index 431d88c..4a49566 100644
--- a/lib/zip_fopen_index.c
+++ b/lib/zip_fopen_index.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_fopen_index.c,v 1.15.4.9 2004/04/13 19:47:59 dillo Exp $
+  $NiH: zip_fopen_index.c,v 1.24 2005/05/20 21:54:53 wiz Exp $
 
   zip_fopen_index.c -- open file in zip archive for reading by index
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -42,124 +42,135 @@
 #include "zip.h"
 #include "zipint.h"
 
-static struct zip_file *_zip_file_new(struct zip *zf);
+static struct zip_file *_zip_file_new(struct zip *za);
 
 
 
 struct zip_file *
-zip_fopen_index(struct zip *zf, int fileno, int flags)
+zip_fopen_index(struct zip *za, int fileno, int flags)
 {
     int len, ret;
     int zfflags;
-    struct zip_file *zff;
+    struct zip_file *zf;
 
-    if ((fileno < 0) || (fileno >= zf->nentry)) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
+    if ((fileno < 0) || (fileno >= za->nentry)) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
 	return NULL;
     }
 
     if ((flags & ZIP_FL_UNCHANGED) == 0
-	&& ZIP_ENTRY_DATA_CHANGED(zf->entry+fileno)) {
-	_zip_error_set(&zf->error, ZERR_CHANGED, 0);
+	&& ZIP_ENTRY_DATA_CHANGED(za->entry+fileno)) {
+	_zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
 	return NULL;
     }
 
-    if ((flags & ZIP_FL_COMPRESSED)
-	|| (zf->cdir->entry[fileno].comp_method == ZIP_CM_STORE))
-	zfflags = ZIP_ZF_COMP;
-    else {
-	if (zf->cdir->entry[fileno].comp_method != ZIP_CM_DEFLATE) {
-	    _zip_error_set(&zf->error, ZERR_COMPNOTSUPP, 0);
-	    return NULL;
-	}
-	zfflags = 0;
+    if (fileno >= za->cdir->nentry) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+	return NULL;
     }
 
-    zff = _zip_file_new(zf);
+    zfflags = 0;
+    switch (za->cdir->entry[fileno].comp_method) {
+    case ZIP_CM_STORE:
+	zfflags |= ZIP_ZF_CRC;
+	break;
 
-    zff->flags = zfflags;
-    /* zff->name = zf->cdir->entry[fileno].filename; */
-    zff->method = zf->cdir->entry[fileno].comp_method;
-    zff->bytes_left = zf->cdir->entry[fileno].uncomp_size;
-    zff->cbytes_left = zf->cdir->entry[fileno].comp_size;
-    zff->crc_orig = zf->cdir->entry[fileno].crc;
+    case ZIP_CM_DEFLATE:
+	if ((flags & ZIP_FL_COMPRESSED) == 0)
+	    zfflags |= ZIP_ZF_CRC | ZIP_ZF_DECOMP;
+	break;
+    default:
+	if ((flags & ZIP_FL_COMPRESSED) == 0) {
+	    _zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0);
+	    return NULL;
+	}
+	break;
+    }
 
-    if ((zff->fpos=_zip_file_get_offset(zf, fileno)) == 0) {
-	zip_fclose(zff);
+    zf = _zip_file_new(za);
+
+    zf->flags = zfflags;
+    /* zf->name = za->cdir->entry[fileno].filename; */
+    zf->method = za->cdir->entry[fileno].comp_method;
+    zf->bytes_left = za->cdir->entry[fileno].uncomp_size;
+    zf->cbytes_left = za->cdir->entry[fileno].comp_size;
+    zf->crc_orig = za->cdir->entry[fileno].crc;
+
+    if ((zf->fpos=_zip_file_get_offset(za, fileno)) == 0) {
+	zip_fclose(zf);
 	return NULL;
     }
     
-    if (zff->flags & ZIP_ZF_COMP)
-	zff->bytes_left = zff->cbytes_left;
+    if ((zf->flags & ZIP_ZF_DECOMP) == 0)
+	zf->bytes_left = zf->cbytes_left;
     else {
-	/* XXX: don't use BUFSIZE */
-	if ((zff->buffer=(char *)malloc(BUFSIZE)) == NULL) {
-	    _zip_error_set(&zf->error, ZERR_MEMORY, 0);
-	    zip_fclose(zff);
+	if ((zf->buffer=(char *)malloc(BUFSIZE)) == NULL) {
+	    _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	    zip_fclose(zf);
 	    return NULL;
 	}
 
-	len = _zip_file_fillbuf(zff->buffer, BUFSIZE, zff);
+	len = _zip_file_fillbuf(zf->buffer, BUFSIZE, zf);
 	if (len <= 0) {
-	    _zip_error_copy(&zf->error, &zff->error);
-	    zip_fclose(zff);
+	    _zip_error_copy(&za->error, &zf->error);
+	    zip_fclose(zf);
 	return NULL;
 	}
 
-	if ((zff->zstr = (z_stream *)malloc(sizeof(z_stream))) == NULL) {
-	    _zip_error_set(&zf->error, ZERR_MEMORY, 0);
-	    zip_fclose(zff);
+	if ((zf->zstr = (z_stream *)malloc(sizeof(z_stream))) == NULL) {
+	    _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	    zip_fclose(zf);
 	    return NULL;
 	}
-	zff->zstr->zalloc = Z_NULL;
-	zff->zstr->zfree = Z_NULL;
-	zff->zstr->opaque = NULL;
-	zff->zstr->next_in = zff->buffer;
-	zff->zstr->avail_in = len;
+	zf->zstr->zalloc = Z_NULL;
+	zf->zstr->zfree = Z_NULL;
+	zf->zstr->opaque = NULL;
+	zf->zstr->next_in = (Bytef *)zf->buffer;
+	zf->zstr->avail_in = len;
 	
 	/* negative value to tell zlib that there is no header */
-	if ((ret=inflateInit2(zff->zstr, -MAX_WBITS)) != Z_OK) {
-	    _zip_error_set(&zf->error, ZERR_ZLIB, ret);
-	    zip_fclose(zff);
+	if ((ret=inflateInit2(zf->zstr, -MAX_WBITS)) != Z_OK) {
+	    _zip_error_set(&za->error, ZIP_ER_ZLIB, ret);
+	    zip_fclose(zf);
 	    return NULL;
 	}
     }
     
-    return zff;
+    return zf;
 }
 
 
 
 int
-_zip_file_fillbuf(void *buf, size_t buflen, struct zip_file *zff)
+_zip_file_fillbuf(void *buf, size_t buflen, struct zip_file *zf)
 {
     int i, j;
 
-    if (zff->error.zip_err != ZERR_OK)
+    if (zf->error.zip_err != ZIP_ER_OK)
 	return -1;
 
-    if ((zff->flags & ZIP_ZF_EOF) || zff->cbytes_left <= 0 || buflen <= 0)
+    if ((zf->flags & ZIP_ZF_EOF) || zf->cbytes_left <= 0 || buflen <= 0)
 	return 0;
     
-    if (fseek(zff->zf->zp, zff->fpos, SEEK_SET) < 0) {
-	_zip_error_set(&zff->error, ZERR_SEEK, errno);
+    if (fseeko(zf->za->zp, zf->fpos, SEEK_SET) < 0) {
+	_zip_error_set(&zf->error, ZIP_ER_SEEK, errno);
 	return -1;
     }
-    if (buflen < zff->cbytes_left)
+    if (buflen < zf->cbytes_left)
 	i = buflen;
     else
-	i = zff->cbytes_left;
+	i = zf->cbytes_left;
 
-    j = fread(buf, 1, i, zff->zf->zp);
+    j = fread(buf, 1, i, zf->za->zp);
     if (j == 0) {
-	_zip_error_set(&zff->error, ZERR_EOF, 0);
+	_zip_error_set(&zf->error, ZIP_ER_EOF, 0);
 	j = -1;
     }
     else if (j < 0)
-	_zip_error_set(&zff->error, ZERR_READ, errno);
+	_zip_error_set(&zf->error, ZIP_ER_READ, errno);
     else {
-	zff->fpos += j;
-	zff->cbytes_left -= j;
+	zf->fpos += j;
+	zf->cbytes_left -= j;
     }
 
     return j;	
@@ -168,41 +179,41 @@
 
 
 static struct zip_file *
-_zip_file_new(struct zip *zf)
+_zip_file_new(struct zip *za)
 {
-    struct zip_file *zff, **file;
+    struct zip_file *zf, **file;
     int n;
 
-    if ((zff=(struct zip_file *)malloc(sizeof(struct zip_file))) == NULL) {
-	_zip_error_set(&zf->error, ZERR_MEMORY, 0);
+    if ((zf=(struct zip_file *)malloc(sizeof(struct zip_file))) == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
 	return NULL;
     }
     
-    if (zf->nfile >= zf->nfile_alloc-1) {
-	n = zf->nfile_alloc + 10;
-	file = (struct zip_file **)realloc(zf->file,
+    if (za->nfile >= za->nfile_alloc-1) {
+	n = za->nfile_alloc + 10;
+	file = (struct zip_file **)realloc(za->file,
 					   n*sizeof(struct zip_file *));
 	if (file == NULL) {
-	    _zip_error_set(&zf->error, ZERR_MEMORY, 0);
-	    free(zff);
+	    _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	    free(zf);
 	    return NULL;
 	}
-	zf->nfile_alloc = n;
-	zf->file = file;
+	za->nfile_alloc = n;
+	za->file = file;
     }
 
-    zf->file[zf->nfile++] = zff;
+    za->file[za->nfile++] = zf;
 
-    zff->zf = zf;
-    _zip_error_init(&zff->error);
-    zff->flags = 0;
-    zff->crc = crc32(0L, Z_NULL, 0);
-    zff->crc_orig = 0;
-    zff->method = -1;
-    zff->bytes_left = zff->cbytes_left = 0;
-    zff->fpos = 0;
-    zff->buffer = NULL;
-    zff->zstr = NULL;
+    zf->za = za;
+    _zip_error_init(&zf->error);
+    zf->flags = 0;
+    zf->crc = crc32(0L, Z_NULL, 0);
+    zf->crc_orig = 0;
+    zf->method = -1;
+    zf->bytes_left = zf->cbytes_left = 0;
+    zf->fpos = 0;
+    zf->buffer = NULL;
+    zf->zstr = NULL;
 
-    return zff;
+    return zf;
 }
diff --git a/lib/zip_fread.c b/lib/zip_fread.c
index fa8dbf3..030b3c8 100644
--- a/lib/zip_fread.c
+++ b/lib/zip_fread.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_fread.c,v 1.8.4.2 2004/04/08 16:56:07 dillo Exp $
+  $NiH: zip_fread.c,v 1.20 2006/02/22 19:52:20 dillo Exp $
 
   zip_fread.c -- read from file
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -41,44 +41,49 @@
 
 
 ssize_t
-zip_fread(struct zip_file *zff, void *outbuf, size_t toread)
+zip_fread(struct zip_file *zf, void *outbuf, size_t toread)
 {
-    int len, out_before, ret;
+    int ret;
+    size_t out_before, len;
+    int i;
 
-    if (!zff)
+    if (!zf)
 	return -1;
 
-    if (zff->error.zip_err != 0)
+    if (zf->error.zip_err != 0)
 	return -1;
 
-    if ((zff->flags & ZIP_ZF_EOF) || (toread == 0))
+    if ((zf->flags & ZIP_ZF_EOF) || (toread == 0))
 	return 0;
 
-    if (zff->bytes_left == 0) {
-	zff->flags |= ZIP_ZF_EOF;
-	if (zff->crc != zff->crc_orig) {
-	    _zip_error_set(&zff->error, ZERR_CRC, 0);
-	    return -1;
+    if (zf->bytes_left == 0) {
+	zf->flags |= ZIP_ZF_EOF;
+	if (zf->flags & ZIP_ZF_CRC) {
+	    if (zf->crc != zf->crc_orig) {
+		_zip_error_set(&zf->error, ZIP_ER_CRC, 0);
+		return -1;
+	    }
 	}
 	return 0;
     }
     
-    if (zff->flags & ZIP_ZF_COMP) {
-	ret = _zip_file_fillbuf(outbuf, toread, zff);
+    if ((zf->flags & ZIP_ZF_DECOMP) == 0) {
+	ret = _zip_file_fillbuf(outbuf, toread, zf);
 	if (ret > 0) {
-	    zff->crc = crc32(zff->crc, outbuf, ret);
-	    zff->bytes_left -= ret;
+	    if (zf->flags & ZIP_ZF_CRC)
+		zf->crc = crc32(zf->crc, (Bytef *)outbuf, ret);
+	    zf->bytes_left -= ret;
 	}
 	return ret;
     }
     
-    zff->zstr->next_out = outbuf;
-    zff->zstr->avail_out = toread;
-    out_before = zff->zstr->total_out;
+    zf->zstr->next_out = (Bytef *)outbuf;
+    zf->zstr->avail_out = toread;
+    out_before = zf->zstr->total_out;
     
     /* endless loop until something has been accomplished */
     for (;;) {
-	ret = inflate(zff->zstr, Z_SYNC_FLUSH);
+	ret = inflate(zf->zstr, Z_SYNC_FLUSH);
 
 	switch (ret) {
 	case Z_OK:
@@ -86,25 +91,26 @@
 	    /* all ok */
 	    /* Z_STREAM_END probably won't happen, since we didn't
 	       have a header */
-	    len = zff->zstr->total_out - out_before;
-	    if (len >= zff->bytes_left || len >= toread) {
-		zff->crc = crc32(zff->crc, outbuf, len);
-		zff->bytes_left -= len;
+	    len = zf->zstr->total_out - out_before;
+	    if (len >= zf->bytes_left || len >= toread) {
+		if (zf->flags & ZIP_ZF_CRC)
+		    zf->crc = crc32(zf->crc, (Bytef *)outbuf, len);
+		zf->bytes_left -= len;
 	        return len;
 	    }
 	    break;
 
 	case Z_BUF_ERROR:
-	    if (zff->zstr->avail_in == 0) {
-		len = _zip_file_fillbuf(zff->buffer, BUFSIZE, zff);
-		if (len == 0) {
-		    _zip_error_set(&zff->error, ZERR_INCONS, 0);
+	    if (zf->zstr->avail_in == 0) {
+		i = _zip_file_fillbuf(zf->buffer, BUFSIZE, zf);
+		if (i == 0) {
+		    _zip_error_set(&zf->error, ZIP_ER_INCONS, 0);
 		    return -1;
 		}
-		else if (len < 0)
+		else if (i < 0)
 		    return -1;
-		zff->zstr->next_in = zff->buffer;
-		zff->zstr->avail_in = len;
+		zf->zstr->next_in = (Bytef *)zf->buffer;
+		zf->zstr->avail_in = i;
 		continue;
 	    }
 	    /* fallthrough */
@@ -112,7 +118,7 @@
 	case Z_DATA_ERROR:
 	case Z_STREAM_ERROR:
 	case Z_MEM_ERROR:
-	    _zip_error_set(&zff->error, ZERR_ZLIB, ret);
+	    _zip_error_set(&zf->error, ZIP_ER_ZLIB, ret);
 	    return -1;
 	}
     }
diff --git a/lib/zip_free.c b/lib/zip_free.c
index e3cd191..8edbf99 100644
--- a/lib/zip_free.c
+++ b/lib/zip_free.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_free.c,v 1.8.4.1 2004/04/06 20:30:04 dillo Exp $
+  $NiH: zip_free.c,v 1.16 2005/01/11 17:40:56 dillo Exp $
 
   zip_free.c -- free struct zip
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -46,36 +46,38 @@
    corresponding file. */
 
 void
-_zip_free(struct zip *zf)
+_zip_free(struct zip *za)
 {
     int i;
 
-    if (zf == NULL)
+    if (za == NULL)
 	return;
 
-    if (zf->zn)
-	free(zf->zn);
+    if (za->zn)
+	free(za->zn);
 
-    if (zf->zp)
-	fclose(zf->zp);
+    if (za->zp)
+	fclose(za->zp);
 
-    _zip_cdir_free(zf->cdir);
+    _zip_cdir_free(za->cdir);
 
-    if (zf->entry) {
-	for (i=0; i<zf->nentry; i++) {
-	    _zip_free_entry(zf->entry+i);
+    if (za->entry) {
+	for (i=0; i<za->nentry; i++) {
+	    _zip_entry_free(za->entry+i);
 	}
-	free (zf->entry);
+	free(za->entry);
     }
 
-    for (i=0; i<zf->nfile; i++) {
-	zf->file[i]->flags = ZERR_ZIPCLOSED;
-	zf->file[i]->zf = NULL;
+    for (i=0; i<za->nfile; i++) {
+	if (za->file[i]->error.zip_err == ZIP_ER_OK) {
+	    _zip_error_set(&za->file[i]->error, ZIP_ER_ZIPCLOSED, 0);
+	    za->file[i]->za = NULL;
+	}
     }
 
-    free(zf->file);
+    free(za->file);
     
-    free(zf);
+    free(za);
 
     return;
 }
diff --git a/lib/zip_add_filep.c b/lib/zip_get_archive_comment.c
similarity index 73%
rename from lib/zip_add_filep.c
rename to lib/zip_get_archive_comment.c
index 7fd3aaf..67efd99 100644
--- a/lib/zip_add_filep.c
+++ b/lib/zip_get_archive_comment.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_add_filep.c,v 1.6 2003/10/02 14:13:28 dillo Exp $
+  $NiH: zip_get_archive_comment.c,v 1.4 2006/04/23 16:11:33 wiz Exp $
 
-  zip_add_filep.c -- add file from FILE*
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_get_archive_comment.c -- get archive comment
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -40,14 +40,24 @@
 
 
 
-int
-zip_add_filep(struct zip *zf, const char *name,
-	      FILE *file, off_t start, off_t len)
+const char *
+zip_get_archive_comment(struct zip *za, int *lenp, int flags)
 {
-    if (name == NULL) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
-	return -1;
+    if ((flags & ZIP_FL_UNCHANGED)
+	|| (za->ch_comment_len == -1)) {
+	if (za->cdir) {
+	    if (lenp != NULL)
+		*lenp = za->cdir->comment_len;
+	    return za->cdir->comment;
+	}
+	else {
+	    if (lenp != NULL)
+		*lenp = -1;
+	    return NULL;
+	}
     }
-
-    return _zip_replace_filep(zf, -1, name, file, start, len);
+    
+    if (lenp != NULL)
+	*lenp = za->ch_comment_len;
+    return za->ch_comment;
 }
diff --git a/lib/zip_free_entry.c b/lib/zip_get_file_comment.c
similarity index 71%
copy from lib/zip_free_entry.c
copy to lib/zip_get_file_comment.c
index 033061b..23e2fe7 100644
--- a/lib/zip_free_entry.c
+++ b/lib/zip_get_file_comment.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_free_entry.c,v 1.9.4.2 2004/03/22 14:17:33 dillo Exp $
+  $NiH: zip_get_file_comment.c,v 1.1 2006/04/09 19:05:47 wiz Exp $
 
-  zip_free_entry.c -- free struct zip_entry
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_get_file_comment.c -- get file comment
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -35,24 +35,27 @@
 
 
 
-#include <stdlib.h>
-
 #include "zip.h"
 #include "zipint.h"
 
 
 
-int
-_zip_free_entry(struct zip_entry *ze)
+const char *
+zip_get_file_comment(struct zip *za, int idx, int *lenp, int flags)
 {
-    int ret;
+    if (idx < 0 || idx >= za->nentry) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+	return NULL;
+    }
 
-    ret = 0;
+    if ((flags & ZIP_FL_UNCHANGED)
+	|| (za->entry[idx].ch_comment_len == -1)) {
+	if (lenp != NULL)
+	    *lenp = za->cdir->entry[idx].comment_len;
+	return za->cdir->entry[idx].comment;
+    }
     
-    free(ze->ch_filename);
-    
-    if (ze->ch_func)
-	ret = ze->ch_func(ze->ch_data, NULL, 0, ZIP_CMD_CLOSE);
-
-    return ret;
+    if (lenp != NULL)
+	*lenp = za->entry[idx].ch_comment_len;
+    return za->entry[idx].ch_comment;
 }
diff --git a/lib/zip_get_name.c b/lib/zip_get_name.c
index 985bd79..8439bce 100644
--- a/lib/zip_get_name.c
+++ b/lib/zip_get_name.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_get_name.c,v 1.6 2003/10/06 16:37:41 dillo Exp $
+  $NiH: zip_get_name.c,v 1.12 2004/11/30 23:02:46 wiz Exp $
 
   zip_get_name.c -- get filename for a file in zip file
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -41,15 +41,34 @@
 
 
 const char *
-zip_get_name(struct zip *zf, int idx)
+zip_get_name(struct zip *za, int idx, int flags)
 {
-    if (idx < 0 || idx >= zf->nentry) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
+    return _zip_get_name(za, idx, flags, &za->error);
+}
+
+
+
+const char *
+_zip_get_name(struct zip *za, int idx, int flags, struct zip_error *error)
+{
+    if (idx < 0 || idx >= za->nentry) {
+	_zip_error_set(error, ZIP_ER_INVAL, 0);
 	return NULL;
     }
 
-    if (zf->entry[idx].ch_filename)
-	return zf->entry[idx].ch_filename;
+    if ((flags & ZIP_FL_UNCHANGED) == 0) {
+	if (za->entry[idx].state == ZIP_ST_DELETED) {
+	    _zip_error_set(error, ZIP_ER_DELETED, 0);
+	    return NULL;
+	}
+	if (za->entry[idx].ch_filename)
+	    return za->entry[idx].ch_filename;
+    }
 
-    return zf->cdir->entry[idx].filename;
+    if (za->cdir == NULL || idx >= za->cdir->nentry) {
+	_zip_error_set(error, ZIP_ER_INVAL, 0);
+	return NULL;
+    }
+    
+    return za->cdir->entry[idx].filename;
 }
diff --git a/lib/zip_free_entry.c b/lib/zip_memdup.c
similarity index 78%
copy from lib/zip_free_entry.c
copy to lib/zip_memdup.c
index 033061b..4f38a01 100644
--- a/lib/zip_free_entry.c
+++ b/lib/zip_memdup.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_free_entry.c,v 1.9.4.2 2004/03/22 14:17:33 dillo Exp $
+  $NiH: zip_memdup.c,v 1.1 2006/04/23 00:40:47 wiz Exp $
 
-  zip_free_entry.c -- free struct zip_entry
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_memdup.c -- internal zip function, "strdup" with len
+  Copyright (C) 1999, 2003, 2004, 2005, 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -33,26 +33,26 @@
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-
-
 #include <stdlib.h>
+#include <string.h>
 
 #include "zip.h"
 #include "zipint.h"
 
 
 
-int
-_zip_free_entry(struct zip_entry *ze)
+void *
+_zip_memdup(const void *mem, size_t len, struct zip_error *error)
 {
-    int ret;
+    void *ret;
 
-    ret = 0;
-    
-    free(ze->ch_filename);
-    
-    if (ze->ch_func)
-	ret = ze->ch_func(ze->ch_data, NULL, 0, ZIP_CMD_CLOSE);
+    ret = malloc(len);
+    if (!ret) {
+	_zip_error_set(error, ZIP_ER_MEMORY, 0);
+	return NULL;
+    }
+
+    memcpy(ret, mem, len);
 
     return ret;
 }
diff --git a/lib/zip_name_locate.c b/lib/zip_name_locate.c
index bfbea50..0668aa6 100644
--- a/lib/zip_name_locate.c
+++ b/lib/zip_name_locate.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_name_locate.c,v 1.9.4.2 2004/04/14 09:21:34 dillo Exp $
+  $NiH: zip_name_locate.c,v 1.18 2005/01/11 18:52:42 wiz Exp $
 
   zip_name_locate.c -- get index by name
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -45,31 +45,47 @@
 int
 zip_name_locate(struct zip *za, const char *fname, int flags)
 {
-    int (*cmp)();
+    return _zip_name_locate(za, fname, flags, &za->error);
+}
+
+
+
+int
+_zip_name_locate(struct zip *za, const char *fname, int flags,
+		 struct zip_error *error)
+{
+    int (*cmp)(const char *, const char *);
     const char *fn, *p;
-    int i;
+    int i, n;
 
     if (fname == NULL) {
-	_zip_error_set(&za->error, ZERR_INVAL, 0);
+	_zip_error_set(error, ZIP_ER_INVAL, 0);
 	return -1;
     }
     
-    cmp = (flags & ZIP_FL_NOCASE) ? strcmp : strcasecmp;
+    cmp = (flags & ZIP_FL_NOCASE) ? strcasecmp : strcmp;
 
-    /* XXX: honour ZIP_FL_UNCHANGED */
+    n = (flags & ZIP_FL_UNCHANGED) ? za->cdir->nentry : za->nentry;
+    for (i=0; i<n; i++) {
+	if (flags & ZIP_FL_UNCHANGED)
+	    fn = za->cdir->entry[i].filename;
+	else
+	    fn = _zip_get_name(za, i, flags, error);
 
-    for (i=0; i<za->nentry; i++) {
-	fn = zip_get_name(za, i);
+	/* newly added (partially filled) entry */
+	if (fn == NULL)
+	    continue;
+	
 	if (flags & ZIP_FL_NODIR) {
-	    /* XXX: handle '\' */
-	    if ((p=strrchr(fn, '/')) != NULL)
-		fn = p;
+	    p = strrchr(fn, '/');
+	    if (p)
+		fn = p+1;
 	}
 
 	if (cmp(fname, fn) == 0)
 	    return i;
     }
 
-    _zip_error_set(&za->error, ZERR_NOENT, 0);
+    _zip_error_set(error, ZIP_ER_NOENT, 0);
     return -1;
 }
diff --git a/lib/zip_new.c b/lib/zip_new.c
index 0b880ae..8c614ed 100644
--- a/lib/zip_new.c
+++ b/lib/zip_new.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_new.c,v 1.6.4.2 2004/03/23 16:08:46 dillo Exp $
+  $NiH: zip_new.c,v 1.11 2005/06/09 19:57:10 dillo Exp $
 
   zip_new.c -- create and init struct zip
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -52,16 +52,19 @@
 
     za = (struct zip *)malloc(sizeof(struct zip));
     if (!za) {
-	_zip_error_set(error, ZERR_MEMORY, 0);
+	_zip_error_set(error, ZIP_ER_MEMORY, 0);
 	return NULL;
     }
 
     za->zn = NULL;
     za->zp = NULL;
-    za->nentry = za->nentry_alloc = 0;
-    za->nfile = za->nfile_alloc = 0;
+    _zip_error_init(&za->error);
     za->cdir = NULL;
+    za->ch_comment = NULL;
+    za->ch_comment_len = -1;
+    za->nentry = za->nentry_alloc = 0;
     za->entry = NULL;
+    za->nfile = za->nfile_alloc = 0;
     za->file = NULL;
     
     return za;
diff --git a/lib/zip_open.c b/lib/zip_open.c
index 41d52f5..6a69036 100644
--- a/lib/zip_open.c
+++ b/lib/zip_open.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_open.c,v 1.19.4.5 2004/04/06 20:30:06 dillo Exp $
+  $NiH: zip_open.c,v 1.42 2007/02/28 18:08:39 wiz Exp $
 
   zip_open.c -- open zip archive
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2007 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -35,25 +35,26 @@
 
 
 
+#include <sys/stat.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 
 #include "zip.h"
 #include "zipint.h"
 
 static void set_error(int *, struct zip_error *, int);
+static struct zip *_zip_allocate_new(const char *, int *);
 static int _zip_checkcons(FILE *, struct zip_cdir *, struct zip_error *);
+static struct zip_cdir *_zip_find_central_dir(FILE *, int, int *, off_t);
+static int _zip_file_exists(const char *, int, int *);
 static int _zip_headercomp(struct zip_dirent *, int,
 			   struct zip_dirent *, int);
 static unsigned char *_zip_memmem(const unsigned char *, int,
 				  const unsigned char *, int);
 static struct zip_cdir *_zip_readcdir(FILE *, unsigned char *, unsigned char *,
-				 int, struct zip_error *);
+				 int, int, struct zip_error *);
 
 
 
@@ -61,145 +62,60 @@
 zip_open(const char *fn, int flags, int *zep)
 {
     FILE *fp;
-    unsigned char *buf, *match;
-    int a, i, buflen, best;
     struct zip *za;
-    struct zip_cdir *cdir, *cdirnew;
-    long len;
-    struct stat st;
-    struct zip_error error, err2;
+    struct zip_cdir *cdir;
+    int i;
+    off_t len;
+    
+    switch (_zip_file_exists(fn, flags, zep)) {
+    case -1:
+	return NULL;
+    case 0:
+	return _zip_allocate_new(fn, zep);
+    default:
+	break;
+    }
 
-    if (fn == NULL) {
-	set_error(zep, NULL, ZERR_INVAL);
-	return NULL;
-    }
-    
-    if (stat(fn, &st) != 0) {
-	if (flags & ZIP_CREATE) {
-	    if ((za=_zip_new(&error)) == NULL) {
-		set_error(zep, &error, 0);
-		return NULL;
-	    }
-	    
-	    za->zn = strdup(fn);
-	    if (!za->zn) {
-		_zip_free(za);
-		set_error(zep, NULL, ZERR_MEMORY);
-		return NULL;
-	    }
-	    return za;
-	}
-	else {
-	    set_error(zep, NULL, ZERR_OPEN);
-	    return NULL;
-	}
-    }
-    else if ((flags & ZIP_EXCL)) {
-	set_error(zep, NULL, ZERR_EXISTS);
-	return NULL;
-    }
-    /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL,
-       just like open() */
-    
     if ((fp=fopen(fn, "rb")) == NULL) {
-	set_error(zep, NULL, ZERR_OPEN);
+	set_error(zep, NULL, ZIP_ER_OPEN);
 	return NULL;
     }
-    
-    clearerr(fp);
-    fseek(fp, 0, SEEK_END);
-    len = ftell(fp);
-    i = fseek(fp, -(len < BUFSIZE ? len : BUFSIZE), SEEK_END);
-    if (i == -1 && errno != EFBIG) {
-	/* seek before start of file on my machine */
-	set_error(zep, NULL, ZERR_SEEK);
+
+    fseeko(fp, 0, SEEK_END);
+    len = ftello(fp);
+
+    /* treat empty files as empty archives */
+    if (len == 0) {
+	if ((za=_zip_allocate_new(fn, zep)) == NULL)
+	    fclose(fp);
+	else
+	    za->zp = fp;
+	return za;
+    }
+
+    cdir = _zip_find_central_dir(fp, flags, zep, len);
+    if (cdir == NULL) {
 	fclose(fp);
 	return NULL;
     }
 
-    /* 64k is too much for stack */
-    if ((buf=(unsigned char *)malloc(BUFSIZE)) == NULL) {
-	set_error(zep, NULL, ZERR_MEMORY);
-	fclose(fp);
-	return NULL;
-    }
-
-    clearerr(fp);
-    buflen = fread(buf, 1, BUFSIZE, fp);
-
-    if (ferror(fp)) {
-	set_error(zep, NULL, ZERR_READ);
-	free(buf);
-	fclose(fp);
-	return NULL;
-    }
-    
-    best = -1;
-    cdir = NULL;
-    match = buf;
-    while ((match=_zip_memmem(match, buflen-(match-buf)-18,
-			      EOCD_MAGIC, 4))!=NULL) {
-	/* found match -- check, if good */
-	/* to avoid finding the same match all over again */
-	match++;
-	if ((cdirnew=_zip_readcdir(fp, buf, match-1, buflen, &err2)) == NULL)
-	    continue;	    
-
-	if (cdir) {
-	    if (best <= 0)
-		best = _zip_checkcons(fp, cdir, &err2);
-	    a = _zip_checkcons(fp, cdirnew, &err2);
-	    if (best < a) {
-		_zip_cdir_free(cdir);
-		cdir = cdirnew;
-		best = a;
-	    }
-	    else
-		_zip_cdir_free(cdirnew);
-	}
-	else {
-	    cdir = cdirnew;
-	    if (flags & ZIP_CHECKCONS)
-		best = _zip_checkcons(fp, cdir, &err2);
-	    else
-		best = 0;
-	}
-	cdirnew = NULL;
-    }
-
-    free(buf);
-    
-    if (best < 0) {
-	/* no consistent eocd found */
-	set_error(zep, NULL, ZERR_NOZIP);
+    if ((za=_zip_allocate_new(fn, zep)) == NULL) {
 	_zip_cdir_free(cdir);
 	fclose(fp);
 	return NULL;
     }
 
-    if ((za=_zip_new(&error)) == NULL) {
-	set_error(zep, &error, 0);
-	_zip_cdir_free(cdir);
-	fclose(fp);
-	return NULL;
-    }
-
-    za->zp = fp;
     za->cdir = cdir;
-    
-    if ((za->zn=strdup(fn)) == NULL) {
-	set_error(zep, NULL, ZERR_MEMORY);
-	_zip_free(za);
-	return NULL;
-    }
+    za->zp = fp;
 
-    if ((za->entry=malloc(sizeof(*(za->entry))*cdir->nentry)) == NULL) {
-	set_error(zep, NULL, ZERR_MEMORY);
+    if ((za->entry=(struct zip_entry *)malloc(sizeof(*(za->entry))
+					      * cdir->nentry)) == NULL) {
+	set_error(zep, NULL, ZIP_ER_MEMORY);
 	_zip_free(za);
 	return NULL;
     }
     for (i=0; i<cdir->nentry; i++)
-	_zip_new_entry(za);
+	_zip_entry_new(za);
 
     return za;
 }
@@ -213,7 +129,7 @@
 
     if (err) {
 	_zip_error_get(err, &ze, &se);
-	if (zip_error_sys_type(ze) == ZIP_ET_SYS)
+	if (zip_error_get_sys_type(ze) == ZIP_ET_SYS)
 	    errno = se;
     }
 
@@ -231,7 +147,7 @@
 
 static struct zip_cdir *
 _zip_readcdir(FILE *fp, unsigned char *buf, unsigned char *eocd, int buflen,
-	      struct zip_error *error)
+	      int flags, struct zip_error *error)
 {
     struct zip_cdir *cd;
     unsigned char *cdp, **bufp;
@@ -240,18 +156,18 @@
     comlen = buf + buflen - eocd - EOCDLEN;
     if (comlen < 0) {
 	/* not enough bytes left for comment */
-	_zip_error_set(error, ZERR_NOZIP, 0);
+	_zip_error_set(error, ZIP_ER_NOZIP, 0);
 	return NULL;
     }
 
     /* check for end-of-central-dir magic */
     if (memcmp(eocd, EOCD_MAGIC, 4) != 0) {
-	_zip_error_set(error, ZERR_NOZIP, 0);
+	_zip_error_set(error, ZIP_ER_NOZIP, 0);
 	return NULL;
     }
 
     if (memcmp(eocd+4, "\0\0\0\0", 4) != 0) {
-	_zip_error_set(error, ZERR_MULTIDISK, 0);
+	_zip_error_set(error, ZIP_ER_MULTIDISK, 0);
 	return NULL;
     }
 
@@ -269,22 +185,27 @@
     cd->comment = NULL;
     cd->comment_len = _zip_read2(&cdp);
 
-    /* XXX: some zip files are broken; their internal comment length
-       says 0, but they have 1 or 2 comment bytes */
-    if ((comlen-cd->comment_len < 0) || (comlen-cd->comment_len > 2)
-	|| (cd->nentry != i)) {
-	/* comment size wrong -- too few or too many left after central dir */
-	/* or number of cdir-entries on this disk != number of cdir-entries */
-	_zip_error_set(error, ZERR_NOZIP, 0);
+    if ((comlen < cd->comment_len) || (cd->nentry != i)) {
+	_zip_error_set(error, ZIP_ER_NOZIP, 0);
+	free(cd);
+	return NULL;
+    }
+    if ((flags & ZIP_CHECKCONS) && comlen != cd->comment_len) {
+	_zip_error_set(error, ZIP_ER_INCONS, 0);
 	free(cd);
 	return NULL;
     }
 
     if (cd->comment_len)
-	cd->comment = _zip_memdup(eocd+EOCDLEN, cd->comment_len);
+	if ((cd->comment=(char *)_zip_memdup(eocd+EOCDLEN,
+					     cd->comment_len, error))
+	    == NULL) {
+	    free(cd);
+	    return NULL;
+	}
 
     cdp = eocd;
-    if (cd->size < eocd-buf) {
+    if (cd->size < (unsigned int)(eocd-buf)) {
 	/* if buffer already read in, use it */
 	cdp = eocd - cd->size;
 	bufp = &cdp;
@@ -293,13 +214,15 @@
 	/* go to start of cdir and read it entry by entry */
 	bufp = NULL;
 	clearerr(fp);
-	fseek(fp, -(cd->size+cd->comment_len+EOCDLEN), SEEK_END);
-	if (ferror(fp) || (ftell(fp) != cd->offset)) {
+	fseeko(fp, cd->offset, SEEK_SET);
+	/* possible consistency check: cd->offset =
+	   len-(cd->size+cd->comment_len+EOCDLEN) ? */
+	if (ferror(fp) || ((unsigned long)ftello(fp) != cd->offset)) {
 	    /* seek error or offset of cdir wrong */
 	    if (ferror(fp))
-		_zip_error_set(error, ZERR_SEEK, errno);
+		_zip_error_set(error, ZIP_ER_SEEK, errno);
 	    else
-		_zip_error_set(error, ZERR_NOZIP, 0);
+		_zip_error_set(error, ZIP_ER_NOZIP, 0);
 	    free(cd);
 	    return NULL;
 	}
@@ -328,21 +251,22 @@
 static int
 _zip_checkcons(FILE *fp, struct zip_cdir *cd, struct zip_error *error)
 {
-    int min, max, i, j;
+    int i;
+    unsigned int min, max, j;
     struct zip_dirent temp;
-    unsigned char *buf;
 
-    buf = NULL;
     if (cd->nentry) {
 	max = cd->entry[0].offset;
 	min = cd->entry[0].offset;
     }
+    else
+	min = max = 0;
 
     for (i=0; i<cd->nentry; i++) {
 	if (cd->entry[i].offset < min)
 	    min = cd->entry[i].offset;
-	if (min < 0) {
-	    _zip_error_set(error, ZERR_NOZIP, 0);
+	if (min > cd->offset) {
+	    _zip_error_set(error, ZIP_ER_NOZIP, 0);
 	    return -1;
 	}
 	
@@ -351,12 +275,12 @@
 	if (j > max)
 	    max = j;
 	if (max > cd->offset) {
-	    _zip_error_set(error, ZERR_NOZIP, 0);
+	    _zip_error_set(error, ZIP_ER_NOZIP, 0);
 	    return -1;
 	}
 	
-	if (fseek(fp, cd->entry[i].offset, SEEK_SET) != 0) {
-	    _zip_error_set(error, ZERR_SEEK, 0);
+	if (fseeko(fp, cd->entry[i].offset, SEEK_SET) != 0) {
+	    _zip_error_set(error, ZIP_ER_SEEK, 0);
 	    return -1;
 	}
 	
@@ -364,7 +288,7 @@
 	    return -1;
 	
 	if (_zip_headercomp(cd->entry+i, 0, &temp, 1) != 0) {
-	    _zip_error_set(error, ZERR_NOZIP, 0);
+	    _zip_error_set(error, ZIP_ER_INCONS, 0);
 	    _zip_dirent_finalize(&temp);
 	    return -1;
 	}
@@ -393,14 +317,32 @@
 #endif
 	|| (h1->comp_method != h2->comp_method)
 	|| (h1->last_mod != h2->last_mod)
-	|| (h1->crc != h2->crc)
-	|| (h1->comp_size != h2->comp_size)
-	|| (h1->uncomp_size != h2->uncomp_size)
 	|| (h1->filename_len != h2->filename_len)
 	|| !h1->filename || !h2->filename
 	|| strcmp(h1->filename, h2->filename))
 	return -1;
 
+    /* check that CRC and sizes are zero if data descriptor is used */
+    if ((h1->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) && local1p
+	&& (h1->crc != 0
+	    || h1->comp_size != 0
+	    || h1->uncomp_size != 0))
+	return -1;
+    if ((h2->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) && local2p
+	&& (h2->crc != 0
+	    || h2->comp_size != 0
+	    || h2->uncomp_size != 0))
+	return -1;
+    
+    /* check that CRC and sizes are equal if no data descriptor is used */
+    if (((h1->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0 || local1p == 0)
+	&& ((h2->bitflags & ZIP_GPBF_DATA_DESCRIPTOR) == 0 || local2p == 0)) {
+	if ((h1->crc != h2->crc)
+	    || (h1->comp_size != h2->comp_size)
+	    || (h1->uncomp_size != h2->uncomp_size))
+	    return -1;
+    }
+    
     if ((local1p == local2p)
 	&& ((h1->extrafield_len != h2->extrafield_len)
 	    || (h1->extrafield_len && h2->extrafield
@@ -427,6 +369,137 @@
 
 
 
+static struct zip *
+_zip_allocate_new(const char *fn, int *zep)
+{
+    struct zip *za;
+    struct zip_error error;
+
+    if ((za=_zip_new(&error)) == NULL) {
+	set_error(zep, &error, 0);
+	return NULL;
+    }
+	
+    za->zn = strdup(fn);
+    if (!za->zn) {
+	_zip_free(za);
+	set_error(zep, NULL, ZIP_ER_MEMORY);
+	return NULL;
+    }
+    return za;
+}
+
+
+
+static int
+_zip_file_exists(const char *fn, int flags, int *zep)
+{
+    struct stat st;
+
+    if (fn == NULL) {
+	set_error(zep, NULL, ZIP_ER_INVAL);
+	return -1;
+    }
+    
+    if (stat(fn, &st) != 0) {
+	if (flags & ZIP_CREATE)
+	    return 0;
+	else {
+	    set_error(zep, NULL, ZIP_ER_OPEN);
+	    return -1;
+	}
+    }
+    else if ((flags & ZIP_EXCL)) {
+	set_error(zep, NULL, ZIP_ER_EXISTS);
+	return -1;
+    }
+    /* ZIP_CREATE gets ignored if file exists and not ZIP_EXCL,
+       just like open() */
+
+    return 1;
+}
+
+
+
+static struct zip_cdir *
+_zip_find_central_dir(FILE *fp, int flags, int *zep, off_t len)
+{
+    struct zip_cdir *cdir, *cdirnew;
+    unsigned char *buf, *match;
+    int a, best, buflen, i;
+    struct zip_error zerr;
+
+    i = fseeko(fp, -(len < CDBUFSIZE ? len : CDBUFSIZE), SEEK_END);
+    if (i == -1 && errno != EFBIG) {
+	/* seek before start of file on my machine */
+	set_error(zep, NULL, ZIP_ER_SEEK);
+	return NULL;
+    }
+
+    /* 64k is too much for stack */
+    if ((buf=(unsigned char *)malloc(CDBUFSIZE)) == NULL) {
+	set_error(zep, NULL, ZIP_ER_MEMORY);
+	return NULL;
+    }
+
+    clearerr(fp);
+    buflen = fread(buf, 1, CDBUFSIZE, fp);
+
+    if (ferror(fp)) {
+	set_error(zep, NULL, ZIP_ER_READ);
+	free(buf);
+	return NULL;
+    }
+    
+    best = -1;
+    cdir = NULL;
+    match = buf;
+    _zip_error_set(&zerr, ZIP_ER_NOZIP, 0);
+
+    while ((match=_zip_memmem(match, buflen-(match-buf)-18,
+			      (const unsigned char *)EOCD_MAGIC, 4))!=NULL) {
+	/* found match -- check, if good */
+	/* to avoid finding the same match all over again */
+	match++;
+	if ((cdirnew=_zip_readcdir(fp, buf, match-1, buflen, flags,
+				   &zerr)) == NULL)
+	    continue;
+
+	if (cdir) {
+	    if (best <= 0)
+		best = _zip_checkcons(fp, cdir, &zerr);
+	    a = _zip_checkcons(fp, cdirnew, &zerr);
+	    if (best < a) {
+		_zip_cdir_free(cdir);
+		cdir = cdirnew;
+		best = a;
+	    }
+	    else
+		_zip_cdir_free(cdirnew);
+	}
+	else {
+	    cdir = cdirnew;
+	    if (flags & ZIP_CHECKCONS)
+		best = _zip_checkcons(fp, cdir, &zerr);
+	    else
+		best = 0;
+	}
+	cdirnew = NULL;
+    }
+
+    free(buf);
+    
+    if (best < 0) {
+	set_error(zep, &zerr, 0);
+	_zip_cdir_free(cdir);
+	return NULL;
+    }
+
+    return cdir;
+}
+
+
+
 static unsigned char *
 _zip_memmem(const unsigned char *big, int biglen, const unsigned char *little, 
        int littlelen)
@@ -436,28 +509,12 @@
     if ((biglen < littlelen) || (littlelen == 0))
 	return NULL;
     p = big-1;
-    while ((p=memchr(p+1, little[0], big-(p+1)+biglen-littlelen+1))!=NULL) {
+    while ((p=(const unsigned char *)
+	        memchr(p+1, little[0], (size_t)(big-(p+1)+biglen-littlelen+1)))
+	   != NULL) {
 	if (memcmp(p+1, little+1, littlelen-1)==0)
 	    return (unsigned char *)p;
     }
 
     return NULL;
 }
-
-
-
-void *
-_zip_memdup(const void *mem, int len)
-{
-    void *ret;
-
-    ret = malloc(len);
-    if (!ret) {
-	/* XXX: zip_err = ZERR_MEMORY; */
-	return NULL;
-    }
-
-    memcpy(ret, mem, len);
-
-    return ret;
-}
diff --git a/lib/zip_rename.c b/lib/zip_rename.c
index 00b7bee..7e75d2b 100644
--- a/lib/zip_rename.c
+++ b/lib/zip_rename.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_rename.c,v 1.10 2003/10/06 16:37:41 dillo Exp $
+  $NiH: zip_rename.c,v 1.14 2004/11/18 17:11:22 wiz Exp $
 
   zip_rename.c -- rename file in zip archive
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -41,18 +41,12 @@
 
 
 int
-zip_rename(struct zip *zf, int idx, const char *name)
+zip_rename(struct zip *za, int idx, const char *name)
 {
-    if (idx >= zf->nentry || idx < 0) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
+    if (idx >= za->nentry || idx < 0) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
 	return -1;
     }
 
-    /* XXX: move this to _zip_set_name */
-    if (zf->entry[idx].state == ZIP_ST_UNCHANGED) 
-	zf->entry[idx].state = ZIP_ST_RENAMED;
-    
-    _zip_set_name(zf, idx, name);
-
-    return 0;
+    return _zip_set_name(za, idx, name);
 }
diff --git a/lib/zip_replace.c b/lib/zip_replace.c
index 7ae05f6..9d62199 100644
--- a/lib/zip_replace.c
+++ b/lib/zip_replace.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_replace.c,v 1.11.4.2 2004/04/06 20:30:06 dillo Exp $
+  $NiH: zip_replace.c,v 1.19 2004/11/30 22:19:38 wiz Exp $
 
   zip_replace.c -- replace file via callback function
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2003, 2004, 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -41,41 +41,41 @@
 
 
 int
-zip_replace(struct zip *zf, int idx, zip_read_func fn, void *state, int flags)
+zip_replace(struct zip *za, int idx, struct zip_source *source)
 {
-    if (idx < 0 || idx >= zf->nentry) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
+    if (idx < 0 || idx >= za->nentry || source == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
 	return -1;
     }
 
-    return _zip_replace(zf, idx, NULL, fn, state, flags);
+    if (_zip_replace(za, idx, NULL, source) == -1)
+	return -1;
+
+    return 0;
 }
 
 
 
 
 int
-_zip_replace(struct zip *zf, int idx, const char *name,
-	     zip_read_func fn, void *state, int flags)
+_zip_replace(struct zip *za, int idx, const char *name,
+	     struct zip_source *source)
 {
     if (idx == -1) {
-	if (_zip_new_entry(zf) == NULL)
+	if (_zip_entry_new(za) == NULL)
 	    return -1;
 
-	idx = zf->nentry - 1;
+	idx = za->nentry - 1;
     }
     
-    if (_zip_unchange_data(zf->entry+idx) != 0)
-	return -1;
+    _zip_unchange_data(za->entry+idx);
 
-    if (_zip_set_name(zf, idx, name) != 0)
+    if (name && _zip_set_name(za, idx, name) != 0)
 	return -1;
     
-    zf->entry[idx].state = ((zf->cdir == NULL || idx >= zf->cdir->nentry)
+    za->entry[idx].state = ((za->cdir == NULL || idx >= za->cdir->nentry)
 			    ? ZIP_ST_ADDED : ZIP_ST_REPLACED);
-    zf->entry[idx].ch_func = fn;
-    zf->entry[idx].ch_data = state;
-    zf->entry[idx].ch_flags = flags;
+    za->entry[idx].source = source;
 
-    return 0;
+    return idx;
 }
diff --git a/lib/zip_replace_data.c b/lib/zip_replace_data.c
deleted file mode 100644
index 91b60af..0000000
--- a/lib/zip_replace_data.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
-  $NiH: zip_replace_data.c,v 1.12 2003/10/02 14:13:32 dillo Exp $
-
-  zip_replace_data.c -- replace file from buffer
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
-
-  This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-  1. Redistributions of source code must retain the above copyright
-     notice, this list of conditions and the following disclaimer.
-  2. Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in
-     the documentation and/or other materials provided with the
-     distribution.
-  3. The names of the authors may not be used to endorse or promote
-     products derived from this software without specific prior
-     written permission.
- 
-  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
-  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
-  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "zip.h"
-#include "zipint.h"
-
-struct read_data {
-    const char *buf, *data;
-    off_t len;
-    int freep;
-};
-
-static ssize_t read_data(void *state, void *data, size_t len,
-			 enum zip_cmd cmd);
-
-
-
-int
-zip_replace_data(struct zip *zf, int idx,
-		 const void *data, off_t len, int freep)
-{
-    if (idx < 0 || idx >= zf->nentry) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
-	return -1;
-    }
-    
-    return _zip_replace_data(zf, idx, NULL, data, len, freep);
-}
-
-
-
-int
-_zip_replace_data(struct zip *zf, int idx, const char *name,
-		  const void *data, off_t len, int freep)
-{
-    struct read_data *f;
-
-    if ((f=malloc(sizeof(*f))) == NULL) {
-	_zip_error_set(&zf->error, ZERR_MEMORY, 0);
-	return -1;
-    }
-
-    f->data = data;
-    f->len = len;
-    f->freep = freep;
-    
-    return _zip_replace(zf, idx, name, read_data, f, 0);
-}
-
-
-
-static int
-read_data(void *state, void *data, size_t len, enum zip_cmd cmd)
-{
-    struct read_data *z;
-    char *buf;
-    int n;
-
-    z = (struct read_data *)state;
-    buf = (char *)data;
-
-    switch (cmd) {
-    case ZIP_CMD_INIT:
-	z->buf = z->data;
-	return 0;
-	
-    case ZIP_CMD_READ:
-	n = len > z->len ? z->len : len;
-	if (n < 0)
-	    n = 0;
-
-	if (n) {
-	    memcpy(buf, z->buf, n);
-	    z->buf += n;
-	    z->len -= n;
-	}
-
-	return n;
-	
-    case ZIP_CMD_CLOSE:
-	if (z->freep) {
-	    free((void *)z->data);
-	    z->data = NULL;
-	}
-	free(z);
-	return 0;
-
-    default:
-	;
-    }
-
-    return -1;
-}
diff --git a/lib/zip_replace_filep.c b/lib/zip_replace_filep.c
deleted file mode 100644
index a1b260f..0000000
--- a/lib/zip_replace_filep.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
-  $NiH: zip_replace_filep.c,v 1.7 2003/10/02 14:13:32 dillo Exp $
-
-  zip_replace_filep.c -- replace file from FILE*
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
-
-  This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-  1. Redistributions of source code must retain the above copyright
-     notice, this list of conditions and the following disclaimer.
-  2. Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in
-     the documentation and/or other materials provided with the
-     distribution.
-  3. The names of the authors may not be used to endorse or promote
-     products derived from this software without specific prior
-     written permission.
- 
-  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
-  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
-  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-
-#include <stdlib.h>
-
-#include "zip.h"
-#include "zipint.h"
-
-struct read_file {
-    FILE *f;
-    off_t off, len;
-};
-
-static int read_file(void *state, void *data, size_t len, enum zip_cmd cmd);
-
-
-
-int
-zip_replace_filep(struct zip *zf, int idx,
-		  FILE *file, off_t start, off_t len)
-{
-    if (idx < 0 || idx >= zf->nentry) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
-	return -1;
-    }
-    
-    return _zip_replace_filep(zf, idx, NULL, file, start, len);
-}
-
-
-
-int
-_zip_replace_filep(struct zip *zf, int idx, const char *name,
-		  FILE *file, off_t start, off_t len)
-{
-    struct read_file *f;
-
-    if ((f=(struct read_file *)malloc(sizeof(struct read_file))) == NULL) {
-	_zip_error_set(&zf->error, ZERR_MEMORY, 0);
-	return -1;
-    }
-
-    f->f = file;
-    f->off = start;
-    f->len = (len ? len : -1);
-    
-    return _zip_replace(zf, idx, name, read_file, f, 0);
-}
-
-
-
-static int
-read_file(void *state, void *data, size_t len, enum zip_cmd cmd)
-{
-    struct read_file *z;
-    char *buf;
-    int i, n;
-
-    z = (struct read_file *)state;
-    buf = (char *)data;
-
-    switch (cmd) {
-    case ZIP_CMD_INIT:
-	if (fseeko(z->f, z->off, SEEK_SET) < 0) {
-	    /* XXX: zip_err = ZERR_SEEK; */
-	    return -1;
-	}
-	return 0;
-	
-    case ZIP_CMD_READ:
-	if (z->len != -1)
-	    n = len > z->len ? z->len : len;
-	else
-	    n = len;
-	
-	if ((i=fread(buf, 1, n, z->f)) < 0) {
-	    /* XXX: zip_err = ZERR_READ; */
-	    return -1;
-	}
-
-	if (z->len != -1)
-	    z->len -= i;
-
-	return i;
-	
-    case ZIP_CMD_CLOSE:
-	if (z->f) {
-	    fclose(z->f);
-	    z->f = NULL;
-	}
-	free(z);
-	return 0;
-
-    default:
-	;
-    }
-
-    return -1;
-}
diff --git a/lib/zip_add_filep.c b/lib/zip_set_archive_comment.c
similarity index 71%
copy from lib/zip_add_filep.c
copy to lib/zip_set_archive_comment.c
index 7fd3aaf..86bb991 100644
--- a/lib/zip_add_filep.c
+++ b/lib/zip_set_archive_comment.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_add_filep.c,v 1.6 2003/10/02 14:13:28 dillo Exp $
+  $NiH: zip_set_archive_comment.c,v 1.2 2006/04/23 15:26:30 dillo Exp $
 
-  zip_add_filep.c -- add file from FILE*
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_set_archive_comment.c -- set archive comment
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -35,19 +35,34 @@
 
 
 
+#include <stdlib.h>
+
 #include "zip.h"
 #include "zipint.h"
 
 
 
 int
-zip_add_filep(struct zip *zf, const char *name,
-	      FILE *file, off_t start, off_t len)
+zip_set_archive_comment(struct zip *za, const char *comment, int len)
 {
-    if (name == NULL) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
+    char *tmpcom;
+
+    if (len < 0 || len > MAXCOMLEN
+	|| (len > 0 && comment == NULL)) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
 	return -1;
     }
 
-    return _zip_replace_filep(zf, -1, name, file, start, len);
+    if (len > 0) {
+	if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL)
+	    return -1;
+    }
+    else
+	tmpcom = NULL;
+
+    free(za->ch_comment);
+    za->ch_comment = tmpcom;
+    za->ch_comment_len = len;
+    
+    return 0;
 }
diff --git a/lib/zip_free_entry.c b/lib/zip_set_file_comment.c
similarity index 69%
copy from lib/zip_free_entry.c
copy to lib/zip_set_file_comment.c
index 033061b..28c8891 100644
--- a/lib/zip_free_entry.c
+++ b/lib/zip_set_file_comment.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_free_entry.c,v 1.9.4.2 2004/03/22 14:17:33 dillo Exp $
+  $NiH: zip_set_file_comment.c,v 1.3 2006/04/23 15:26:30 dillo Exp $
 
-  zip_free_entry.c -- free struct zip_entry
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_set_file_comment.c -- set comment for file in archive
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -43,16 +43,27 @@
 
 
 int
-_zip_free_entry(struct zip_entry *ze)
+zip_set_file_comment(struct zip *za, int idx, const char *comment, int len)
 {
-    int ret;
+    char *tmpcom;
 
-    ret = 0;
-    
-    free(ze->ch_filename);
-    
-    if (ze->ch_func)
-	ret = ze->ch_func(ze->ch_data, NULL, 0, ZIP_CMD_CLOSE);
+    if (idx < 0 || idx >= za->nentry
+	|| len < 0 || len > MAXCOMLEN
+	|| (len > 0 && comment == NULL)) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+	return -1;
+    }
 
-    return ret;
+    if (len > 0) {
+	if ((tmpcom=(char *)_zip_memdup(comment, len, &za->error)) == NULL)
+	    return -1;
+    }
+    else
+	tmpcom = NULL;
+
+    free(za->entry[idx].ch_comment);
+    za->entry[idx].ch_comment = tmpcom;
+    za->entry[idx].ch_comment_len = len;
+    
+    return 0;
 }
diff --git a/lib/zip_set_name.c b/lib/zip_set_name.c
index a86190f..38faabe 100644
--- a/lib/zip_set_name.c
+++ b/lib/zip_set_name.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_set_name.c,v 1.10 2003/10/06 16:37:41 dillo Exp $
+  $NiH: zip_set_name.c,v 1.15 2004/11/30 22:19:38 wiz Exp $
 
   zip_set_name.c -- rename helper function
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -43,24 +43,35 @@
 
 
 int
-_zip_set_name(struct zip *zf, int idx, const char *name)
+_zip_set_name(struct zip *za, int idx, const char *name)
 {
     char *s;
+    int i;
     
-    if (idx < 0 || idx >= zf->nentry) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
+    if (idx < 0 || idx >= za->nentry || name == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
 	return -1;
     }
 
-    if (name != NULL) {
-	if ((s=strdup(name)) == NULL) {
-	    _zip_error_set(&zf->error, ZERR_MEMORY, 0);
-	    return -1;
-	}
-	
-	free(zf->entry[idx].ch_filename);
-	zf->entry[idx].ch_filename = s;
+    if ((i=_zip_name_locate(za, name, 0, NULL)) != -1 && i != idx) {
+	_zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
+	return -1;
     }
 
+    /* no effective name change */
+    if (i == idx)
+	return 0;
+    
+    if ((s=strdup(name)) == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	return -1;
+    }
+    
+    if (za->entry[idx].state == ZIP_ST_UNCHANGED) 
+	za->entry[idx].state = ZIP_ST_RENAMED;
+
+    free(za->entry[idx].ch_filename);
+    za->entry[idx].ch_filename = s;
+
     return 0;
 }
diff --git a/lib/zip_source_buffer.c b/lib/zip_source_buffer.c
new file mode 100644
index 0000000..f76515c
--- /dev/null
+++ b/lib/zip_source_buffer.c
@@ -0,0 +1,160 @@
+/*
+  $NiH: zip_source_buffer.c,v 1.8 2006/04/23 14:50:49 wiz Exp $
+
+  zip_source_buffer.c -- create zip data source from buffer
+  Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "zip.h"
+#include "zipint.h"
+
+struct read_data {
+    const char *buf, *data, *end;
+    time_t mtime;
+    int freep;
+};
+
+static ssize_t read_data(void *state, void *data, size_t len,
+			 enum zip_source_cmd cmd);
+
+
+
+struct zip_source *
+zip_source_buffer(struct zip *za, const void *data, off_t len, int freep)
+{
+    struct read_data *f;
+    struct zip_source *zs;
+
+    if (za == NULL)
+	return NULL;
+
+    if (len < 0 || (data == NULL && len > 0)) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+	return NULL;
+    }
+
+    if ((f=(struct read_data *)malloc(sizeof(*f))) == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	return NULL;
+    }
+
+    f->data = (const char *)data;
+    f->end = ((const char *)data)+len;
+    f->freep = freep;
+    f->mtime = time(NULL);
+    
+    if ((zs=zip_source_function(za, read_data, f)) == NULL) {
+	free(f);
+	return NULL;
+    }
+
+    return zs;
+}
+
+
+
+static ssize_t
+read_data(void *state, void *data, size_t len, enum zip_source_cmd cmd)
+{
+    struct read_data *z;
+    char *buf;
+    size_t n;
+
+    z = (struct read_data *)state;
+    buf = (char *)data;
+
+    switch (cmd) {
+    case ZIP_SOURCE_OPEN:
+	z->buf = z->data;
+	return 0;
+	
+    case ZIP_SOURCE_READ:
+	n = z->end - z->buf;
+	if (n > len)
+	    n = len;
+
+	if (n) {
+	    memcpy(buf, z->buf, n);
+	    z->buf += n;
+	}
+
+	return n;
+	
+    case ZIP_SOURCE_CLOSE:
+	return 0;
+
+    case ZIP_SOURCE_STAT:
+        {
+	    struct zip_stat *st;
+	    
+	    if (len < sizeof(*st))
+		return -1;
+
+	    st = (struct zip_stat *)data;
+
+	    zip_stat_init(st);
+	    st->mtime = z->mtime;
+	    st->size = z->end - z->data;
+	    
+	    return sizeof(*st);
+	}
+
+    case ZIP_SOURCE_ERROR:
+	{
+	    int *e;
+
+	    if (len < sizeof(int)*2)
+		return -1;
+
+	    e = (int *)data;
+	    e[0] = e[1] = 0;
+	}
+	return sizeof(int)*2;
+
+    case ZIP_SOURCE_FREE:
+	if (z->freep) {
+	    free((void *)z->data);
+	    z->data = NULL;
+	}
+	free(z);
+	return 0;
+
+    default:
+	;
+    }
+
+    return -1;
+}
diff --git a/lib/zip_replace_file.c b/lib/zip_source_file.c
similarity index 71%
rename from lib/zip_replace_file.c
rename to lib/zip_source_file.c
index b8bc5a3..8715625 100644
--- a/lib/zip_replace_file.c
+++ b/lib/zip_source_file.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_replace_file.c,v 1.11 2003/10/02 14:13:32 dillo Exp $
+  $NiH: zip_source_file.c,v 1.1 2004/11/18 15:06:23 wiz Exp $
 
-  zip_replace_file.c -- replace file from file system
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_source_file.c -- create data source from file
+  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -43,30 +43,29 @@
 
 
 
-int
-zip_replace_file(struct zip *zf, int idx,
-		 const char *fname, off_t start, off_t len)
+struct zip_source *
+zip_source_file(struct zip *za, const char *fname, off_t start, off_t len)
 {
-    if (idx < 0 || idx >= zf->nentry) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
-	return -1;
-    }
-
-    return _zip_replace_file(zf, idx, NULL, fname, start, len);
-}
-
-
-
-int
-_zip_replace_file(struct zip *zf, int idx, const char *name,
-		  const char *fname, off_t start, off_t len)
-{
+    struct zip_source *zs;
     FILE *fp;
 
-    if ((fp=fopen(fname, "rb")) == NULL) {
-	_zip_error_set(&zf->error, ZERR_OPEN, errno);
-	return -1;
+    if (za == NULL)
+	return NULL;
+
+    if (fname == NULL || start < 0 || len < -1) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+	return NULL;
     }
 
-    return _zip_replace_filep(zf, idx, name, fp, start, len);
+    if ((fp=fopen(fname, "rb")) == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_OPEN, errno);
+	return NULL;
+    }
+
+    if ((zs=zip_source_filep(za, fp, start, len)) == NULL) {
+	fclose(fp);
+	return NULL;
+    }
+
+    return zs;
 }
diff --git a/lib/zip_source_filep.c b/lib/zip_source_filep.c
new file mode 100644
index 0000000..32d2897
--- /dev/null
+++ b/lib/zip_source_filep.c
@@ -0,0 +1,176 @@
+/*
+  $NiH: zip_source_filep.c,v 1.6 2005/06/09 19:57:10 dillo Exp $
+
+  zip_source_filep.c -- create data source from FILE *
+  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <sys/stat.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zip.h"
+#include "zipint.h"
+
+struct read_file {
+    FILE *f;		/* file to copy from */
+    off_t off;		/* start offset of */
+    off_t len;		/* lengt of data to copy */
+    off_t remain;	/* bytes remaining to be copied */
+    int e[2];		/* error codes */
+};
+
+static ssize_t read_file(void *state, void *data, size_t len,
+		     enum zip_source_cmd cmd);
+
+
+
+struct zip_source *
+zip_source_filep(struct zip *za, FILE *file, off_t start, off_t len)
+{
+    struct read_file *f;
+    struct zip_source *zs;
+
+    if (za == NULL)
+	return NULL;
+
+    if (file == NULL || start < 0 || len < -1) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+	return NULL;
+    }
+
+    if ((f=(struct read_file *)malloc(sizeof(struct read_file))) == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	return NULL;
+    }
+
+    f->f = file;
+    f->off = start;
+    f->len = (len ? len : -1);
+    
+    if ((zs=zip_source_function(za, read_file, f)) == NULL) {
+	free(f);
+	return NULL;
+    }
+
+    return zs;
+}
+
+
+
+static ssize_t
+read_file(void *state, void *data, size_t len, enum zip_source_cmd cmd)
+{
+    struct read_file *z;
+    char *buf;
+    int i, n;
+
+    z = (struct read_file *)state;
+    buf = (char *)data;
+
+    switch (cmd) {
+    case ZIP_SOURCE_OPEN:
+	if (fseeko(z->f, z->off, SEEK_SET) < 0) {
+	    z->e[0] = ZIP_ER_SEEK;
+	    z->e[1] = errno;
+	    return -1;
+	}
+	z->remain = z->len;
+	return 0;
+	
+    case ZIP_SOURCE_READ:
+	if (z->remain != -1)
+	    n = len > z->remain ? z->remain : len;
+	else
+	    n = len;
+	
+	if ((i=fread(buf, 1, n, z->f)) < 0) {
+	    z->e[0] = ZIP_ER_READ;
+	    z->e[1] = errno;
+	    return -1;
+	}
+
+	if (z->remain != -1)
+	    z->remain -= i;
+
+	return i;
+	
+    case ZIP_SOURCE_CLOSE:
+	return 0;
+
+    case ZIP_SOURCE_STAT:
+        {
+	    struct zip_stat *st;
+	    struct stat fst;
+	    
+	    if (len < sizeof(*st))
+		return -1;
+
+	    if (fstat(fileno(z->f), &fst) != 0) {
+		z->e[0] = ZIP_ER_READ; /* best match */
+		z->e[1] = errno;
+		return -1;
+	    }
+
+	    st = (struct zip_stat *)data;
+
+	    zip_stat_init(st);
+	    st->mtime = fst.st_mtime;
+	    if (z->len != -1)
+		st->size = z->len;
+	    else if ((fst.st_mode&S_IFMT) == S_IFREG)
+		st->size = fst.st_size;
+
+	    return sizeof(*st);
+	}
+
+    case ZIP_SOURCE_ERROR:
+	if (len < sizeof(int)*2)
+	    return -1;
+
+	memcpy(data, z->e, sizeof(int)*2);
+	return sizeof(int)*2;
+
+    case ZIP_SOURCE_FREE:
+	fclose(z->f);
+	free(z);
+	return 0;
+
+    default:
+	;
+    }
+
+    return -1;
+}
diff --git a/lib/zip_error_sys_type.c b/lib/zip_source_free.c
similarity index 81%
copy from lib/zip_error_sys_type.c
copy to lib/zip_source_free.c
index 7c1c899..ecc18f6 100644
--- a/lib/zip_error_sys_type.c
+++ b/lib/zip_source_free.c
@@ -1,8 +1,8 @@
 /*
-  $NiH$
+  $NiH: zip_source_free.c,v 1.1 2004/11/18 15:06:24 wiz Exp $
 
-  zip_error_sys_type.c -- return type of system error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_source_free.c -- free zip data source
+  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -35,16 +35,20 @@
 
 
 
+#include <stdlib.h>
+
 #include "zip.h"
 #include "zipint.h"
 
 
 
-int
-zip_error_sys_type(int ze)
+void
+zip_source_free(struct zip_source *source)
 {
-    if (ze < 0 || ze >= _zip_nerr_str)
-	return 0;
+    if (source == NULL)
+	return;
 
-    return _zip_err_type[ze];
+    (void)source->f(source->ud, NULL, 0, ZIP_SOURCE_FREE);
+
+    free(source);
 }
diff --git a/lib/zip_free_entry.c b/lib/zip_source_function.c
similarity index 74%
copy from lib/zip_free_entry.c
copy to lib/zip_source_function.c
index 033061b..d8f9297 100644
--- a/lib/zip_free_entry.c
+++ b/lib/zip_source_function.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_free_entry.c,v 1.9.4.2 2004/03/22 14:17:33 dillo Exp $
+  $NiH: zip_source_function.c,v 1.3 2004/12/22 16:32:00 dillo Exp $
 
-  zip_free_entry.c -- free struct zip_entry
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_source_function.c -- create zip data source from callback function
+  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -42,17 +42,21 @@
 
 
 
-int
-_zip_free_entry(struct zip_entry *ze)
+struct zip_source *
+zip_source_function(struct zip *za, zip_source_callback zcb, void *ud)
 {
-    int ret;
+    struct zip_source *zs;
 
-    ret = 0;
-    
-    free(ze->ch_filename);
-    
-    if (ze->ch_func)
-	ret = ze->ch_func(ze->ch_data, NULL, 0, ZIP_CMD_CLOSE);
+    if (za == NULL)
+	return NULL;
 
-    return ret;
+    if ((zs=(struct zip_source *)malloc(sizeof(*zs))) == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	return NULL;
+    }
+
+    zs->f = zcb;
+    zs->ud = ud;
+    
+    return zs;
 }
diff --git a/lib/zip_replace_zip.c b/lib/zip_source_zip.c
similarity index 61%
rename from lib/zip_replace_zip.c
rename to lib/zip_source_zip.c
index 3f4c4ae..5cfdf3d 100644
--- a/lib/zip_replace_zip.c
+++ b/lib/zip_source_zip.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_replace_zip.c,v 1.17.4.9 2004/04/13 19:47:59 dillo Exp $
+  $NiH: zip_source_zip.c,v 1.6 2005/06/09 19:57:10 dillo Exp $
 
-  zip_replace_zip.c -- replace file from zip file
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_source_zip.c -- create data source from zip file
+  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -36,6 +36,8 @@
 
 
 #include <stdlib.h>
+#include <string.h>
+
 #include "zip.h"
 #include "zipint.h"
 
@@ -45,36 +47,30 @@
     off_t off, len;
 };
 
-static ssize_t read_zip(void *st, void *data, size_t len, enum zip_cmd cmd);
+static ssize_t read_zip(void *st, void *data, size_t len,
+			enum zip_source_cmd cmd);
 
 
 
-int
-zip_replace_zip(struct zip *zf, int idx,
-		struct zip *srczf, int srcidx, int flags,
-		off_t start, off_t len)
-{
-    if (srcidx < 0 || srcidx >= srczf->nentry) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
-	return -1;
-    }
-
-    return _zip_replace_zip(zf, idx, NULL, srczf, srcidx, flags, start, len);
-}
-
-
-
-int
-_zip_replace_zip(struct zip *zf, int idx, const char *name,
-		 struct zip *srczf, int srcidx, int flags,
-		 off_t start, off_t len)
+struct zip_source *
+zip_source_zip(struct zip *za, struct zip *srcza, int srcidx, int flags,
+	       off_t start, off_t len)
 {
     struct zip_error error;
+    struct zip_source *zs;
     struct read_zip *p;
 
+    if (za == NULL)
+	return NULL;
+
+    if (srcza == NULL || start < 0 || len < -1 || srcidx < 0 || srcidx >= srcza->nentry) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+	return NULL;
+    }
+
     if ((flags & ZIP_FL_UNCHANGED) == 0
-	&& ZIP_ENTRY_DATA_CHANGED(srczf->entry+srcidx)) {
-	_zip_error_set(&zf->error, ZERR_CHANGED, 0);
+	&& ZIP_ENTRY_DATA_CHANGED(srcza->entry+srcidx)) {
+	_zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
 	return NULL;
     }
 
@@ -86,20 +82,20 @@
     else
 	flags &= ~ZIP_FL_COMPRESSED;
 
-    if ((p=malloc(sizeof(*p))) == NULL) {
-	_zip_error_set(&zf->error, ZERR_MEMORY, 0);
-	return -1;
+    if ((p=(struct read_zip *)malloc(sizeof(*p))) == NULL) {
+	_zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
+	return NULL;
     }
 	
-    _zip_error_copy(&error, &srczf->error);
+    _zip_error_copy(&error, &srcza->error);
 	
-    if (zip_stat_index(srczf, srcidx, flags, &p->st) < 0
-	|| (p->zf=zip_fopen_index(srczf, srcidx, flags)) == NULL) {
+    if (zip_stat_index(srcza, srcidx, flags, &p->st) < 0
+	|| (p->zf=zip_fopen_index(srcza, srcidx, flags)) == NULL) {
 	free(p);
-	_zip_error_copy(&zf->error, &srczf->error);
-	_zip_error_copy(&srczf->error, &error);
+	_zip_error_copy(&za->error, &srcza->error);
+	_zip_error_copy(&srcza->error, &error);
 	
-	return -1;
+	return NULL;
     }
     p->off = start;
     p->len = len;
@@ -107,16 +103,21 @@
     if ((flags & ZIP_FL_COMPRESSED) == 0) {
 	p->st.size = p->st.comp_size = len;
 	p->st.comp_method = ZIP_CM_STORE;
-	/* XXX: crc */
+	p->st.crc = 0;
     }
     
-    return _zip_replace(zf, idx, name, read_zip, p, 0);
+    if ((zs=zip_source_function(za, read_zip, p)) == NULL) {
+	free(p);
+	return NULL;
+    }
+
+    return zs;
 }
 
 
 
 static ssize_t
-read_zip(void *state, void *data, size_t len, enum zip_cmd cmd)
+read_zip(void *state, void *data, size_t len, enum zip_source_cmd cmd)
 {
     struct read_zip *z;
     char b[8192], *buf;
@@ -126,7 +127,7 @@
     buf = (char *)data;
 
     switch (cmd) {
-    case ZIP_CMD_INIT:
+    case ZIP_SOURCE_OPEN:
 	for (n=0; n<z->off; n+= i) {
 	    i = (z->off-n > sizeof(b) ? sizeof(b) : z->off-n);
 	    if ((i=zip_fread(z->zf, b, i)) < 0) {
@@ -137,33 +138,47 @@
 	}
 	return 0;
 	
-    case ZIP_CMD_READ:
+    case ZIP_SOURCE_READ:
 	if (z->len != -1)
 	    n = len > z->len ? z->len : len;
 	else
 	    n = len;
 	
 
-	if ((i=zip_fread(z->zf, buf, n)) < 0) {
-	    /* XXX: copy error from z->zff */
+	if ((i=zip_fread(z->zf, buf, n)) < 0)
 	    return -1;
-	}
 
 	if (z->len != -1)
 	    z->len -= i;
 
 	return i;
 	
-    case ZIP_CMD_CLOSE:
-	zip_fclose(z->zf);
-	free(z);
+    case ZIP_SOURCE_CLOSE:
 	return 0;
 
-    case ZIP_CMD_STAT:
+    case ZIP_SOURCE_STAT:
 	if (len < sizeof(z->st))
 	    return -1;
+	len = sizeof(z->st);
 
-	memcpy(data, &z->st, sizeof(z->st));
+	memcpy(data, &z->st, len);
+	return len;
+
+    case ZIP_SOURCE_ERROR:
+	{
+	    int *e;
+
+	    if (len < sizeof(int)*2)
+		return -1;
+
+	    e = (int *)data;
+	    zip_file_error_get(z->zf, e, e+1);
+	}
+	return sizeof(int)*2;
+
+    case ZIP_SOURCE_FREE:
+	zip_fclose(z->zf);
+	free(z);
 	return 0;
 
     default:
diff --git a/lib/zip_stat.c b/lib/zip_stat.c
index f6f3ad3..7926f21 100644
--- a/lib/zip_stat.c
+++ b/lib/zip_stat.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_stat.c,v 1.1 2003/10/06 02:50:06 dillo Exp $
+  $NiH: zip_stat.c,v 1.2 2004/04/14 14:01:28 dillo Exp $
 
   zip_stat.c -- get information about file by name
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
diff --git a/lib/zip_stat_index.c b/lib/zip_stat_index.c
index 933a81c..28c2cfb 100644
--- a/lib/zip_stat_index.c
+++ b/lib/zip_stat_index.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_stat_index.c,v 1.1.4.3 2004/04/10 23:15:55 dillo Exp $
+  $NiH: zip_stat_index.c,v 1.10 2006/04/24 14:04:19 dillo Exp $
 
   zip_stat_index.c -- get information about file by index
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -43,26 +43,51 @@
 int
 zip_stat_index(struct zip *za, int index, int flags, struct zip_stat *st)
 {
+    const char *name;
+    
     if (index < 0 || index >= za->nentry) {
-	_zip_error_set(&za->error, ZERR_INVAL, 0);
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
 	return -1;
     }
 
+    if ((name=zip_get_name(za, index, flags)) == NULL)
+	return -1;
+    
+
     if ((flags & ZIP_FL_UNCHANGED) == 0
 	&& ZIP_ENTRY_DATA_CHANGED(za->entry+index)) {
-	/* XXX: call ch_func with ZIP_CMD_STAT */
-	_zip_error_set(&za->error, ZERR_CHANGED, 0);
-	return NULL;
+	if (za->entry[index].source->f(za->entry[index].source->ud,
+				     st, sizeof(*st), ZIP_SOURCE_STAT) < 0) {
+	    _zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
+	    return -1;
+	}
     }
-    
-    st->name = zip_get_name(za, index);
-    st->index = index;
-    st->crc = za->cdir->entry[index].crc;
-    st->size = za->cdir->entry[index].uncomp_size;
-    st->mtime = za->cdir->entry[index].last_mod;
-    st->comp_size = za->cdir->entry[index].comp_size;
-    st->comp_method = za->cdir->entry[index].comp_method;
-    /* st->bitflags = za->cdir->entry[index].bitflags; */
+    else {
+	if (za->cdir == NULL || index >= za->cdir->nentry) {
+	    _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
+	    return -1;
+	}
+	
+	st->crc = za->cdir->entry[index].crc;
+	st->size = za->cdir->entry[index].uncomp_size;
+	st->mtime = za->cdir->entry[index].last_mod;
+	st->comp_size = za->cdir->entry[index].comp_size;
+	st->comp_method = za->cdir->entry[index].comp_method;
+	if (za->cdir->entry[index].bitflags & ZIP_GPBF_ENCRYPTED) {
+	    if (za->cdir->entry[index].bitflags & ZIP_GPBF_STRONG_ENCRYPTION) {
+		/* XXX */
+		st->encryption_method = ZIP_EM_UNKNOWN;
+	    }
+	    else
+		st->encryption_method = ZIP_EM_TRAD_PKWARE;
+	}
+	else
+	    st->encryption_method = ZIP_EM_NONE;
+	/* st->bitflags = za->cdir->entry[index].bitflags; */
+    }
 
+    st->index = index;
+    st->name = name;
+    
     return 0;
 }
diff --git a/lib/zip_error_sys_type.c b/lib/zip_stat_init.c
similarity index 81%
copy from lib/zip_error_sys_type.c
copy to lib/zip_stat_init.c
index 7c1c899..a7d0a1f 100644
--- a/lib/zip_error_sys_type.c
+++ b/lib/zip_stat_init.c
@@ -1,8 +1,8 @@
 /*
   $NiH$
 
-  zip_error_sys_type.c -- return type of system error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_stat_init.c -- initialize struct zip_stat.
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -35,16 +35,19 @@
 
 
 
-#include "zip.h"
 #include "zipint.h"
 
 
 
-int
-zip_error_sys_type(int ze)
+void
+zip_stat_init(struct zip_stat *st)
 {
-    if (ze < 0 || ze >= _zip_nerr_str)
-	return 0;
-
-    return _zip_err_type[ze];
+    st->name = NULL;
+    st->index = -1;
+    st->crc = 0;
+    st->mtime = (time_t)-1;
+    st->size = -1;
+    st->comp_size = -1;
+    st->comp_method = ZIP_CM_STORE;
+    st->encryption_method = ZIP_EM_NONE;
 }
diff --git a/lib/zip_unchange.c b/lib/zip_unchange.c
index 569dc68..16c8877 100644
--- a/lib/zip_unchange.c
+++ b/lib/zip_unchange.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_unchange.c,v 1.11.4.1 2004/03/20 09:54:09 dillo Exp $
+  $NiH: zip_unchange.c,v 1.18 2006/04/09 19:05:47 wiz Exp $
 
   zip_unchange.c -- undo changes to file in zip archive
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2004, 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -42,21 +42,43 @@
 
 
 int
-zip_unchange(struct zip *zf, int idx)
+zip_unchange(struct zip *za, int idx)
 {
-    int ret;
+    return _zip_unchange(za, idx, 0);
+}
+
+
+
+int
+_zip_unchange(struct zip *za, int idx, int allow_duplicates)
+{
+    int i;
     
-    if (!zf || idx < 0 || idx >= zf->nentry) {
-	_zip_error_set(&zf->error, ZERR_INVAL, 0);
+    if (idx < 0 || idx >= za->nentry) {
+	_zip_error_set(&za->error, ZIP_ER_INVAL, 0);
 	return -1;
     }
 
-    if (zf->entry[idx].ch_filename) {
-	free(zf->entry[idx].ch_filename);
-	zf->entry[idx].ch_filename = NULL;
+    if (za->entry[idx].ch_filename) {
+	if (!allow_duplicates) {
+	    i = _zip_name_locate(za,
+			 _zip_get_name(za, idx, ZIP_FL_UNCHANGED, NULL),
+				 0, NULL);
+	    if (i != -1 && i != idx) {
+		_zip_error_set(&za->error, ZIP_ER_EXISTS, 0);
+		return -1;
+	    }
+	}
+
+	free(za->entry[idx].ch_filename);
+	za->entry[idx].ch_filename = NULL;
     }
 
-    ret = _zip_unchange_data(zf->entry+idx);
-        
-    return ret;
+    free(za->entry[idx].ch_comment);
+    za->entry[idx].ch_comment = NULL;
+    za->entry[idx].ch_comment_len = -1;
+
+    _zip_unchange_data(za->entry+idx);
+
+    return 0;
 }
diff --git a/lib/zip_unchange_all.c b/lib/zip_unchange_all.c
index fba406d..1531f6f 100644
--- a/lib/zip_unchange_all.c
+++ b/lib/zip_unchange_all.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_unchange_all.c,v 1.5 2003/10/03 08:34:11 dillo Exp $
+  $NiH: zip_unchange_all.c,v 1.9 2006/04/23 00:40:48 wiz Exp $
 
   zip_unchange.c -- undo changes to all files in zip archive
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -48,7 +48,9 @@
 
     ret = 0;
     for (i=0; i<za->nentry; i++)
-	ret |= zip_unchange(za, i);
-        
+	ret |= _zip_unchange(za, i, 1);
+
+    ret |= zip_unchange_archive(za);
+
     return ret;
 }
diff --git a/lib/zip_error_sys_type.c b/lib/zip_unchange_archive.c
similarity index 82%
copy from lib/zip_error_sys_type.c
copy to lib/zip_unchange_archive.c
index 7c1c899..1737e83 100644
--- a/lib/zip_error_sys_type.c
+++ b/lib/zip_unchange_archive.c
@@ -1,8 +1,8 @@
 /*
-  $NiH$
+  $NiH: zip_unchange_all.c,v 1.9 2006/04/23 00:40:48 wiz Exp $
 
-  zip_error_sys_type.c -- return type of system error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  zip_unchange_archive.c -- undo global changes to ZIP archive
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -35,16 +35,18 @@
 
 
 
+#include <stdlib.h>
 #include "zip.h"
 #include "zipint.h"
 
 
 
 int
-zip_error_sys_type(int ze)
+zip_unchange_archive(struct zip *za)
 {
-    if (ze < 0 || ze >= _zip_nerr_str)
-	return 0;
+    free(za->ch_comment);
+    za->ch_comment = NULL;
+    za->ch_comment_len = -1;
 
-    return _zip_err_type[ze];
+    return 0;
 }
diff --git a/lib/zip_unchange_data.c b/lib/zip_unchange_data.c
index 894b431..f8a3f19 100644
--- a/lib/zip_unchange_data.c
+++ b/lib/zip_unchange_data.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_unchange_data.c,v 1.9.4.1 2004/03/20 09:54:09 dillo Exp $
+  $NiH: zip_unchange_data.c,v 1.14 2004/11/30 23:02:47 wiz Exp $
 
   zip_unchange_data.c -- undo helper function
-  Copyright (C) 1999 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -36,25 +36,18 @@
 
 
 #include <stdlib.h>
-#include "zip.h"
+
 #include "zipint.h"
 
-int
+void
 _zip_unchange_data(struct zip_entry *ze)
 {
-    int ret;
-
-    ret = 0;
-    
-    if (ze->ch_func) {
-	ret = ze->ch_func(ze->ch_data, NULL, 0, ZIP_CMD_CLOSE);
-	ze->ch_func = NULL;
+    if (ze->source) {
+	(void)ze->source->f(ze->source->ud, NULL, 0, ZIP_SOURCE_FREE);
+	free(ze->source);
+	ze->source = NULL;
     }
     
-    ze->ch_flags = 0;
-
     ze->state = ze->ch_filename ? ZIP_ST_RENAMED : ZIP_ST_UNCHANGED;
-
-    return ret;
 }
 
diff --git a/lib/zipint.h b/lib/zipint.h
index 9d6746e..e4b1e2c 100644
--- a/lib/zipint.h
+++ b/lib/zipint.h
@@ -1,12 +1,11 @@
-
 #ifndef _HAD_ZIPINT_H
 #define _HAD_ZIPINT_H
 
 /*
-  $NiH: zipint.h,v 1.22.4.11 2004/04/13 19:48:00 dillo Exp $
+  $NiH: zipint.h,v 1.50 2006/10/04 15:21:09 dillo Exp $
 
   zipint.h -- internal declarations.
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -37,17 +36,35 @@
   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#include <zlib.h>
+
+#include "zip.h"
+#include "config.h"
+
+#ifndef HAVE_MKSTEMP
+int _zip_mkstemp(char *);
+#define mkstemp _zip_mkstemp
+#endif
+
+#ifndef HAVE_FSEEKO
+#define fseeko(s, o, w)	(fseek((s), (long int)(o), (w)))
+#endif
+#ifndef HAVE_FTELLO
+#define ftello(s)	((long)ftell((s)))
+#endif
+
 
 
-#define MAXCOMLEN        65536
-#define EOCDLEN             22
-#define BUFSIZE       (MAXCOMLEN+EOCDLEN)
-#define LOCAL_MAGIC   "PK\3\4"
 #define CENTRAL_MAGIC "PK\1\2"
+#define LOCAL_MAGIC   "PK\3\4"
 #define EOCD_MAGIC    "PK\5\6"
 #define DATADES_MAGIC "PK\7\8"
-#define CDENTRYSIZE         46
+#define CDENTRYSIZE         46u
 #define LENTRYSIZE          30
+#define MAXCOMLEN        65536
+#define EOCDLEN             22
+#define CDBUFSIZE       (MAXCOMLEN+EOCDLEN)
+#define BUFSIZE		8192
 
 
 
@@ -59,12 +76,19 @@
 /* constants for struct zip_file's member flags */
 
 #define ZIP_ZF_EOF	1 /* EOF reached */
-#define ZIP_ZF_COMP	2 /* read compressed data */
+#define ZIP_ZF_DECOMP	2 /* decompress data */
+#define ZIP_ZF_CRC	4 /* compute and compare CRC */
+
+/* directory entry: general purpose bit flags */
+
+#define ZIP_GPBF_ENCRYPTED		0x0001	/* is encrypted */
+#define ZIP_GPBF_DATA_DESCRIPTOR	0x0008	/* crc/size after file data */
+#define ZIP_GPBF_STRONG_ENCRYPTION	0x0040  /* uses strong encryption */
 
 /* error information */
 
 struct zip_error {
-    int zip_err;	/* libzip error code (ZERR_*) */
+    int zip_err;	/* libzip error code (ZIP_ER_*) */
     int sys_err;	/* copy of errno (E*) or zlib error code */
     char *str;		/* string representation or NULL */
 };
@@ -77,27 +101,30 @@
     struct zip_error error;	/* error information */
 
     struct zip_cdir *cdir;	/* central directory */
+    char *ch_comment;		/* changed archive comment */
+    int ch_comment_len;		/* length of changed zip archive
+				 * comment, -1 if unchanged */
     int nentry;			/* number of entries */
     int nentry_alloc;		/* number of entries allocated */
     struct zip_entry *entry;	/* entries */
-    int nfile;			/* number of opened files within archvie */
+    int nfile;			/* number of opened files within archive */
     int nfile_alloc;		/* number of files allocated */
-    struct zip_file **file;	/* opened files within archvie */
+    struct zip_file **file;	/* opened files within archive */
 };
 
 /* file in zip archive, part of API */
 
 struct zip_file {
-    struct zip *zf;		/* zip archive containing this file */
+    struct zip *za;		/* zip archive containing this file */
     struct zip_error error;	/* error information */
     int flags;			/* -1: eof, >0: error */
 
     int method;			/* compression method */
-    long fpos;			/* position within zip file (fread/fwrite) */
+    off_t fpos;			/* position within zip file (fread/fwrite) */
     unsigned long bytes_left;	/* number of bytes left to read */
     unsigned long cbytes_left;  /* number of bytes of compressed data left */
     
-    unsigned long crc;		/* crc so far */
+    unsigned long crc;		/* CRC so far */
     unsigned long crc_orig;	/* CRC recorded in archive */
     
     char *buffer;
@@ -109,7 +136,7 @@
 struct zip_dirent {
     unsigned short version_madeby;	/* (c)  version of creator */
     unsigned short version_needed;	/* (cl) version needed to extract */
-    unsigned short bitflags;		/* (cl) general purposee bit flag */
+    unsigned short bitflags;		/* (cl) general purpose bit flag */
     unsigned short comp_method;		/* (cl) compression method used */
     time_t last_mod;			/* (cl) time of last modification */
     unsigned int crc;			/* (cl) CRC-32 of uncompressed data */
@@ -124,7 +151,7 @@
     unsigned short disk_number;		/* (c)  disk number start */
     unsigned short int_attrib;		/* (c)  internal file attributes */
     unsigned int ext_attrib;		/* (c)  external file attributes */
-    unsigned int offset;		/* (c)  offest of local header  */
+    unsigned int offset;		/* (c)  offset of local header  */
 };
 
 /* zip archive central directory */
@@ -139,15 +166,21 @@
     unsigned short comment_len;	/* length of zip archive comment */
 };
 
+
+
+struct zip_source {
+    zip_source_callback f;
+    void *ud;
+};
+
 /* entry in zip archive directory */
 
 struct zip_entry {
     enum zip_state state;
-    zip_read_func ch_func;
-    void *ch_data;
-    int ch_flags;		/* 1: data returned by ch_func is compressed */
+    struct zip_source *source;
     char *ch_filename;
-    time_t ch_mtime;
+    char *ch_comment;
+    int ch_comment_len;
 };
 
 
@@ -167,39 +200,39 @@
 void _zip_cdir_free(struct zip_cdir *);
 struct zip_cdir *_zip_cdir_new(int, struct zip_error *);
 int _zip_cdir_write(struct zip_cdir *, FILE *, struct zip_error *);
+
 void _zip_dirent_finalize(struct zip_dirent *);
 void _zip_dirent_init(struct zip_dirent *);
 int _zip_dirent_read(struct zip_dirent *, FILE *,
-		     unsigned char **, int, int, struct zip_error *);
+		     unsigned char **, unsigned int, int, struct zip_error *);
 int _zip_dirent_write(struct zip_dirent *, FILE *, int, struct zip_error *);
+
+void _zip_entry_free(struct zip_entry *);
 void _zip_entry_init(struct zip *, int);
+struct zip_entry *_zip_entry_new(struct zip *);
+
+void _zip_error_clear(struct zip_error *);
 void _zip_error_copy(struct zip_error *, struct zip_error *);
 void _zip_error_fini(struct zip_error *);
 void _zip_error_get(struct zip_error *, int *, int *);
 void _zip_error_init(struct zip_error *);
 void _zip_error_set(struct zip_error *, int, int);
 const char *_zip_error_strerror(struct zip_error *);
+
 int _zip_file_fillbuf(void *, size_t, struct zip_file *);
 unsigned int _zip_file_get_offset(struct zip *, int);
+
 void _zip_free(struct zip *);
-int _zip_free_entry(struct zip_entry *);
+const char *_zip_get_name(struct zip *, int, int, struct zip_error *);
 int _zip_local_header_read(struct zip *, int);
-void *_zip_memdup(const void *, int);
+void *_zip_memdup(const void *, size_t, struct zip_error *);
+int _zip_name_locate(struct zip *, const char *, int, struct zip_error *);
 struct zip *_zip_new(struct zip_error *);
-struct zip_entry *_zip_new_entry(struct zip *);
 unsigned short _zip_read2(unsigned char **);
 unsigned int _zip_read4(unsigned char **);
-int _zip_replace(struct zip *, int, const char *,zip_read_func, void *, int);
-int _zip_replace_data(struct zip *, int, const char *,
-		      const void *, off_t, int);
-int _zip_replace_file(struct zip *, int, const char *,
-		      const char *, off_t, off_t);
-int _zip_replace_filep(struct zip *, int, const char *, FILE *, off_t, off_t);
-int _zip_replace_zip(struct zip *, int, const char *,
-		     struct zip *, int, int, off_t, off_t);
+int _zip_replace(struct zip *, int, const char *, struct zip_source *);
 int _zip_set_name(struct zip *, int, const char *);
-int _zip_unchange(struct zip_entry *);
-int _zip_unchange_data(struct zip_entry *);
+int _zip_unchange(struct zip *, int, int);
+void _zip_unchange_data(struct zip_entry *);
 
 #endif /* zipint.h */
-
diff --git a/libzip.pc.in b/libzip.pc.in
index f810573..ad1e565 100644
--- a/libzip.pc.in
+++ b/libzip.pc.in
@@ -3,10 +3,10 @@
 libdir=@libdir@
 includedir=@includedir@
 
-zipcmp=zipcmp
+zipcmp=@prefix@/bin/zipcmp
 
 Name: libzip
-Description: library for handling zip archvies
+Description: library for handling zip archives
 Version: @VERSION@
 Libs: -L${libdir} -lzip @LIBS@
 Cflags: -I${includedir}
diff --git a/ltcf-c.sh b/ltcf-c.sh
deleted file mode 100644
index 952c6a1..0000000
--- a/ltcf-c.sh
+++ /dev/null
@@ -1,805 +0,0 @@
-#### This script is meant to be sourced by ltconfig.
-
-# ltcf-c.sh - Create a C compiler specific configuration
-#
-# Copyright (C) 1996-2000, 2001 Free Software Foundation, Inc.
-# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
-#
-# This file is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-
-# Source file extension for C test sources.
-ac_ext=c
-
-# Object file extension for compiled C test sources.
-objext=o
-
-# Code to be used in simple compile tests
-lt_simple_compile_test_code="int some_variable = 0;"
-
-# Code to be used in simple link tests
-lt_simple_link_test_code='main(){return(0);}'
-
-## Linker Characteristics
-case $host_os in
-cygwin* | mingw*)
-  # FIXME: the MSVC++ port hasn't been tested in a loooong time
-  # When not using gcc, we currently assume that we are using
-  # Microsoft Visual C++.
-  if test "$with_gcc" != yes; then
-    with_gnu_ld=no
-  fi
-  ;;
-
-esac
-
-ld_shlibs=yes
-if test "$with_gnu_ld" = yes; then
-  # If archive_cmds runs LD, not CC, wlarc should be empty
-  wlarc='${wl}'
-
-  # See if GNU ld supports shared libraries.
-  case $host_os in
-  aix3* | aix4* | aix5*)
-    # On AIX, the GNU linker is very broken
-    ld_shlibs=no
-    cat <<EOF 1>&2
-
-*** Warning: the GNU linker, at least up to release 2.9.1, is reported
-*** to be unable to reliably create shared libraries on AIX.
-*** Therefore, libtool is disabling shared libraries support.  If you
-*** really care for shared libraries, you may want to modify your PATH
-*** so that a non-GNU linker is found, and then restart.
-
-EOF
-    ;;
-
-  amigaos*)
-    archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
-    hardcode_libdir_flag_spec='-L$libdir'
-    hardcode_minus_L=yes
-
-    # Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports
-    # that the semantics of dynamic libraries on AmigaOS, at least up
-    # to version 4, is to share data among multiple programs linked
-    # with the same dynamic library.  Since this doesn't match the
-    # behavior of shared libraries on other platforms, we can use
-    # them.
-    ld_shlibs=no
-    ;;
-
-  beos*)
-    if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
-      allow_undefined_flag=unsupported
-      # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
-      # support --undefined.  This deserves some investigation.  FIXME
-      archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-    else
-      ld_shlibs=no
-    fi
-    ;;
-
-  cygwin* | mingw*)
-    # hardcode_libdir_flag_spec is actually meaningless, as there is
-    # no search path for DLLs.
-    hardcode_libdir_flag_spec='-L$libdir'
-    allow_undefined_flag=unsupported
-    always_export_symbols=yes
-
-    extract_expsyms_cmds='test -f $output_objdir/impgen.c || \
-      sed -e "/^# \/\* impgen\.c starts here \*\//,/^# \/\* impgen.c ends here \*\// { s/^# //; p; }" -e d < $0 > $output_objdir/impgen.c~
-      test -f $output_objdir/impgen.exe || (cd $output_objdir && \
-      if test "x$HOST_CC" != "x" ; then $HOST_CC -o impgen impgen.c ; \
-      else $CC -o impgen impgen.c ; fi)~
-      $output_objdir/impgen $dir/$soroot > $output_objdir/$soname-def'
-
-    old_archive_from_expsyms_cmds='$DLLTOOL --as=$AS --dllname $soname --def $output_objdir/$soname-def --output-lib $output_objdir/$newlib'
-
-    # cygwin and mingw dlls have different entry points and sets of symbols
-    # to exclude.
-    # FIXME: what about values for MSVC?
-    dll_entry=__cygwin_dll_entry@12
-    dll_exclude_symbols=DllMain@12,_cygwin_dll_entry@12,_cygwin_noncygwin_dll_entry@12~
-    case $host_os in
-    mingw*)
-      # mingw values
-      dll_entry=_DllMainCRTStartup@12
-      dll_exclude_symbols=DllMain@12,DllMainCRTStartup@12,DllEntryPoint@12~
-      ;;
-    esac
-
-    # mingw and cygwin differ, and it's simplest to just exclude the union
-    # of the two symbol sets.
-    dll_exclude_symbols=DllMain@12,_cygwin_dll_entry@12,_cygwin_noncygwin_dll_entry@12,DllMainCRTStartup@12,DllEntryPoint@12
-
-    # recent cygwin and mingw systems supply a stub DllMain which the user
-    # can override, but on older systems we have to supply one (in ltdll.c)
-    if test "x$lt_cv_need_dllmain" = "xyes"; then
-      ltdll_obj='$output_objdir/$soname-ltdll.'"$objext "
-      ltdll_cmds='test -f $output_objdir/$soname-ltdll.c || sed -e "/^# \/\* ltdll\.c starts here \*\//,/^# \/\* ltdll.c ends here \*\// { s/^# //; p; }" -e d < $0 > $output_objdir/$soname-ltdll.c~
-	test -f $output_objdir/$soname-ltdll.$objext || (cd $output_objdir && $CC -c $soname-ltdll.c)~'
-    else
-      ltdll_obj=
-      ltdll_cmds=
-    fi
-
-    # Extract the symbol export list from an `--export-all' def file,
-    # then regenerate the def file from the symbol export list, so that
-    # the compiled dll only exports the symbol export list.
-    # Be careful not to strip the DATA tag left be newer dlltools.
-    export_symbols_cmds="$ltdll_cmds"'
-      $DLLTOOL --export-all --exclude-symbols '$dll_exclude_symbols' --output-def $output_objdir/$soname-def '$ltdll_obj'$libobjs $convenience~
-      sed -e "1,/EXPORTS/d" -e "s/ @ [0-9]*//" -e "s/ *;.*$//" < $output_objdir/$soname-def > $export_symbols'
-
-    # If the export-symbols file already is a .def file (1st line
-    # is EXPORTS), use it as is.
-    # If DATA tags from a recent dlltool are present, honour them!
-    archive_expsym_cmds='if test "x`head -1 $export_symbols`" = xEXPORTS; then
-        cp $export_symbols $output_objdir/$soname-def;
-      else
-        echo EXPORTS > $output_objdir/$soname-def;
-        _lt_hint=1;
-        cat $export_symbols | while read symbol; do
-         set dummy \$symbol;
-         case \[$]# in
-           2) echo "   \[$]2 @ \$_lt_hint ; " >> $output_objdir/$soname-def;;
-           *) echo "     \[$]2 @ \$_lt_hint \[$]3 ; " >> $output_objdir/$soname-def;;
-         esac;
-         _lt_hint=`expr 1 + \$_lt_hint`;
-        done;
-      fi~
-      '"$ltdll_cmds"'
-      $CC -Wl,--base-file,$output_objdir/$soname-base '$lt_cv_cc_dll_switch' -Wl,-e,'$dll_entry' -o $output_objdir/$soname '$ltdll_obj'$libobjs $deplibs $compiler_flags~
-      $DLLTOOL --as=$AS --dllname $soname --exclude-symbols '$dll_exclude_symbols' --def $output_objdir/$soname-def --base-file $output_objdir/$soname-base --output-exp $output_objdir/$soname-exp~
-      $CC -Wl,--base-file,$output_objdir/$soname-base $output_objdir/$soname-exp '$lt_cv_cc_dll_switch' -Wl,-e,'$dll_entry' -o $output_objdir/$soname '$ltdll_obj'$libobjs $deplibs $compiler_flags~
-      $DLLTOOL --as=$AS --dllname $soname --exclude-symbols '$dll_exclude_symbols' --def $output_objdir/$soname-def --base-file $output_objdir/$soname-base --output-exp $output_objdir/$soname-exp --output-lib $output_objdir/$libname.dll.a~
-      $CC $output_objdir/$soname-exp '$lt_cv_cc_dll_switch' -Wl,-e,'$dll_entry' -o $output_objdir/$soname '$ltdll_obj'$libobjs $deplibs $compiler_flags'
-    ;;
-
-  netbsd*)
-    if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
-      archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
-      wlarc=
-    else
-      archive_cmds='$CC -shared -nodefaultlibs $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-      archive_expsym_cmds='$CC -shared -nodefaultlibs $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-    fi
-    ;;
-
-  solaris* | sysv5*)
-    if $LD -v 2>&1 | egrep 'BFD 2\.8' > /dev/null; then
-      ld_shlibs=no
-      cat <<EOF 1>&2
-
-*** Warning: The releases 2.8.* of the GNU linker cannot reliably
-*** create shared libraries on Solaris systems.  Therefore, libtool
-*** is disabling shared libraries support.  We urge you to upgrade GNU
-*** binutils to release 2.9.1 or newer.  Another option is to modify
-*** your PATH or compiler configuration so that the native linker is
-*** used, and then restart.
-
-EOF
-    elif $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
-      archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-      archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-    else
-      ld_shlibs=no
-    fi
-    ;;
-
-  sunos4*)
-    archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
-    wlarc=
-    hardcode_direct=yes
-    hardcode_shlibpath_var=no
-    ;;
-
-  *)
-    if $LD --help 2>&1 | egrep ': supported targets:.* elf' > /dev/null; then
-      archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
-      archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
-    else
-      ld_shlibs=no
-    fi
-    ;;
-  esac
-
-  if test "$ld_shlibs" = yes; then
-    runpath_var=LD_RUN_PATH
-    hardcode_libdir_flag_spec='${wl}--rpath ${wl}$libdir'
-    export_dynamic_flag_spec='${wl}--export-dynamic'
-    case $host_os in
-    cygwin* | mingw*)
-      # dlltool doesn't understand --whole-archive et. al.
-      whole_archive_flag_spec=
-      ;;
-    *)
-      # ancient GNU ld didn't support --whole-archive et. al.
-      if $LD --help 2>&1 | egrep 'no-whole-archive' > /dev/null; then
-	whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
-      else
-	whole_archive_flag_spec=
-      fi
-      ;;
-    esac
-  fi
-else
-  # PORTME fill in a description of your system's linker (not GNU ld)
-  case $host_os in
-  aix3*)
-    allow_undefined_flag=unsupported
-    always_export_symbols=yes
-    archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
-    # Note: this linker hardcodes the directories in LIBPATH if there
-    # are no directories specified by -L.
-    hardcode_minus_L=yes
-    if test "$with_gcc" = yes && test -z "$link_static_flag"; then
-      # Neither direct hardcoding nor static linking is supported with a
-      # broken collect2.
-      hardcode_direct=unsupported
-    fi
-    ;;
-
-  aix4* | aix5*)
-    hardcode_direct=yes
-    hardcode_libdir_separator=':'
-    link_all_deplibs=yes
-    # When large executables or shared objects are built, AIX ld can
-    # have problems creating the table of contents.  If linking a library
-    # or program results in "error TOC overflow" add -mminimal-toc to
-    # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
-    # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
-    if test "$with_gcc" = yes; then
-      case $host_os in aix4.[012]|aix4.[012].*)
-      # We only want to do this on AIX 4.2 and lower, the check
-      # below for broken collect2 doesn't work under 4.3+
-        collect2name=`${CC} -print-prog-name=collect2`
-        if test -f "$collect2name" && \
-	   strings "$collect2name" | grep resolve_lib_name >/dev/null
-        then
-	  # We have reworked collect2
-	  hardcode_direct=yes
-        else
-	  # We have old collect2
-	  hardcode_direct=unsupported
-	  # It fails to find uninstalled libraries when the uninstalled
-	  # path is not listed in the libpath.  Setting hardcode_minus_L
-	  # to unsupported forces relinking
-	  hardcode_minus_L=yes
-	  hardcode_libdir_flag_spec='-L$libdir'
-	  hardcode_libdir_separator=
-        fi
-      esac
-      shared_flag='-shared'
-    else
-      # not using gcc
-      if test "$host_cpu" = ia64; then
-        shared_flag='${wl}-G'
-      else
-        shared_flag='${wl}-bM:SRE'
-      fi
-    fi
-
-    if test "$host_cpu" = ia64; then
-      # On IA64, the linker does run time linking by default, so we don't
-      # have to do anything special.
-      aix_use_runtimelinking=no
-      exp_sym_flag='-Bexport'
-      no_entry_flag=""
-    else
-      # Test if we are trying to use run time linking, or normal AIX style linking.
-      # If -brtl is somewhere in LDFLAGS, we need to do run time linking.
-      aix_use_runtimelinking=no
-      for ld_flag in $LDFLAGS; do
-        if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl" ); then
-          aix_use_runtimelinking=yes
-          break
-        fi
-      done
-      exp_sym_flag='-bexport'
-      no_entry_flag='-bnoentry'
-    fi
-    # -bexpall does not export symbols beginning with underscore (_)
-    always_export_symbols=yes
-    if test "$aix_use_runtimelinking" = yes; then
-      # Warning - without using the other run time loading flags (-brtl), -berok will
-      #           link without error, but may produce a broken library.
-      allow_undefined_flag=' ${wl}-berok'
-      hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:/usr/lib:/lib'
-      archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols"
-    else
-      if test "$host_cpu" = ia64; then
-        hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib'
-        allow_undefined_flag="-z nodefs"
-        archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$no_entry_flag \${wl}$exp_sym_flag:\$export_symbols"
-      else
-        allow_undefined_flag=' ${wl}-berok'
-        # -bexpall does not export symbols beginning with underscore (_)
-        always_export_symbols=yes
-        # Exported symbols can be pulled into shared objects from archives
-        whole_archive_flag_spec=' '
-        build_libtool_need_lc=yes
-        hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:/usr/lib:/lib'
-        # This is similar to how AIX traditionally builds it's shared libraries.
-        archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs $compiler_flags ${wl}-bE:$export_symbols ${wl}-bnoentry${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
-      fi
-    fi
-    ;;
-
-  amigaos*)
-    archive_cmds='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
-    hardcode_libdir_flag_spec='-L$libdir'
-    hardcode_minus_L=yes
-    # see comment about different semantics on the GNU ld section
-    ld_shlibs=no
-    ;;
-
-  cygwin* | mingw*)
-    # When not using gcc, we currently assume that we are using
-    # Microsoft Visual C++.
-    # hardcode_libdir_flag_spec is actually meaningless, as there is
-    # no search path for DLLs.
-    hardcode_libdir_flag_spec=' '
-    allow_undefined_flag=unsupported
-    # Tell ltmain to make .lib files, not .a files.
-    libext=lib
-    # FIXME: Setting linknames here is a bad hack.
-    archive_cmds='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | sed -e '\''s/ -lc$//'\''` -link -dll~linknames='
-    # The linker will automatically build a .lib file if we build a DLL.
-    old_archive_from_new_cmds='true'
-    # FIXME: Should let the user specify the lib program.
-    old_archive_cmds='lib /OUT:$oldlib$oldobjs$old_deplibs'
-    fix_srcfile_path='`cygpath -w "$srcfile"`'
-    ;;
-
-  darwin* | rhapsody*)
-    case "$host_os" in
-    rhapsody* | darwin1.[012])
-      allow_undefined_flag='-undefined suppress'
-      ;;
-    *) # Darwin 1.3 on
-      allow_undefined_flag='-flat_namespace -undefined suppress'
-      ;;
-    esac
-    archive_cmds='$CC $(if test .$module = .yes; then echo -bundle; else echo -dynamiclib; fi) $allow_undefined_flag -o $lib $libobjs $deplibs $linkopts -install_name $rpath/$soname $verstring'
-    # We need to add '_' to the symbols in $export_symbols first
-    #archive_expsym_cmds="$archive_cmds"' && strip -s $export_symbols $lib'
-    hardcode_direct=yes
-    hardcode_shlibpath_var=no
-    whole_archive_flag_spec='-all_load $convenience'
-    ;;
-
-  freebsd1*)
-    ld_shlibs=no
-    ;;
-
-  # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
-  # support.  Future versions do this automatically, but an explicit c++rt0.o
-  # does not break anything, and helps significantly (at the cost of a little
-  # extra space).
-  freebsd2.2*)
-    archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
-    hardcode_libdir_flag_spec='-R$libdir'
-    hardcode_direct=yes
-    hardcode_shlibpath_var=no
-    ;;
-
-  # Unfortunately, older versions of FreeBSD 2 do not have this feature.
-  freebsd2*)
-    archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
-    hardcode_direct=yes
-    hardcode_minus_L=yes
-    hardcode_shlibpath_var=no
-    ;;
-
-  # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
-  freebsd*)
-    archive_cmds='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
-    hardcode_libdir_flag_spec='-R$libdir'
-    hardcode_direct=yes
-    hardcode_shlibpath_var=no
-    ;;
-
-  hpux9* | hpux10* | hpux11*)
-    case $host_os in
-    hpux9*) archive_cmds='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' ;;
-    *) archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' ;;
-    esac
-    hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir'
-    hardcode_libdir_separator=:
-    hardcode_direct=yes
-    hardcode_minus_L=yes # Not in the search PATH, but as the default
-			 # location of the library.
-    export_dynamic_flag_spec='${wl}-E'
-    ;;
-
-  irix5* | irix6*)
-    if test "$with_gcc" = yes; then
-      archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${objdir}/so_locations -o $lib'
-    else
-      archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib'
-    fi
-    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-    hardcode_libdir_separator=:
-    link_all_deplibs=yes
-    ;;
-
-  netbsd*)
-    if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
-      archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
-    else
-      archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
-    fi
-    hardcode_libdir_flag_spec='-R$libdir'
-    hardcode_direct=yes
-    hardcode_shlibpath_var=no
-    ;;
-
-  newsos6)
-    archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linkopts'
-    hardcode_direct=yes
-    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-    hardcode_libdir_separator=:
-    hardcode_shlibpath_var=no
-    ;;
-
-  openbsd*)
-    archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
-    hardcode_libdir_flag_spec='-R$libdir'
-    hardcode_direct=yes
-    hardcode_shlibpath_var=no
-    ;;
-
-  os2*)
-    hardcode_libdir_flag_spec='-L$libdir'
-    hardcode_minus_L=yes
-    allow_undefined_flag=unsupported
-    archive_cmds='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
-    old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
-    ;;
-
-  osf3*)
-    if test "$with_gcc" = yes; then
-      allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
-      archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${objdir}/so_locations -o $lib'
-    else
-      allow_undefined_flag=' -expect_unresolved \*'
-      archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib'
-    fi
-    hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-    hardcode_libdir_separator=:
-    ;;
-
-  osf4* | osf5*)	# as osf3* with the addition of -msym flag
-    if test "$with_gcc" = yes; then
-      allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*'
-      archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${objdir}/so_locations -o $lib'
-      hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir'
-    else
-      allow_undefined_flag=' -expect_unresolved \*'
-      archive_cmds='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib'
-      archive_expsym_cmds='for i in `cat $export_symbols`; do printf "-exported_symbol " >> $lib.exp; echo "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~
-      $LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${objdir}/so_locations -o $lib~$rm $lib.exp'
-
-      # cc supports -rpath directly
-      hardcode_libdir_flag_spec='-rpath $libdir'
-    fi
-    hardcode_libdir_separator=:
-    ;;
-
-  sco3.2v5*)
-    archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-    hardcode_shlibpath_var=no
-    runpath_var=LD_RUN_PATH
-    hardcode_runpath_var=yes
-    ;;
-
-  solaris*)
-    no_undefined_flag=' -z defs'
-    # $CC -shared without GNU ld will not create a library from C++
-    # object files and a static libstdc++, better avoid it by now
-    archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
-    archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
-		$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
-    hardcode_libdir_flag_spec='-R$libdir'
-    hardcode_shlibpath_var=no
-    case $host_os in
-    solaris2.[0-5] | solaris2.[0-5].*) ;;
-    *) # Supported since Solaris 2.6 (maybe 2.5.1?)
-      whole_archive_flag_spec='-z allextract$convenience -z defaultextract' ;;
-    esac
-    link_all_deplibs=yes
-    ;;
-
-  sunos4*)
-    archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
-    hardcode_libdir_flag_spec='-L$libdir'
-    hardcode_direct=yes
-    hardcode_minus_L=yes
-    hardcode_shlibpath_var=no
-    ;;
-
-  sysv4)
-    archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-    runpath_var='LD_RUN_PATH'
-    hardcode_shlibpath_var=no
-    hardcode_direct=no #Motorola manual says yes, but my tests say they lie
-    ;;
-
-  sysv4.3*)
-    archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-    hardcode_shlibpath_var=no
-    export_dynamic_flag_spec='-Bexport'
-    ;;
-
-  sysv5*)
-    no_undefined_flag=' -z text'
-    # $CC -shared without GNU ld will not create a library from C++
-    # object files and a static libstdc++, better avoid it by now
-    archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
-    archive_expsym_cmds='$echo "{ global:" > $lib.exp~cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
-		$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
-    hardcode_libdir_flag_spec=
-    hardcode_shlibpath_var=no
-    runpath_var='LD_RUN_PATH'
-    ;;
-
-  uts4*)
-    archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-    hardcode_libdir_flag_spec='-L$libdir'
-    hardcode_shlibpath_var=no
-    ;;
-
-  dgux*)
-    archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-    hardcode_libdir_flag_spec='-L$libdir'
-    hardcode_shlibpath_var=no
-    ;;
-
-  sysv4*MP*)
-    if test -d /usr/nec; then
-      archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
-      hardcode_shlibpath_var=no
-      runpath_var=LD_RUN_PATH
-      hardcode_runpath_var=yes
-      ld_shlibs=yes
-    fi
-    ;;
-
-  sysv4.2uw2*)
-    archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags'
-    hardcode_direct=yes
-    hardcode_minus_L=no
-    hardcode_shlibpath_var=no
-    hardcode_runpath_var=yes
-    runpath_var=LD_RUN_PATH
-    ;;
-
-  sysv5uw7* | unixware7*)
-    no_undefined_flag='${wl}-z ${wl}text'
-    if test "$GCC" = yes; then
-      archive_cmds='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
-    else
-      archive_cmds='$CC -G ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
-    fi
-    runpath_var='LD_RUN_PATH'
-    hardcode_shlibpath_var=no
-    ;;
-
-  *)
-    ld_shlibs=no
-    ;;
-  esac
-fi
-
-## Compiler Characteristics: PIC flags, static flags, etc
-if test "X${ac_cv_prog_cc_pic+set}" = Xset; then
-  :
-else
-  ac_cv_prog_cc_pic=
-  ac_cv_prog_cc_shlib=
-  ac_cv_prog_cc_wl=
-  ac_cv_prog_cc_static=
-  ac_cv_prog_cc_no_builtin=
-  ac_cv_prog_cc_can_build_shared=$can_build_shared
-
-  if test "$with_gcc" = yes; then
-    ac_cv_prog_cc_wl='-Wl,'
-    ac_cv_prog_cc_static='-static'
-
-    case $host_os in
-    aix*)
-      # All AIX code is PIC.
-      if test "$host_cpu" = ia64; then
-        # AIX 5 now supports IA64 processor
-        lt_cv_prog_cc_static='-Bstatic'
-      else
-        lt_cv_prog_cc_static='-bnso -bI:/lib/syscalls.exp'
-      fi
-      ;;
-    amigaos*)
-      # FIXME: we need at least 68020 code to build shared libraries, but
-      # adding the `-m68020' flag to GCC prevents building anything better,
-      # like `-m68040'.
-      ac_cv_prog_cc_pic='-m68020 -resident32 -malways-restore-a4'
-      ;;
-    beos* | irix5* | irix6* | osf3* | osf4* | osf5*)
-      # PIC is the default for these OSes.
-      ;;
-    cygwin* | mingw* | os2*)
-      # This hack is so that the source file can tell whether it is being
-      # built for inclusion in a dll (and should export symbols for example).
-      ac_cv_prog_cc_pic='-DDLL_EXPORT'
-      ;;
-    darwin* | rhapsody*)
-      # PIC is the default on this platform
-      # Common symbols not allowed in MH_DYLIB files
-      ac_cv_prog_cc_pic='-fno-common'
-      ;;
-    *djgpp*)
-      # DJGPP does not support shared libraries at all
-      ac_cv_prog_cc_pic=
-      ;;
-    sysv4*MP*)
-      if test -d /usr/nec; then
-	 ac_cv_prog_cc_pic=-Kconform_pic
-      fi
-      ;;
-    *)
-      ac_cv_prog_cc_pic='-fPIC'
-      ;;
-    esac
-  else
-    # PORTME Check for PIC flags for the system compiler.
-    case $host_os in
-    aix*)
-     # All AIX code is PIC.
-      ac_cv_prog_cc_static="$ac_cv_prog_cc_static ${ac_cv_prog_cc_wl}-lC"
-      ;;
-
-    hpux9* | hpux10* | hpux11*)
-      # Is there a better ac_cv_prog_cc_static that works with the bundled CC?
-      ac_cv_prog_cc_wl='-Wl,'
-      ac_cv_prog_cc_static="${ac_cv_prog_cc_wl}-a ${ac_cv_prog_cc_wl}archive"
-      ac_cv_prog_cc_pic='+Z'
-      ;;
-
-    irix5* | irix6*)
-      ac_cv_prog_cc_wl='-Wl,'
-      ac_cv_prog_cc_static='-non_shared'
-      # PIC (with -KPIC) is the default.
-      ;;
-
-    cygwin* | mingw* | os2*)
-      # This hack is so that the source file can tell whether it is being
-      # built for inclusion in a dll (and should export symbols for example).
-      ac_cv_prog_cc_pic='-DDLL_EXPORT'
-      ;;
-
-    newsos6)
-      ac_cv_prog_cc_pic='-KPIC'
-      ac_cv_prog_cc_static='-Bstatic'
-      ;;
-
-    osf3* | osf4* | osf5*)
-      # All OSF/1 code is PIC.
-      ac_cv_prog_cc_wl='-Wl,'
-      ac_cv_prog_cc_static='-non_shared'
-      ;;
-
-    sco3.2v5*)
-      ac_cv_prog_cc_pic='-Kpic'
-      ac_cv_prog_cc_static='-dn'
-      ac_cv_prog_cc_shlib='-belf'
-      ;;
-
-    solaris*)
-      ac_cv_prog_cc_pic='-KPIC'
-      ac_cv_prog_cc_static='-Bstatic'
-      ac_cv_prog_cc_wl='-Wl,'
-      ;;
-
-    sunos4*)
-      ac_cv_prog_cc_pic='-PIC'
-      ac_cv_prog_cc_static='-Bstatic'
-      ac_cv_prog_cc_wl='-Qoption ld '
-      ;;
-
-    sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
-      ac_cv_prog_cc_pic='-KPIC'
-      ac_cv_prog_cc_static='-Bstatic'
-      ac_cv_prog_cc_wl='-Wl,'
-      ;;
-
-    uts4*)
-      ac_cv_prog_cc_pic='-pic'
-      ac_cv_prog_cc_static='-Bstatic'
-      ;;
-
-    sysv4*MP*)
-      if test -d /usr/nec ;then
-	ac_cv_prog_cc_pic='-Kconform_pic'
-	ac_cv_prog_cc_static='-Bstatic'
-      fi
-      ;;
-
-    *)
-      ac_cv_prog_cc_can_build_shared=no
-      ;;
-    esac
-  fi
-  case "$host_os" in
-      # Platforms which do not suport PIC and -DPIC is meaningless
-      # on them:
-      *djgpp*)
-        ac_cv_prog_cc_pic=
-        ;;
-      *)
-        ac_cv_prog_cc_pic="$ac_cv_prog_cc_pic -DPIC"
-        ;;
-  esac
-fi
-
-need_lc=yes
-if test "$enable_shared" = yes && test "$with_gcc" = yes; then
-  case $archive_cmds in
-  *'~'*)
-    # FIXME: we may have to deal with multi-command sequences.
-    ;;
-  '$CC '*)
-    # Test whether the compiler implicitly links with -lc since on some
-    # systems, -lgcc has to come before -lc. If gcc already passes -lc
-    # to ld, don't add -lc before -lgcc.
-    echo $ac_n "checking whether -lc should be explicitly linked in... $ac_c" 1>&6
-    if eval "test \"`echo '$''{'ac_cv_archive_cmds_needs_lc'+set}'`\" = set"; then
-      echo $ac_n "(cached) $ac_c" 1>&6
-      need_lc=$ac_cv_archive_cmds_needs_lc
-    else
-      $rm conftest*
-      echo "static int dummy;" > conftest.$ac_ext
-      if { (eval echo ltcf-c.sh:need_lc: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>conftest.err; }; then
-	# Append any warnings to the config.log.
-	cat conftest.err 1>&5
-	soname=conftest
-	lib=conftest
-	libobjs=conftest.$ac_objext
-	deplibs=
-	wl=$ac_cv_prog_cc_wl
-	compiler_flags=-v
-	linker_flags=-v
-	verstring=
-	output_objdir=.
-	libname=conftest
-	save_allow_undefined_flag=$allow_undefined_flag
-	allow_undefined_flag=
-	if { (eval echo ltcf-c.sh:need_lc: \"$archive_cmds\") 1>&5; (eval $archive_cmds) 2>&1 | grep " -lc " 1>&5 ; }; then
-	  need_lc=no
-	fi
-	allow_undefined_flag=$save_allow_undefined_flag
-      else
-	cat conftest.err 1>&5
-      fi
-    fi
-    $rm conftest*
-    echo "$ac_t$need_lc" 1>&6
-    ;;
-  esac
-fi
-ac_cv_archive_cmds_needs_lc=$need_lc
diff --git a/ltconfig b/ltconfig
deleted file mode 100755
index 354dc1e..0000000
--- a/ltconfig
+++ /dev/null
@@ -1,2797 +0,0 @@
-#! /bin/sh
-
-# ltconfig - Create a system-specific libtool.
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
-# Free Software Foundation, Inc.
-# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
-#
-# This file is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# A lot of this script is taken from autoconf-2.10.
-
-# Check that we are running under the correct shell.
-SHELL=${CONFIG_SHELL-/bin/sh}
-echo=echo
-if test "X$1" = X--no-reexec; then
-  # Discard the --no-reexec flag, and continue.
-  shift
-elif test "X$1" = X--fallback-echo; then
-  # Avoid inline document here, it may be left over
-  :
-elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then
-  # Yippee, $echo works!
-  :
-else
-  # Restart under the correct shell.
-  exec "$SHELL" "$0" --no-reexec ${1+"$@"}
-fi
-
-if test "X$1" = X--fallback-echo; then
-  # used as fallback echo
-  shift
-  cat <<EOF
-$*
-EOF
-  exit 0
-fi
-
-# Find the correct PATH separator.  Usually this is `:', but
-# DJGPP uses `;' like DOS.
-if test "X${PATH_SEPARATOR+set}" != Xset; then
-  UNAME=${UNAME-`uname 2>/dev/null`}
-  case X$UNAME in
-    *-DOS) PATH_SEPARATOR=';' ;;
-    *)     PATH_SEPARATOR=':' ;;
-  esac
-fi
-
-# The HP-UX ksh and POSIX shell print the target directory to stdout
-# if CDPATH is set.
-if test "X${CDPATH+set}" = Xset; then CDPATH=:; export CDPATH; fi
-
-if test "X${echo_test_string+set}" != Xset; then
-  # find a string as large as possible, as long as the shell can cope with it
-  for cmd in 'sed 50q "$0"' 'sed 20q "$0"' 'sed 10q "$0"' 'sed 2q "$0"' 'echo test'; do
-    # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
-    if (echo_test_string="`eval $cmd`") 2>/dev/null &&
-       echo_test_string="`eval $cmd`" &&
-       (test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null; then
-      break
-    fi
-  done
-fi
-
-if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
-   echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
-   test "X$echo_testing_string" = "X$echo_test_string"; then
-  :
-else
-  # The Solaris, AIX, and Digital Unix default echo programs unquote
-  # backslashes.  This makes it impossible to quote backslashes using
-  #   echo "$something" | sed 's/\\/\\\\/g'
-  #
-  # So, first we look for a working echo in the user's PATH.
-
-  IFS="${IFS= 	}"; save_ifs="$IFS"; IFS="${IFS}${PATH_SEPARATOR}"
-  for dir in $PATH /usr/ucb; do
-    if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
-       test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
-       echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
-       test "X$echo_testing_string" = "X$echo_test_string"; then
-      echo="$dir/echo"
-      break
-    fi
-  done
-  IFS="$save_ifs"
-
-  if test "X$echo" = Xecho; then
-    # We didn't find a better echo, so look for alternatives.
-    if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' &&
-       echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` &&
-       test "X$echo_testing_string" = "X$echo_test_string"; then
-      # This shell has a builtin print -r that does the trick.
-      echo='print -r'
-    elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) &&
-	 test "X$CONFIG_SHELL" != X/bin/ksh; then
-      # If we have ksh, try running ltconfig again with it.
-      ORIGINAL_CONFIG_SHELL="${CONFIG_SHELL-/bin/sh}"
-      export ORIGINAL_CONFIG_SHELL
-      CONFIG_SHELL=/bin/ksh
-      export CONFIG_SHELL
-      exec "$CONFIG_SHELL" "$0" --no-reexec ${1+"$@"}
-    else
-      # Try using printf.
-      echo='printf %s\n'
-      if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
-	 echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
-	 test "X$echo_testing_string" = "X$echo_test_string"; then
-	# Cool, printf works
-	:
-      elif echo_testing_string=`("$ORIGINAL_CONFIG_SHELL" "$0" --fallback-echo '\t') 2>/dev/null` &&
-	   test "X$echo_testing_string" = 'X\t' &&
-	   echo_testing_string=`("$ORIGINAL_CONFIG_SHELL" "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
-	   test "X$echo_testing_string" = "X$echo_test_string"; then
-	CONFIG_SHELL="$ORIGINAL_CONFIG_SHELL"
-	export CONFIG_SHELL
-	SHELL="$CONFIG_SHELL"
-	export SHELL
-	echo="$CONFIG_SHELL $0 --fallback-echo"
-      elif echo_testing_string=`("$CONFIG_SHELL" "$0" --fallback-echo '\t') 2>/dev/null` &&
-	   test "X$echo_testing_string" = 'X\t' &&
-	   echo_testing_string=`("$CONFIG_SHELL" "$0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
-	   test "X$echo_testing_string" = "X$echo_test_string"; then
-	echo="$CONFIG_SHELL $0 --fallback-echo"
-      else
-	# maybe with a smaller string...
-	prev=:
-
-	for cmd in 'echo test' 'sed 2q "$0"' 'sed 10q "$0"' 'sed 20q "$0"' 'sed 50q "$0"'; do
-	  if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null; then
-	    break
-	  fi
-	  prev="$cmd"
-	done
-
-	if test "$prev" != 'sed 50q "$0"'; then
-	  echo_test_string=`eval $prev`
-	  
-	  export echo_test_string
-	  exec "${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}}" "$0" ${1+"$@"}
-	else
-	  # Oops.  We lost completely, so just stick with echo.
-	  echo=echo
-	fi
-      fi
-    fi
-  fi
-fi
-
-# Sed substitution that helps us do robust quoting.  It backslashifies
-# metacharacters that are still active within double-quoted strings.
-Xsed='sed -e s/^X//'
-sed_quote_subst='s/\([\\"\\`$\\\\]\)/\\\1/g'
-
-# Same as above, but do not quote variable references.
-double_quote_subst='s/\([\\"\\`\\\\]\)/\\\1/g'
-
-# Sed substitution to delay expansion of an escaped shell variable in a
-# double_quote_subst'ed string.
-delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
-
-# The name of this program.
-progname=`$echo "X$0" | $Xsed -e 's%^.*/%%'`
-
-# Constants:
-PROGRAM=ltconfig
-PACKAGE=libtool
-VERSION=1.4a
-TIMESTAMP=" (1.641.2.255 2001/05/22 10:39:30)"
-ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
-ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
-rm="rm -f"
-
-help="Try \`$progname --help' for more information."
-
-# Global variables:
-default_ofile=libtool
-can_build_shared=yes
-enable_shared=yes
-# All known linkers require a `.a' archive for static linking (except M$VC,
-# which needs '.lib').
-enable_static=yes
-enable_fast_install=yes
-enable_dlopen=unknown
-enable_win32_dll=no
-pic_mode=default
-ltmain=
-silent=
-srcdir=
-ac_config_guess=
-ac_config_sub=
-host=
-build=NONE
-nonopt=NONE
-ofile="$default_ofile"
-verify_host=yes
-tagname=
-with_gcc=no
-with_gnu_ld=no
-need_locks=yes
-ac_ext=c
-libext=a
-cache_file=
-max_cmd_len=
-
-## Dependencies to place before and after the object being linked:
-predep_objects=
-postdep_objects=
-predeps=
-postdeps=
-compiler_lib_search_path=
-
-## Link characteristics:
-allow_undefined_flag=
-no_undefined_flag=
-need_lib_prefix=unknown
-need_version=unknown
-# when you set need_version to no, make sure it does not cause -set_version
-# flags to be left without arguments
-archive_cmds=
-archive_expsym_cmds=
-old_archive_from_new_cmds=
-old_archive_from_expsyms_cmds=
-striplib=
-old_striplib=
-export_dynamic_flag_spec=
-whole_archive_flag_spec=
-thread_safe_flag_spec=
-hardcode_into_libs=no
-hardcode_libdir_flag_spec=
-hardcode_libdir_separator=
-hardcode_direct=no
-hardcode_minus_L=no
-hardcode_shlibpath_var=unsupported
-runpath_var=
-link_all_deplibs=unknown
-always_export_symbols=no
-export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | sed '\''s/.* //'\'' | sort | uniq > $export_symbols'
-# include_expsyms should be a list of space-separated symbols to be *always*
-# included in the symbol list
-include_expsyms=
-# exclude_expsyms can be an egrep regular expression of symbols to exclude
-# it will be wrapped by ` (' and `)$', so one must not match beginning or
-# end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
-# as well as any symbol that contains `d'.
-exclude_expsyms="_GLOBAL_OFFSET_TABLE_"
-# Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
-# platforms (ab)use it in PIC code, but their linkers get confused if
-# the symbol is explicitly referenced.  Since portable code cannot
-# rely on this symbol name, it's probably fine to never include it in
-# preloaded symbol tables.
-extract_expsyms_cmds=
-
-## Tools:
-old_AR="$AR"
-old_AR_FLAGS="$AR_FLAGS"
-old_CC="$CC"
-old_CFLAGS="$CFLAGS"
-old_CPPFLAGS="$CPPFLAGS"
-old_LDFLAGS="$LDFLAGS"
-old_LIBS="$LIBS"
-old_MAGIC_CMD="$MAGIC_CMD"
-old_LD="$LD"
-old_LN_S="$LN_S"
-old_LTCC="$LTCC"
-old_NM="$NM"
-old_RANLIB="$RANLIB"
-old_STRIP="$STRIP"
-old_AS="$AS"
-old_DLLTOOL="$DLLTOOL"
-old_OBJDUMP="$OBJDUMP"
-old_OBJEXT="$OBJEXT"
-old_EXEEXT="$EXEEXT"
-old_reload_flag="$reload_flag"
-old_deplibs_check_method="$deplibs_check_method"
-old_file_magic_cmd="$file_magic_cmd"
-
-# Parse the command line options.
-args=
-prev=
-for option
-do
-  case $option in
-  -*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
-  *) optarg= ;;
-  esac
-
-  # If the previous option needs an argument, assign it.
-  if test -n "$prev"; then
-    eval "$prev=\$option"
-    prev=
-    continue
-  fi
-
-  case $option in
-  --help) cat <<EOM
-Usage: $progname [OPTION]... LTMAIN [HOST]
-
-Generate a system-specific libtool script.
-
-    --build                configure for building on BUILD [BUILD=HOST]
-    --debug                enable verbose shell tracing
-    --disable-shared       do not build shared libraries
-    --disable-static       do not build static libraries
-    --disable-fast-install do not optimize for fast installation
-    --enable-dlopen        enable dlopen support
-    --enable-win32-dll     enable building dlls on win32 hosts
-    --help                 display this help and exit
-    --no-verify            do not verify that HOST is a valid host type
--o, --output=FILE          specify the output file [default=$default_ofile]
-    --quiet                same as \`--silent'
-    --silent               do not print informational messages
-    --srcdir=DIR           find \`config.guess' in DIR
-    --version              output version information and exit
-    --add-tag=TAG          append an alternate configuration
-    --with-gcc             assume that the GNU C compiler will be used
-    --with-gnu-ld          assume that the C compiler uses the GNU linker
-    --prefer-pic           try to use only PIC objects
-    --prefer-non-pic       try to use only non-PIC objects
-    --disable-lock         disable file locking
-    --cache-file=FILE      configure cache file
-
-LTMAIN is the \`ltmain.sh' shell script fragment or \`ltmain.c' program
-that provides basic libtool functionality.
-
-HOST is the canonical host system name [default=guessed].
-EOM
-  exit 0
-  ;;
-
-  --build) prev=build ;;
-  --build=*) build="$optarg" ;;
-
-  --debug)
-    echo "$progname: enabling shell trace mode"
-    set -x
-    ;;
-
-  --disable-shared) enable_shared=no ;;
-
-  --disable-static) enable_static=no ;;
-
-  --disable-fast-install) enable_fast_install=no ;;
-
-  --enable-dlopen) enable_dlopen=yes ;;
-
-  --enable-win32-dll) enable_win32_dll=yes ;;
-
-  --quiet | --silent) silent=yes ;;
-
-  --srcdir) prev=srcdir ;;
-  --srcdir=*) srcdir="$optarg" ;;
-
-  --no-verify) verify_host=no ;;
-
-  --output | -o) prev=ofile ;;
-  --output=*) ofile="$optarg" ;;
-
-  --version) echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP"; exit 0 ;;
-
-  --add-tag) prev=tagname ;;
-  --add-tag=*) tagname="$optarg" ;;
-
-  --with-gcc) with_gcc=yes ;;
-  --with-gnu-ld) with_gnu_ld=yes ;;
-
-  --prefer-pic) pic_mode=yes ;;
-  --prefer-non-pic) pic_mode=no ;;
-
-  --disable-lock) need_locks=no ;;
-
-  --cache-file=*) cache_file="$optarg" ;;
-
-  -*)
-    echo "$progname: unrecognized option \`$option'" 1>&2
-    echo "$help" 1>&2
-    exit 1
-    ;;
-
-  *)
-    if test -z "$ltmain"; then
-      ltmain="$option"
-    elif test -z "$host"; then
-# This generates an unnecessary warning for sparc-sun-solaris4.1.3_U1
-#      if test -n "`echo $option| sed 's/[-a-z0-9.]//g'`"; then
-#        echo "$progname: warning \`$option' is not a valid host type" 1>&2
-#      fi
-      host="$option"
-    else
-      echo "$progname: too many arguments" 1>&2
-      echo "$help" 1>&2
-      exit 1
-    fi ;;
-  esac
-done
-
-if test -z "$ltmain"; then
-  echo "$progname: you must specify a LTMAIN file" 1>&2
-  echo "$help" 1>&2
-  exit 1
-fi
-
-if test ! -f "$ltmain"; then
-  echo "$progname: \`$ltmain' does not exist" 1>&2
-  echo "$help" 1>&2
-  exit 1
-fi
-
-if test -n "$tagname"; then
-  # Check whether tagname contains only valid characters
-  case `$echo "X$tagname" | $Xsed -e 's/[-_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,/]//g'` in
-  "") ;;
-  *)
-    echo "$progname: invalid tag name: $tagname" 1>&2
-    exit 1
-    ;;
-  esac
-
-  if grep "^### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$ofile" > /dev/null; then
-    echo "$progname: tag name $tagname already exists" 1>&2
-    exit 1
-  fi
-
-  if test ! -f "$ofile"; then
-    echo "$progname: warning: output file \`$ofile' does not exist" 1>&2
-  fi
-
-  if test -z "$LTCC"; then
-    eval "`$SHELL $ofile --config | grep '^LTCC='`"
-    if test -z "$LTCC"; then
-      echo "$progname: warning: output file \`$ofile' does not look like a libtool script" 1>&2
-    else
-      echo "$progname: warning: using \`LTCC=$LTCC', extracted from \`$ofile'" 1>&2
-    fi
-  fi
-fi
-
-# Quote any args containing shell metacharacters.
-ltconfig_args=
-for arg
-do
-  case $arg in
-  *" "*|*"	"*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*)
-  ltconfig_args="$ltconfig_args '$arg'" ;;
-  *) ltconfig_args="$ltconfig_args $arg" ;;
-  esac
-done
-
-# A relevant subset of AC_INIT.
-
-# File descriptor usage:
-# 0 standard input
-# 1 file creation
-# 2 errors and warnings
-# 3 some systems may open it to /dev/tty
-# 4 used on the Kubota Titan
-# 5 compiler messages saved in config.log
-# 6 checking for... messages and results
-if test "$silent" = yes; then
-  exec 6>/dev/null
-else
-  exec 6>&1
-fi
-exec 5>>./config.log
-
-# NLS nuisances.
-# Only set LANG and LC_ALL to C if already set.
-# These must not be set unconditionally because not all systems understand
-# e.g. LANG=C (notably SCO).
-if test "X${LC_ALL+set}" = Xset; then LC_ALL=C; export LC_ALL; fi
-if test "X${LANG+set}"   = Xset; then LANG=C;   export LANG;   fi
-
-if test -n "$cache_file" && test -r "$cache_file" && test -f "$cache_file"; then
-  echo "loading cache $cache_file within ltconfig"
-  . $cache_file
-fi
-
-if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
-  # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
-  if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
-    ac_n= ac_c='
-' ac_t='	'
-  else
-    ac_n=-n ac_c= ac_t=
-  fi
-else
-  ac_n= ac_c='\c' ac_t=
-fi
-
-if test -z "$srcdir"; then
-  # Assume the source directory is the same one as the path to LTMAIN.
-  srcdir=`$echo "X$ltmain" | $Xsed -e 's%/[^/]*$%%'`
-  test "$srcdir" = "$ltmain" && srcdir=.
-fi
-
-trap "$rm conftest*; exit 1" 1 2 15
-if test "$verify_host" = yes; then
-  # Check for config.guess and config.sub.
-  ac_aux_dir=
-  for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do
-    if test -f $ac_dir/config.guess; then
-      ac_aux_dir=$ac_dir
-      break
-    fi
-  done
-  if test -z "$ac_aux_dir"; then
-    echo "$progname: cannot find config.guess in $srcdir $srcdir/.. $srcdir/../.." 1>&2
-    echo "$help" 1>&2
-    exit 1
-  fi
-  ac_config_guess=$ac_aux_dir/config.guess
-  ac_config_sub=$ac_aux_dir/config.sub
-
-  # Make sure we can run config.sub.
-  if $SHELL $ac_config_sub sun4 >/dev/null 2>&1; then :
-  else
-    echo "$progname: cannot run $ac_config_sub" 1>&2
-    echo "$help" 1>&2
-    exit 1
-  fi
-
-  echo $ac_n "checking host system type""... $ac_c" 1>&6
-
-  host_alias=$host
-  case $host_alias in
-  "")
-    # Force config.guess to use the C compiler.
-    # CC_FOR_BUILD overrides the CC variable in config.guess but I had
-    # problems with it so do it this way for now.
-    CC="$LTCC"
-
-    if host_alias=`$SHELL $ac_config_guess`; then :
-    else
-      echo "$progname: cannot guess host type; you must specify one" 1>&2
-      echo "$help" 1>&2
-      exit 1
-    fi
-
-    # Restore the C compiler.
-    CC="$old_CC"
-    ;;
-  esac
-  host=`$SHELL $ac_config_sub $host_alias`
-  echo "$ac_t$host" 1>&6
-
-  # Make sure the host verified.
-  test -z "$host" && exit 1
-
-  # Check for the build system type
-  echo $ac_n "checking build system type... $ac_c" 1>&6
-
-  build_alias=$build
-  case $build_alias in
-  NONE)
-    case $nonopt in
-    NONE) build_alias=$host_alias ;;
-    *) build_alias=$nonopt ;;
-    esac ;;
-  esac
-
-  build=`$SHELL $ac_config_sub $build_alias`
-  build_cpu=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
-  build_vendor=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
-  build_os=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
-  echo "$ac_t""$build" 1>&6
-
-elif test -z "$host"; then
-  echo "$progname: you must specify a host type if you use \`--no-verify'" 1>&2
-  echo "$help" 1>&2
-  exit 1
-else
-  host_alias=$host
-  build_alias=$host_alias
-  build=$host
-fi
-
-if test x"$host" != x"$build"; then
-  ac_tool_prefix=${host_alias}-
-else
-  ac_tool_prefix=
-fi
-
-host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
-host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
-host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
-
-# Transform linux* to *-*-linux-gnu*, to support old configure scripts.
-case $host_os in
-linux-gnu*) ;;
-linux*) host=`echo $host | sed 's/^\(.*-.*-linux\)\(.*\)$/\1-gnu\2/'`
-esac
-
-case $host_os in
-aix3*)
-  # AIX sometimes has problems with the GCC collect2 program.  For some
-  # reason, if we set the COLLECT_NAMES environment variable, the problems
-  # vanish in a puff of smoke.
-  if test "X${COLLECT_NAMES+set}" != Xset; then
-    COLLECT_NAMES=
-    export COLLECT_NAMES
-  fi
-  ;;
-esac
-
-# Determine commands to create old-style static archives.
-old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs'
-old_postinstall_cmds='chmod 644 $oldlib'
-old_postuninstall_cmds=
-
-if test -n "$RANLIB"; then
-  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
-  old_postinstall_cmds="\$RANLIB \$oldlib~$old_postinstall_cmds"
-fi
-
-# Source the script associated with the $tagname tag configuration.
-if test -n "$tagname"; then
-  . $ltmain
-else
-  # FIXME:  We should use a variable here
-  # Configure for a C compiler
-  . $srcdir/ltcf-c.sh
-fi
-
-# Set sane defaults for various variables
-test -z "$AR" && AR=ar
-test -z "$AR_FLAGS" && AR_FLAGS=cru
-test -z "$AS" && AS=as
-test -z "$CC" && CC=cc
-test -z "$DLLTOOL" && DLLTOOL=dlltool
-test -z "$MAGIC_CMD" && MAGIC_CMD=file
-test -z "$LD" && LD=ld
-test -z "$LN_S" && LN_S="ln -s"
-test -z "$NM" && NM=nm
-test -z "$OBJDUMP" && OBJDUMP=objdump
-test -z "$RANLIB" && RANLIB=:
-test -z "$STRIP" && STRIP=:
-test -z "$objext" && objext=o
-
-echo $ac_n "checking for objdir... $ac_c" 1>&6
-rm -f .libs 2>/dev/null
-mkdir .libs 2>/dev/null
-if test -d .libs; then
-  objdir=.libs
-else
-  # MS-DOS does not allow filenames that begin with a dot.
-  objdir=_libs
-fi
-rmdir .libs 2>/dev/null
-echo "$ac_t$objdir" 1>&6
-
-# If no C compiler was specified, use CC.
-LTCC=${LTCC-"$CC"}
-
-# Allow CC to be a program name with arguments.
-set dummy $CC
-compiler="$2"
-
-# We assume here that the value for ac_cv_prog_cc_pic will not be cached
-# in isolation, and that seeing it set (from the cache) indicates that
-# the associated values are set (in the cache) correctly too.
-echo $ac_n "checking for $compiler option to produce PIC... $ac_c" 1>&6
-echo "$progname:678:checking for $compiler option to produce PIC" 1>&5
-
-if test -z "$ac_cv_prog_cc_pic"; then
-  echo "$ac_t"none 1>&6
-else
-  echo "$ac_t""$ac_cv_prog_cc_pic" 1>&6
-
-  # Check to make sure the pic_flag actually works.
-  echo $ac_n "checking if $compiler PIC flag $ac_cv_prog_cc_pic works... $ac_c" 1>&6
-  echo "$progname:687:checking that $compiler PIC flag $ac_cv_prog_cc_pic works." 1>&5
-  if test "X${ac_cv_prog_cc_pic_works+set}" = Xset && \
-     test "X${ac_cv_prog_cc_pic_works}" != X; then
-    echo $ac_n "(cached) $ac_c" 1>&6
-  else
-    ac_cv_prog_cc_pic_works=yes
-    $rm conftest*
-    echo $lt_simple_compile_test_code > conftest.$ac_ext
-    save_CFLAGS="$CFLAGS"
-    CFLAGS="$CFLAGS $ac_cv_prog_cc_pic -DPIC"
-    if { (eval echo $progname:697: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>conftest.err; } && test -s conftest.$objext; then
-      # Append any warnings to the config.log.
-      cat conftest.err 1>&5
-
-      case $host_os in
-      hpux9* | hpux10* | hpux11*)
-	# On HP-UX, both CC and GCC only warn that PIC is supported... then
-	# they create non-PIC objects.  So, if there were any warnings, we
-	# assume that PIC is not supported.
-	if test -s conftest.err; then
-	  ac_cv_prog_cc_pic_works=no
-	  ac_cv_prog_cc_can_build_shared=no
-	  ac_cv_prog_cc_pic=
-	else
-	  ac_cv_prog_cc_pic_works=yes
-	  ac_cv_prog_cc_pic=" $ac_cv_prog_cc_pic"
-	fi
-	;;
-      *)
-	ac_cv_prog_cc_pic_works=yes
-	ac_cv_prog_cc_pic=" $ac_cv_prog_cc_pic"
-	;;
-      esac
-    else
-      # Append any errors to the config.log.
-      cat conftest.err 1>&5
-      ac_cv_prog_cc_pic_works=no
-      ac_cv_prog_cc_can_build_shared=no
-      ac_cv_prog_cc_pic=
-    fi
-    CFLAGS="$save_CFLAGS"
-    $rm conftest*
-  fi
-  # Belt *and* braces to stop my trousers falling down:
-  if test "X$ac_cv_prog_cc_pic_works" = Xno; then
-    ac_cv_prog_cc_pic=
-    ac_cv_prog_cc_can_build_shared=no
-  fi
-  echo "$ac_t""$ac_cv_prog_cc_pic_works" 1>&6
-fi
-
-# Check for any special shared library compilation flags.
-if test -n "$ac_cv_prog_cc_shlib"; then
-  echo "$progname: warning: \`$CC' requires \`$ac_cv_prog_cc_shlib' to build shared libraries" 1>&2
-  if echo "$old_CC $old_CFLAGS " | egrep -e "[ 	]$ac_cv_prog_cc_shlib[ 	]" >/dev/null; then :
-  else
-    echo "$progname: add \`$ac_cv_prog_cc_shlib' to the CC or CFLAGS env variable and reconfigure" 1>&2
-    ac_cv_prog_cc_can_build_shared=no
-  fi
-fi
-
-echo $ac_n "checking if $compiler static flag $ac_cv_prog_cc_static works... $ac_c" 1>&6
-echo "$progname:749: checking if $compiler static flag $ac_cv_prog_cc_static works" >&5
-if test "X${ac_cv_prog_cc_static_works+set}" = Xset && \
-   test "X${ac_cv_prog_cc_static_works}" != X; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  $rm conftest*
-  echo $lt_simple_link_test_code > conftest.$ac_ext
-  save_LDFLAGS="$LDFLAGS"
-  LDFLAGS="$LDFLAGS $ac_cv_prog_cc_static"
-  if { (eval echo $progname:758: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
-    ac_cv_prog_cc_static_works=yes
-  else
-    ac_cv_prog_cc_static_works=no
-    ac_cv_prog_cc_static=
-  fi
-  LDFLAGS="$save_LDFLAGS"
-  $rm conftest*
-fi
-# Belt *and* braces to stop my trousers falling down:
-if test "X$ac_cv_prog_cc_static_works" = Xno; then
-  ac_cv_prog_cc_static=
-fi
-echo "$ac_t""$ac_cv_prog_cc_static_works" 1>&6
-pic_flag="$ac_cv_prog_cc_pic"
-special_shlib_compile_flags="$ac_cv_prog_cc_shlib"
-wl="$ac_cv_prog_cc_wl"
-link_static_flag="$ac_cv_prog_cc_static"
-no_builtin_flag="$ac_cv_prog_cc_no_builtin"
-can_build_shared="$ac_cv_prog_cc_can_build_shared"
-
-# find the maximum length of command line arguments
-echo "$progname:780: finding the maximum length of command line arguments" 1>&5
-echo $ac_n "finding the maximum length of command line arguments... $ac_c" 1>&6
-if test "${lt_cv_sys_max_cmd_len+set}" = set; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  i=0
-  testring="ABCD"
-  # If test is not a shell built-in, we'll probably end up computing a
-  # maximum length that is only half of the actual maximum length, but
-  # we can't tell.
-  while test "X"`$CONFIG_SHELL $0 --fallback-echo "X$testring" 2>/dev/null` \
-             = "XX$testring" &&
-          new_result=`expr "X$testring" : ".*" 2>&1` &&
-          lt_cv_sys_max_cmd_len=$new_result &&
-          test $i != 18 # 1 MB should be enough
-  do
-    i=`expr $i + 1`
-    testring=$testring$testring
-  done
-  testring=
-  # add a significant safety factor because C++ compilers can tack on massive amounts
-  # of additional arguments before passing them to the linker.  1/4 should be good.
-  len=`expr $lt_cv_sys_max_cmd_len \/ 4`
-  lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len - $len`
-fi
-echo "$progname:@lineno@: result: $lt_cv_sys_max_cmd_len" 1>&5
-echo "${ac_t}$lt_cv_sys_max_cmd_len" 1>&6
-
-if test -n $lt_cv_sys_max_cmd_len ; then
-  max_cmd_len=$lt_cv_sys_max_cmd_len
-else
-  max_cmd_len=none
-fi
-
-# Check to see if options -o and -c are simultaneously supported by compiler
-echo $ac_n "checking if $compiler supports -c -o file.$objext... $ac_c" 1>&6
-if test "${lt_cv_compiler_c_o+set}" = set; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  $rm -r conftest 2>/dev/null
-  mkdir conftest
-  cd conftest
-  $rm conftest*
-  echo $lt_simple_compile_test_code > conftest.$ac_ext
-  mkdir out
-  # According to Tom Tromey, Ian Lance Taylor reported there are C compilers
-  # that will create temporary files in the current directory regardless of
-  # the output directory.  Thus, making CWD read-only will cause this test
-  # to fail, enabling locking or at least warning the user not to do parallel
-  # builds.
-  chmod -w .
-  save_CFLAGS="$CFLAGS"
-  CFLAGS="$CFLAGS -o out/conftest2.$objext"
-  echo "$progname:833: checking if $compiler supports -c -o file.$objext" >&5
-  if { (eval echo $progname:834: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>out/conftest.err; } && test -s out/conftest2.$objext; then
-
-    # The compiler can only warn and ignore the option if not recognized
-    # So say no if there are warnings
-      if test -s out/conftest.err; then
-        lt_cv_compiler_c_o=no
-      else
-        lt_cv_compiler_c_o=yes
-      fi
-  else
-    # Append any errors to the config.log.
-    cat out/conftest.err 1>&5
-    lt_cv_compiler_c_o=no
-  fi
-  CFLAGS="$save_CFLAGS"
-  chmod u+w .
-  $rm conftest* out/*
-  rmdir out
-  cd ..
-  rmdir conftest
-  $rm -r conftest 2>/dev/null
-fi
-compiler_c_o=$lt_cv_compiler_c_o
-echo "${ac_t}$compiler_c_o" 1>&6
-
-# Check to see if we can do hard links to lock some files if needed
-hard_links="nottested"
-if test "$compiler_c_o" = no && test "$need_locks" != no; then
-  # do not overwrite the value of need_locks provided by the user
-  echo $ac_n "checking if we can lock with hard links... $ac_c" 1>&6
-  hard_links=yes
-  $rm conftest*
-  ln conftest.a conftest.b 2>/dev/null && hard_links=no
-  touch conftest.a
-  ln conftest.a conftest.b 2>&5 || hard_links=no
-  ln conftest.a conftest.b 2>/dev/null && hard_links=no
-  echo "$ac_t$hard_links" 1>&6
-  $rm conftest*
-  if test "$hard_links" = no; then
-    echo "*** WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2
-    need_locks=warn
-  fi
-else
-  need_locks=no
-fi
-
-if test "$with_gcc" = yes; then
-  # Check to see if options -fno-rtti -fno-exceptions are supported by compiler
-  echo $ac_n "checking if $compiler supports -fno-rtti -fno-exceptions ... $ac_c" 1>&6
-  $rm conftest*
-  echo $lt_simple_compile_test_code > conftest.$ac_ext
-  save_CFLAGS="$CFLAGS"
-  CFLAGS="$CFLAGS -fno-rtti -fno-exceptions -c conftest.$ac_ext"
-  echo "$progname:887: checking if $compiler supports -fno-rtti -fno-exceptions" >&5
-  if { (eval echo $progname:888: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>conftest.err; } && test -s conftest.$objext; then
-
-    # The compiler can only warn and ignore the option if not recognized
-    # So say no if there are warnings
-      if test -s conftest.err; then
-	echo "$ac_t"no 1>&6
-	compiler_rtti_exceptions=no
-      else
-	echo "$ac_t"yes 1>&6
-	compiler_rtti_exceptions=yes
-      fi
-  else
-    # Append any errors to the config.log.
-    cat conftest.err 1>&5
-    compiler_rtti_exceptions=no
-    echo "$ac_t"no 1>&6
-  fi
-  CFLAGS="$save_CFLAGS"
-  $rm conftest*
-
-  if test "$compiler_rtti_exceptions" = "yes"; then
-    no_builtin_flag=' -fno-builtin -fno-rtti -fno-exceptions'
-  else
-    no_builtin_flag=' -fno-builtin'
-  fi
-  
-fi
-
-# See if the linker supports building shared libraries.
-echo $ac_n "checking whether the linker ($LD) supports shared libraries... $ac_c" 1>&6
-
-echo "$ac_t$ld_shlibs" 1>&6
-test "$ld_shlibs" = no && can_build_shared=no
-
-# Check hardcoding attributes.
-echo $ac_n "checking how to hardcode library paths into programs... $ac_c" 1>&6
-hardcode_action=
-if test -n "$hardcode_libdir_flag_spec" || \
-   test -n "$runpath_var"; then
-
-  # We can hardcode non-existant directories.
-  if test "$hardcode_direct" != no &&
-     # If the only mechanism to avoid hardcoding is shlibpath_var, we
-     # have to relink, otherwise we might link with an installed library
-     # when we should be linking with a yet-to-be-installed one
-     ## test "$hardcode_shlibpath_var" != no &&
-     test "$hardcode_minus_L" != no; then
-    # Linking always hardcodes the temporary library directory.
-    hardcode_action=relink
-  else
-    # We can link without hardcoding, and we can hardcode nonexisting dirs.
-    hardcode_action=immediate
-  fi
-else
-  # We cannot hardcode anything, or else we can only hardcode existing
-  # directories.
-  hardcode_action=unsupported
-fi
-echo "$ac_t$hardcode_action" 1>&6
-
-echo $ac_n "checking whether stripping libraries is possible... $ac_c" 1>&6
-if test -n "$STRIP" && $STRIP -V 2>&1 | grep "GNU strip" >/dev/null; then
-  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
-  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
-  echo "${ac_t}yes" 1>&6
-else
-  echo "${ac_t}no" 1>&6
-fi
-
-case $reload_flag in
-"" | " "*) ;;
-*) reload_flag=" $reload_flag" ;;
-esac
-reload_cmds='$LD$reload_flag -o $output$reload_objs'
-test -z "$deplibs_check_method" && deplibs_check_method=unknown
-
-# PORTME Fill in your ld.so characteristics
-library_names_spec=
-libname_spec='lib$name'
-soname_spec=
-postinstall_cmds=
-postuninstall_cmds=
-finish_cmds=
-finish_eval=
-shlibpath_var=
-shlibpath_overrides_runpath=unknown
-version_type=none
-dynamic_linker="$host_os ld.so"
-sys_lib_dlsearch_path_spec="/lib /usr/lib"
-sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
-
-echo $ac_n "checking dynamic linker characteristics... $ac_c" 1>&6
-case $host_os in
-aix3*)
-  version_type=linux
-  library_names_spec='${libname}${release}.so$versuffix $libname.a'
-  shlibpath_var=LIBPATH
-
-  # AIX 3 has no versioning support, so we append a major version to the name.
-  soname_spec='${libname}${release}.so$major'
-  ;;
-
-aix4* | aix5*)
-  if test "$host_cpu" = ia64; then
-    # AIX 5 supports IA64
-    library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-    shlibpath_var=LD_LIBRARY_PATH
-  else
-    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
-    # soname into executable. Probably we can add versioning support to
-    # collect2, so additional links can be useful in future.
-    # We preserve .a as extension for shared libraries though AIX4.2
-    # and later linker supports .so
-    if test "$aix_use_runtimelinking" = yes; then
-      # If using run time linking (on AIX 4.2 or later) use lib<name>.so instead of
-      # lib<name>.a to let people know that these are not typical AIX shared libraries.
-      library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-    else
-      # We preserve .a as extension for shared libraries though AIX4.2
-      # and later when we are not doing run time linking.
-      library_names_spec='${libname}${release}.a $libname.a'
-      soname_spec='${libname}${release}.so$major.o'
-    fi
-    # If we're using GNU nm, then we don't want the "-C" option.
-    # -C means demangle to AIX nm, but means don't demangle with GNU nm
-    if $NM -V 2>&1 | egrep '(GNU)' > /dev/null; then
-      export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
-    else
-      export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$2 == "T") || (\$2 == "D") || (\$2 == "B")) && (substr(\$3,1,1) != ".")) { print \$3 } }'\'' | sort -u > $export_symbols'
-    fi
-    shlibpath_var=LIBPATH
-    deplibs_check_method=pass_all
-    case $host_os in
-    aix4 | aix4.[01] | aix4.[01].*)
-      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
-	   echo ' yes '
-	   echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then
-	:
-      else
-	# With GCC up to 2.95.x, collect2 would create an import file
-	# for dependence libraries.  The import file would start with
-	# the line `#! .'.  This would cause the generated library to
-	# depend on `.', always an invalid library.  This was fixed in
-	# development snapshots of GCC prior to 3.0.
-        can_build_shared=no
-      fi
-      ;;
-    esac
-  fi
-  ;;
-
-amigaos*)
-  library_names_spec='$libname.ixlibrary $libname.a'
-  # Create ${libname}_ixlibrary.a entries in /sys/libs.
-  finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "(cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a)"; (cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a) || exit 1; done'
-  ;;
-
-beos*)
-  library_names_spec='${libname}.so'
-  dynamic_linker="$host_os ld.so"
-  shlibpath_var=LIBRARY_PATH
-  lt_cv_dlopen="load_add_on"
-  lt_cv_dlopen_libs=
-  lt_cv_dlopen_self=yes
-  ;;
-
-bsdi4*)
-  version_type=linux
-  need_version=no
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-  soname_spec='${libname}${release}.so$major'
-  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
-  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
-  export_dynamic_flag_spec=-rdynamic
-  # the default ld.so.conf also contains /usr/contrib/lib and
-  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
-  # libtool to hard-code these into programs
-  ;;
-
-cygwin* | mingw* | pw32*)
-  version_type=windows
-  need_version=no
-  need_lib_prefix=no
-  case $with_gcc,$host_os in
-  yes,cygwin*)
-    library_names_spec='$libname.dll.a'
-    soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | [sed -e 's/[.]/-/g']`${versuffix}.dll'
-    postinstall_cmds='dlpath=`bash 2>&1 -c '\''. $dir/${file}i; echo \$dlname'\''`~
-      dldir=$destdir/`dirname \$dlpath`~
-      test -d \$dldir || mkdir -p \$dldir~
-      $install_prog .libs/$dlname \$dldir/$dlname'
-    postuninstall_cmds='dldll=`bash 2>&1 -c '\''. $file; echo \$dlname'\''`~
-      dlpath=$dir/\$dldll; $rm \$dlpath'
-    ;;
-  yes,mingw*)
-    library_names_spec='${libname}`echo ${release} | sed -e 's/[.]/-/g'`${versuffix}.dll'
-    sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | sed -e "s/^libraries://" -e "s/;/ /g"`
-    ;;
-  yes,pw32*)
-    library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | sed -e 's/[.]/-/g'`${versuffix}.dll'
-;;
-  *)
-    library_names_spec='${libname}`echo ${release} | sed -e 's/[.]/-/g'`${versuffix}.dll $libname.lib'
-    ;;
-  esac
-  dynamic_linker='Win32 ld.exe'
-  # FIXME: first we should search . and the directory the executable is in
-  shlibpath_var=PATH
-  lt_cv_dlopen="LoadLibrary"
-  lt_cv_dlopen_libs=
-  ;;
-
-darwin* | rhapsody*)
-  dynamic_linker="$host_os dyld"
-  version_type=darwin
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}${versuffix}.`test .$module = .yes && echo so || echo dylib` ${libname}${release}${major}.`test .$module = .yes && echo so || echo dylib` ${libname}.`test .$module = .yes && echo so || echo dylib`'
-  soname_spec='${libname}${release}${major}.`test .$module = .yes && echo so || echo dylib`'
-  shlibpath_overrides_runpath=yes
-  shlibpath_var=DYLD_LIBRARY_PATH
-  ;;
-
-freebsd1*)
-  dynamic_linker=no
-  ;;
-
-freebsd*)
-  objformat=`test -x /usr/bin/objformat && /usr/bin/objformat || echo aout`
-  version_type=sunos
-  case $objformat in
-    elf*)
-      library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-      soname_spec='${libname}${release}.so$major'
-      need_version=no
-      need_lc=no
-      need_lib_prefix=no
-      ;;
-    *)
-      library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-      need_version=yes
-      ;;
-  esac
-  shlibpath_var=LD_LIBRARY_PATH
-  case $host_os in
-  freebsd2*)
-    shlibpath_overrides_runpath=yes
-    ;;
-  *)
-    shlibpath_overrides_runpath=no
-    hardcode_into_libs=yes
-    ;;
-  esac
-  ;;
-
-gnu*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so${major} ${libname}.so'
-  soname_spec='${libname}${release}.so$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  hardcode_into_libs=yes
-  ;;
-
-hpux9* | hpux10* | hpux11*)
-  # Give a soname corresponding to the major version so that dld.sl refuses to
-  # link against other versions.
-  dynamic_linker="$host_os dld.sl"
-  version_type=sunos
-  need_lib_prefix=no
-  need_version=no
-  shlibpath_var=SHLIB_PATH
-  shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
-  library_names_spec='${libname}${release}.sl$versuffix ${libname}${release}.sl$major $libname.sl'
-  soname_spec='${libname}${release}.sl$major'
-  # HP-UX runs *really* slowly unless shared libraries are mode 555.
-  postinstall_cmds='chmod 555 $lib'
-  ;;
-
-irix5* | irix6*)
-  version_type=irix
-  need_lib_prefix=no
-  need_version=no
-  soname_spec='${libname}${release}.so$major'
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major ${libname}${release}.so $libname.so'
-  case $host_os in
-  irix5*)
-    libsuff= shlibsuff=
-    ;;
-  *)
-    case $LD in # libtool.m4 will add one of these switches to LD
-    *-32|*"-32 ") libsuff= shlibsuff= libmagic=32-bit;;
-    *-n32|*"-n32 ") libsuff=32 shlibsuff=N32 libmagic=N32;;
-    *-64|*"-64 ") libsuff=64 shlibsuff=64 libmagic=64-bit;;
-    *) libsuff= shlibsuff= libmagic=never-match;;
-    esac
-    ;;
-  esac
-  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
-  shlibpath_overrides_runpath=no
-  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
-  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
-  ;;
-
-# No shared lib support for Linux oldld, aout, or coff.
-linux-gnuoldld* | linux-gnuaout* | linux-gnucoff*)
-  dynamic_linker=no
-  ;;
-
-# This must be Linux ELF.
-linux-gnu*)
-  version_type=sunos
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-  soname_spec='${libname}${release}.so$major'
-  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=no
-  # This implies no fast_install, which is unacceptable.
-  # Some rework will be needed to allow for fast_install
-  # before this can be enabled.
-  hardcode_into_libs=yes
-
-  # We used to test for /lib/ld.so.1 and disable shared libraries on
-  # powerpc, because MkLinux only supported shared libraries with the
-  # GNU dynamic linker.  Since this was broken with cross compilers,
-  # most powerpc-linux boxes support dynamic linking these days and
-  # people can always --disable-shared, the test was removed, and we
-  # assume the GNU/Linux dynamic linker is in use.
-  dynamic_linker='GNU/Linux ld.so'
-  ;;
-
-netbsd*)
-  need_lib_prefix=no
-  need_version=no
-  version_type=sunos
-  if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
-    library_names_spec='${libname}${release}.so$versuffix ${libname}.so$versuffix'
-    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
-    dynamic_linker='NetBSD (a.out) ld.so'
-  else
-    library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major ${libname}${release}.so ${libname}.so'
-    soname_spec='${libname}${release}.so$major'
-    dynamic_linker='NetBSD ld.elf_so'
-  fi
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  hardcode_into_libs=yes
-  sys_lib_dlsearch_path_spec="/usr/lib"
-  sys_lib_search_path_spec="/usr/lib"
-  ;;
-
-newsos6)
-  version_type=linux
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  ;;
-
-openbsd*)
-  version_type=sunos
-  if test "$with_gnu_ld" = yes; then
-    need_lib_prefix=no
-    need_version=no
-  fi
-  library_names_spec='${libname}${release}.so$versuffix ${libname}.so$versuffix'
-  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  ;;
-
-os2*)
-  libname_spec='$name'
-  need_lib_prefix=no
-  library_names_spec='$libname.dll $libname.a'
-  dynamic_linker='OS/2 ld.exe'
-  shlibpath_var=LIBPATH
-  ;;
-
-osf3* | osf4* | osf5*)
-  version_type=osf
-  need_version=no
-  soname_spec='${libname}${release}.so'
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so $libname.so'
-  shlibpath_var=LD_LIBRARY_PATH
-  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
-  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
-  ;;
-
-sco3.2v5*)
-  version_type=osf
-  soname_spec='${libname}${release}.so$major'
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-  shlibpath_var=LD_LIBRARY_PATH
-  ;;
-
-solaris*)
-  version_type=sunos
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-  soname_spec='${libname}${release}.so$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  hardcode_into_libs=yes
-  # ldd complains unless libraries are executable
-  postinstall_cmds='chmod +x $lib'
-  ;;
-
-sunos4*)
-  version_type=sunos
-  library_names_spec='${libname}${release}.so$versuffix ${libname}.so$versuffix'
-  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
-  shlibpath_var=LD_LIBRARY_PATH
-  shlibpath_overrides_runpath=yes
-  if test "$with_gnu_ld" = yes; then
-    need_lib_prefix=no
-  fi
-  need_version=yes
-  ;;
-
-sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
-  version_type=linux
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-  soname_spec='${libname}${release}.so$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  case $host_vendor in
-    motorola)
-      need_lib_prefix=no
-      need_version=no
-      shlibpath_overrides_runpath=no
-      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
-      ;;
-  esac
-  ;;
-
-uts4*)
-  version_type=linux
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-  soname_spec='${libname}${release}.so$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  ;;
-
-dgux*)
-  version_type=linux
-  need_lib_prefix=no
-  need_version=no
-  library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so'
-  soname_spec='${libname}${release}.so$major'
-  shlibpath_var=LD_LIBRARY_PATH
-  ;;
-
-sysv4*MP*)
-  if test -d /usr/nec ;then
-    version_type=linux
-    library_names_spec='$libname.so.$versuffix $libname.so.$major $libname.so'
-    soname_spec='$libname.so.$major'
-    shlibpath_var=LD_LIBRARY_PATH
-  fi
-  ;;
-
-*)
-  dynamic_linker=no
-  ;;
-esac
-echo "$ac_t$dynamic_linker" 1>&6
-test "$dynamic_linker" = no && can_build_shared=no
-
-# Check for command to grab the raw symbol name followed by C symbol from nm.
-echo $ac_n "checking command to parse $NM output... $ac_c" 1>&6
-
-# These are sane defaults that work on at least a few old systems.
-# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
-
-# Character class describing NM global symbol codes.
-symcode='[BCDEGRST]'
-
-# Regexp to match symbols that can be accessed directly from C.
-sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
-
-# Transform the above into a raw symbol and a C symbol.
-symxfrm='\1 \2\3 \3'
-
-# Transform an extracted symbol line into a proper C declaration
-global_symbol_to_cdecl="sed -n -e 's/^. .* \(.*\)$/extern char \1;/p'"
-
-# Define system-specific variables.
-case $host_os in
-aix*)
-  symcode='[BCDT]'
-  ;;
-cygwin* | mingw* | pw32*)
-  symcode='[ABCDGISTW]'
-  ;;
-hpux*) # Its linker distinguishes data from code symbols
-  global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern char \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
-  ;;
-irix*)
-  symcode='[BCDEGRST]'
-  ;;
-solaris* | sysv5*)
-  symcode='[BDT]'
-  ;;
-sysv4)
-  symcode='[DFNSTU]'
-  ;;
-esac
-
-# Handle CRLF in mingw tool chain
-opt_cr=
-case $host_os in
-mingw*)
-  opt_cr=`echo 'x\{0,1\}' | tr x '\015'` # option cr in regexp
-  ;;
-esac
-
-# If we're using GNU nm, then use its standard symbol codes.
-if $NM -V 2>&1 | egrep '(GNU|with BFD)' > /dev/null; then
-  symcode='[ABCDGISTW]'
-fi
-
-# Try without a prefix undercore, then with it.
-for ac_symprfx in "" "_"; do
-
-  # Write the raw and C identifiers.
-  global_symbol_pipe="sed -n -e 's/^.*[ 	]\($symcode$symcode*\)[ 	][ 	]*\($ac_symprfx\)$sympat$opt_cr$/$symxfrm/p'"
-
-  # Check to see that the pipe works correctly.
-  pipe_works=no
-  $rm conftest*
-  cat > conftest.$ac_ext <<EOF
-#ifdef __cplusplus
-extern "C" {
-#endif
-char nm_test_var;
-void nm_test_func(){}
-#ifdef __cplusplus
-}
-#endif
-int main(){nm_test_var='a';nm_test_func();return(0);}
-EOF
-
-  echo "$progname:1433: checking if global_symbol_pipe works" >&5
-  if { (eval echo $progname:1434: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; } && test -s conftest.$objext; then
-    # Now try to grab the symbols.
-    nlist=conftest.nm
-    if { echo "$progname:1437: eval \"$NM conftest.$objext | $global_symbol_pipe > $nlist\"" >&5; eval "$NM conftest.$objext | $global_symbol_pipe > $nlist 2>&5"; } && test -s "$nlist"; then
-
-      # Try sorting and uniquifying the output.
-      if sort "$nlist" | uniq > "$nlist"T; then
-	mv -f "$nlist"T "$nlist"
-      else
-	rm -f "$nlist"T
-      fi
-
-      # Make sure that we snagged all the symbols we need.
-      if egrep ' nm_test_var$' "$nlist" >/dev/null; then
-	if egrep ' nm_test_func$' "$nlist" >/dev/null; then
-	  cat <<EOF > conftest.$ac_ext
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-EOF
-	  # Now generate the symbol file.
-	  eval "$global_symbol_to_cdecl"' < "$nlist" >> conftest.$ac_ext'
-
-	  cat <<EOF >> conftest.$ac_ext
-#if defined (__STDC__) && __STDC__
-# define lt_ptr_t void *
-#else
-# define lt_ptr_t char *
-# define const
-#endif
-
-/* The mapping between symbol names and symbols. */
-const struct {
-  const char *name;
-  lt_ptr_t address;
-}
-lt_preloaded_symbols[] =
-{
-EOF
- 	  sed "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (lt_ptr_t) \&\2},/" < "$nlist" >> conftest.$ac_ext
-	  cat <<\EOF >> conftest.$ac_ext
-  {0, (lt_ptr_t) 0}
-};
-
-#ifdef __cplusplus
-}
-#endif
-EOF
-	  # Now try linking the two files.
-	  mv conftest.$objext conftstm.$objext
-	  save_LIBS="$LIBS"
-	  save_CFLAGS="$CFLAGS"
-	  LIBS="conftstm.$objext"
-	  CFLAGS="$CFLAGS$no_builtin_flag"
-	  if { (eval echo $progname:1489: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
-	    pipe_works=yes
-	  else
-	    echo "$progname: failed program was:" >&5
-	    cat conftest.$ac_ext >&5
-	  fi
-	  LIBS="$save_LIBS"
-	else
-	  echo "cannot find nm_test_func in $nlist" >&5
-	fi
-      else
-	echo "cannot find nm_test_var in $nlist" >&5
-      fi
-    else
-      echo "cannot run $global_symbol_pipe" >&5
-    fi
-  else
-    echo "$progname: failed program was:" >&5
-    cat conftest.$ac_ext >&5
-  fi
-  $rm conftest* conftst*
-
-  # Do not use the global_symbol_pipe unless it works.
-  if test "$pipe_works" = yes; then
-    break
-  else
-    global_symbol_pipe=
-  fi
-done
-if test "$pipe_works" = yes; then
-  echo "${ac_t}ok" 1>&6
-else
-  echo "${ac_t}failed" 1>&6
-fi
-
-if test -z "$global_symbol_pipe"; then
-  global_symbol_to_cdecl=
-fi
-
-# Report the final consequences.
-echo "checking if libtool supports shared libraries... $can_build_shared" 1>&6
-
-# Only try to build win32 dlls if AC_LIBTOOL_WIN32_DLL was used in
-# configure.in, otherwise build static only libraries.
-case $host_os in
-cygwin* | mingw* | pw32* | os2*)
-  if test x$can_build_shared = xyes; then
-    test x$enable_win32_dll = xno && can_build_shared=no
-    echo "checking if package supports dlls... $can_build_shared" 1>&6
-  fi
-;;
-esac
-
-echo $ac_n "checking whether to build shared libraries... $ac_c" 1>&6
-test "$can_build_shared" = "no" && enable_shared=no
-
-# On AIX, shared libraries and static libraries use the same namespace, and
-# are all built from PIC.
-case $host_os in
-aix3*)
-  test "$enable_shared" = yes && enable_static=no
-  if test -n "$RANLIB"; then
-    archive_cmds="$archive_cmds~\$RANLIB \$lib"
-    postinstall_cmds='$RANLIB $lib'
-  fi
-  ;;
-
-aix4*)
-  test "$enable_shared" = yes && enable_static=no
-  ;;
-esac
-
-echo "$ac_t$enable_shared" 1>&6
-
-# Make sure either enable_shared or enable_static is yes.
-test "$enable_shared" = yes || enable_static=yes
-
-echo "checking whether to build static libraries... $enable_static" 1>&6
-
-if test "$hardcode_action" = relink; then
-  # Fast installation is not supported
-  enable_fast_install=no
-elif test "$shlibpath_overrides_runpath" = yes ||
-     test "$enable_shared" = no; then
-  # Fast installation is not necessary
-  enable_fast_install=needless
-fi
-
-variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
-if test "$with_gcc" = yes; then
-  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
-fi
-
-# Check whether we must set pic_mode to default
-test -z "$pic_flag" && pic_mode=default
-
-if test "x$enable_dlopen" != xyes; then
-  enable_dlopen=unknown
-  enable_dlopen_self=unknown
-  enable_dlopen_self_static=unknown
-else
-if test "X${lt_cv_dlopen+set}" != Xset; then
-  lt_cv_dlopen=no lt_cv_dlopen_libs=
-echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "$progname:1593: checking for dlopen in -ldl" >&5
-if test "X${ac_cv_lib_dl_dlopen+set}" = Xset; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  ac_save_LIBS="$LIBS"
-LIBS="-ldl  $LIBS"
-cat > conftest.$ac_ext <<EOF
-#line 1600 "ltconfig"
-/* Override any gcc2 internal prototype to avoid an error.  */
-/* We use char because int might match the return type of a gcc2
-    builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char dlopen();
-
-int main() {
-dlopen()
-; return 0; }
-EOF
-if { (eval echo $progname:1613: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
-  rm -rf conftest*
-  ac_cv_lib_dl_dlopen=yes
-else
-  echo "$progname: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  ac_cv_lib_dl_dlopen=no
-fi
-rm -f conftest*
-LIBS="$ac_save_LIBS"
-
-fi
-if test "X$ac_cv_lib_dl_dlopen" = Xyes; then
-  echo "$ac_t""yes" 1>&6
-  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"
-else
-  echo "$ac_t""no" 1>&6
-echo $ac_n "checking for dlopen""... $ac_c" 1>&6
-echo "$progname:1632: checking for dlopen" >&5
-if test "X${ac_cv_func_dlopen+set}" = Xset; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  cat > conftest.$ac_ext <<EOF
-#line 1637 "ltconfig"
-/* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char dlopen(); below.  */
-#include <assert.h>
-/* Override any gcc2 internal prototype to avoid an error.  */
-/* We use char because int might match the return type of a gcc2
-    builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char dlopen();
-
-int main() {
-
-/* The GNU C library defines this for functions which it implements
-    to always fail with ENOSYS.  Some functions are actually named
-    something starting with __ and the normal name is an alias.  */
-#if defined (__stub_dlopen) || defined (__stub___dlopen)
-choke me
-#else
-dlopen();
-#endif
-
-; return 0; }
-EOF
-if { (eval echo $progname:1662: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
-  rm -rf conftest*
-  ac_cv_func_dlopen=yes
-else
-  echo "$progname: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  ac_cv_func_dlopen=no
-fi
-rm -f conftest*
-fi
-if test "X$ac_cv_func_dlopen" = Xyes; then
-  echo "$ac_t""yes" 1>&6
-  lt_cv_dlopen="dlopen"
-else
-  echo "$ac_t""no" 1>&6
-echo $ac_n "checking for dlopen in -lsvld""... $ac_c" 1>&6
-echo "$progname:1679: checking for dlopen in -lsvld" >&5
-if test "X${ac_cv_lib_svld_dlopen+set}" = Xset; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  ac_save_LIBS="$LIBS"
-LIBS="-lsvld  $LIBS"
-cat > conftest.$ac_ext <<EOF
-#line 1686 "ltconfig"
-/* Override any gcc2 internal prototype to avoid an error.  */
-/* We use char because int might match the return type of a gcc2
-    builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char dlopen();
-
-int main() {
-dlopen()
-; return 0; }
-EOF
-if { (eval echo $progname:1699: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
-  rm -rf conftest*
-  ac_cv_lib_svld_dlopen=yes
-else
-  echo "$progname: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  ac_cv_lib_svld_dlopen=no
-fi
-rm -f conftest*
-LIBS="$ac_save_LIBS"
-
-fi
-if test "X$ac_cv_lib_svld_dlopen" = Xyes; then
-  echo "$ac_t""yes" 1>&6
-  lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"
-else
-  echo "$ac_t""no" 1>&6
-echo $ac_n "checking for dld_link in -ldld""... $ac_c" 1>&6
-echo "$progname:1718: checking for dld_link in -ldld" >&5
-if test "X${ac_cv_lib_dld_dld_link+set}" = Xset; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  ac_save_LIBS="$LIBS"
-LIBS="-ldld  $LIBS"
-cat > conftest.$ac_ext <<EOF
-#line 1725 "ltconfig"
-/* Override any gcc2 internal prototype to avoid an error.  */
-/* We use char because int might match the return type of a gcc2
-    builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char dld_link();
-
-int main() {
-dld_link()
-; return 0; }
-EOF
-if { (eval echo $progname:1738: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
-  rm -rf conftest*
-  ac_cv_lib_dld_dld_link=yes
-else
-  echo "$progname: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  ac_cv_lib_dld_dld_link=no
-fi
-rm -f conftest*
-LIBS="$ac_save_LIBS"
-
-fi
-if test "X$ac_cv_lib_dld_dld_link" = Xyes; then
-  echo "$ac_t""yes" 1>&6
-  lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"
-else
-  echo "$ac_t""no" 1>&6
-echo $ac_n "checking for shl_load""... $ac_c" 1>&6
-echo "$progname:1757: checking for shl_load" >&5
-if test "X${ac_cv_func_shl_load+set}" = Xset; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  cat > conftest.$ac_ext <<EOF
-#line 1762 "ltconfig"
-/* System header to define __stub macros and hopefully few prototypes,
-    which can conflict with char shl_load(); below.  */
-#include <assert.h>
-/* Override any gcc2 internal prototype to avoid an error.  */
-/* We use char because int might match the return type of a gcc2
-    builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char shl_load();
-
-int main() {
-
-/* The GNU C library defines this for functions which it implements
-    to always fail with ENOSYS.  Some functions are actually named
-    something starting with __ and the normal name is an alias.  */
-#if defined (__stub_shl_load) || defined (__stub___shl_load)
-choke me
-#else
-shl_load();
-#endif
-
-; return 0; }
-EOF
-if { (eval echo $progname:1787: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
-  rm -rf conftest*
-  ac_cv_func_shl_load=yes
-else
-  echo "$progname: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  ac_cv_func_shl_load=no
-fi
-rm -f conftest*
-fi
-
-if test "X$ac_cv_func_shl_load" = Xyes; then
-  echo "$ac_t""yes" 1>&6
-  lt_cv_dlopen="shl_load"
-else
-  echo "$ac_t""no" 1>&6
-echo $ac_n "checking for shl_load in -ldld""... $ac_c" 1>&6
-echo "$progname:1805: checking for shl_load in -ldld" >&5
-if test "X${ac_cv_lib_dld_shl_load+set}" = Xset; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  ac_save_LIBS="$LIBS"
-LIBS="-ldld  $LIBS"
-cat > conftest.$ac_ext <<EOF
-#line 1812 "ltconfig"
-#include "confdefs.h"
-/* Override any gcc2 internal prototype to avoid an error.  */
-/* We use char because int might match the return type of a gcc2
-    builtin and then its argument prototype would still apply.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-char shl_load();
-
-int main() {
-shl_load()
-; return 0; }
-EOF
-if { (eval echo $progname:1826: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
-  rm -rf conftest*
-  ac_cv_lib_dld_shl_load=yes
-else
-  echo "$progname: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  ac_cv_lib_dld_shl_load=no
-fi
-rm -f conftest*
-LIBS="$ac_save_LIBS"
-
-fi
-if test "X$ac_cv_lib_dld_shl_load" = Xyes; then
-  echo "$ac_t""yes" 1>&6
-  lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"
-else
-  echo "$ac_t""no" 1>&6
-fi
-
-
-fi
-
-
-fi
-
-
-fi
-
-
-fi
-
-fi
-
-fi
-
-  if test "x$lt_cv_dlopen" != xno; then
-    enable_dlopen=yes
-  else
-    enable_dlopen=no
-  fi
-
-  case $lt_cv_dlopen in
-  dlopen)
-for ac_hdr in dlfcn.h; do
-ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
-echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "$progname:1873: checking for $ac_hdr" >&5
-if eval "test \"`echo 'X$''{'ac_cv_header_$ac_safe'+set}'`\" = Xset"; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  cat > conftest.$ac_ext <<EOF
-#line 1878 "ltconfig"
-#include <$ac_hdr>
-int fnord = 0;
-int main () { return(0); }
-EOF
-ac_try="$ac_compile >/dev/null 2>conftest.out"
-{ (eval echo $progname:1884: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
-  rm -rf conftest*
-  eval "ac_cv_header_$ac_safe=yes"
-else
-  echo "$ac_err" >&5
-  echo "$progname: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -rf conftest*
-  eval "ac_cv_header_$ac_safe=no"
-fi
-rm -f conftest*
-fi
-if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
-  echo "$ac_t""yes" 1>&6
-else
-  echo "$ac_t""no" 1>&6
-fi
-done
-
-    if test "x$ac_cv_header_dlfcn_h" = xyes; then
-      CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
-    fi
-    eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
-    LIBS="$lt_cv_dlopen_libs $LIBS"
-
-  echo $ac_n "checking whether a program can dlopen itself""... $ac_c" 1>&6
-echo "$progname:1912: checking whether a program can dlopen itself" >&5
-if test "X${lt_cv_dlopen_self+set}" = Xset; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  if test "$cross_compiling" = yes; then
-    lt_cv_dlopen_self=cross
-  else
-    cat > conftest.$ac_ext <<EOF
-#line 1920 "ltconfig"
-
-#if HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef RTLD_GLOBAL
-# define LTDL_GLOBAL	RTLD_GLOBAL
-#else
-# ifdef DL_GLOBAL
-#  define LTDL_GLOBAL	DL_GLOBAL
-# else
-#  define LTDL_GLOBAL	0
-# endif
-#endif
-
-/* We may have to define LTDL_LAZY_OR_NOW in the command line if we
-   find out it does not work in some platform. */
-#ifndef LTDL_LAZY_OR_NOW
-# ifdef RTLD_LAZY
-#  define LTDL_LAZY_OR_NOW	RTLD_LAZY
-# else
-#  ifdef DL_LAZY
-#   define LTDL_LAZY_OR_NOW	DL_LAZY
-#  else
-#   ifdef RTLD_NOW
-#    define LTDL_LAZY_OR_NOW	RTLD_NOW
-#   else
-#    ifdef DL_NOW
-#     define LTDL_LAZY_OR_NOW	DL_NOW
-#    else
-#     define LTDL_LAZY_OR_NOW	0
-#    endif
-#   endif
-#  endif
-# endif
-#endif
-
-void fnord() { int i=42; }
-int main() {
-    void *self, *ptr1, *ptr2; self=dlopen(0,LTDL_GLOBAL|LTDL_LAZY_OR_NOW);
-    if(self) { ptr1=dlsym(self,"fnord"); ptr2=dlsym(self,"_fnord");
-               if(ptr1 || ptr2) { dlclose(self); exit(0); } } exit(1); }
-
-EOF
-if { (eval echo $progname:1967: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
-then
-  lt_cv_dlopen_self=yes
-else
-  echo "$progname: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -fr conftest*
-  lt_cv_dlopen_self=no
-fi
-rm -fr conftest*
-fi
-
-fi
-
-echo "$ac_t""$lt_cv_dlopen_self" 1>&6
-
-  if test "$lt_cv_dlopen_self" = yes; then
-    LDFLAGS="$LDFLAGS $link_static_flag"
-  echo $ac_n "checking whether a statically linked program can dlopen itself""... $ac_c" 1>&6
-echo "$progname:1986: checking whether a statically linked program can dlopen itself" >&5
-if test "X${lt_cv_dlopen_self_static+set}" = Xset; then
-  echo $ac_n "(cached) $ac_c" 1>&6
-else
-  if test "$cross_compiling" = yes; then
-    lt_cv_dlopen_self_static=cross
-  else
-    cat > conftest.$ac_ext <<EOF
-#line 1994 "ltconfig"
-
-#if HAVE_DLFCN_H
-#include <dlfcn.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef RTLD_GLOBAL
-# define LTDL_GLOBAL	RTLD_GLOBAL
-#else
-# ifdef DL_GLOBAL
-#  define LTDL_GLOBAL	DL_GLOBAL
-# else
-#  define LTDL_GLOBAL	0
-# endif
-#endif
-
-/* We may have to define LTDL_LAZY_OR_NOW in the command line if we
-   find out it does not work in some platform. */
-#ifndef LTDL_LAZY_OR_NOW
-# ifdef RTLD_LAZY
-#  define LTDL_LAZY_OR_NOW	RTLD_LAZY
-# else
-#  ifdef DL_LAZY
-#   define LTDL_LAZY_OR_NOW	DL_LAZY
-#  else
-#   ifdef RTLD_NOW
-#    define LTDL_LAZY_OR_NOW	RTLD_NOW
-#   else
-#    ifdef DL_NOW
-#     define LTDL_LAZY_OR_NOW	DL_NOW
-#    else
-#     define LTDL_LAZY_OR_NOW	0
-#    endif
-#   endif
-#  endif
-# endif
-#endif
-
-void fnord() { int i=42; }
-int main() {
-    void *self, *ptr1, *ptr2; self=dlopen(0,LTDL_GLOBAL|LTDL_LAZY_OR_NOW);
-    if(self) { ptr1=dlsym(self,"fnord"); ptr2=dlsym(self,"_fnord");
-    if(ptr1 || ptr2) { dlclose(self); exit(0); } } exit(1); }
-
-EOF
-if { (eval echo $progname:2041: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
-then
-  lt_cv_dlopen_self_static=yes
-else
-  echo "$progname: failed program was:" >&5
-  cat conftest.$ac_ext >&5
-  rm -fr conftest*
-  lt_cv_dlopen_self_static=no
-fi
-rm -fr conftest*
-fi
-
-fi
-
-echo "$ac_t""$lt_cv_dlopen_self_static" 1>&6
-fi
-    ;;
-  esac
-
-  case $lt_cv_dlopen_self in
-  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
-  *) enable_dlopen_self=unknown ;;
-  esac
-
-  case $lt_cv_dlopen_self_static in
-  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
-  *) enable_dlopen_self_static=unknown ;;
-  esac
-fi
-
-# Copy echo and quote the copy, instead of the original, because it is
-# used later.
-ltecho="$echo"
-if test "X$ltecho" = "X$CONFIG_SHELL $0 --fallback-echo"; then
-   ltecho="$CONFIG_SHELL \$0 --fallback-echo"
-fi
-LTSHELL="$SHELL"
-
-LTCONFIG_VERSION="$VERSION"
-
-# Only quote variables if we're using ltmain.sh.
-case $ltmain in
-*.sh)
-  # Now quote all the things that may contain metacharacters.
-  for var in ltecho old_AR old_AR_FLAGS old_CC old_LTCC old_CFLAGS old_CPPFLAGS \
-    old_MAGIC_CMD old_LD old_LDFLAGS old_LIBS \
-    old_LN_S old_NM old_RANLIB old_STRIP \
-    old_AS old_DLLTOOL old_OBJDUMP \
-    old_OBJEXT old_EXEEXT old_reload_flag \
-    old_deplibs_check_method old_file_magic_cmd \
-    AR AR_FLAGS CC LTCC LD LN_S NM LTSHELL LTCONFIG_VERSION \
-    reload_flag reload_cmds wl \
-    pic_flag link_static_flag no_builtin_flag export_dynamic_flag_spec \
-    thread_safe_flag_spec whole_archive_flag_spec libname_spec \
-    library_names_spec soname_spec \
-    RANLIB old_archive_cmds old_archive_from_new_cmds old_postinstall_cmds \
-    old_postuninstall_cmds archive_cmds archive_expsym_cmds postinstall_cmds \
-    postuninstall_cmds extract_expsyms_cmds old_archive_from_expsyms_cmds \
-    predep_objects postdep_objects predeps postdeps compiler_lib_search_path \
-    old_striplib striplib file_magic_cmd export_symbols_cmds \
-    deplibs_check_method allow_undefined_flag no_undefined_flag \
-    finish_cmds finish_eval global_symbol_pipe global_symbol_to_cdecl \
-    hardcode_libdir_flag_spec hardcode_libdir_separator  \
-    sys_lib_search_path_spec sys_lib_dlsearch_path_spec \
-    compiler_c_o need_locks exclude_expsyms include_expsyms; do
-
-    case $var in
-    reload_cmds | old_archive_cmds | old_archive_from_new_cmds | \
-    old_postinstall_cmds | old_postuninstall_cmds | \
-    export_symbols_cmds | archive_cmds | archive_expsym_cmds | \
-    extract_expsyms_cmds | old_archive_from_expsyms_cmds | \
-    postinstall_cmds | postuninstall_cmds | \
-    finish_cmds | sys_lib_search_path_spec | sys_lib_dlsearch_path_spec)
-      # Double-quote double-evaled strings.
-      eval "$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\"" ### testsuite: skip nested quoting test
-      ;;
-    *)
-      eval "$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\"" ### testsuite: skip nested quoting test
-      ;;
-    esac
-  done
-
-  case $ltecho in
-  *'\$0 --fallback-echo"')
-    ltecho=`$echo "X$ltecho" | $Xsed -e 's/\\\\\\\$0 --fallback-echo"$/$0 --fallback-echo"/'`
-    ;;
-  esac
-
-  if test -z "$tagname"; then
-    trap "$rm \"$ofile\"; exit 1" 1 2 15
-    echo "creating $ofile"
-    $rm "$ofile"
-    cat <<EOF > "$ofile"
-#! $SHELL
-
-# `$echo "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
-# Generated automatically by $PROGRAM (GNU $PACKAGE $VERSION$TIMESTAMP)
-# NOTE: Changes made to this file will be lost: look at ltconfig or ltmain.sh.
-#
-# Copyright (C) 1996-2000 Free Software Foundation, Inc.
-# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-# As a special exception to the GNU General Public License, if you
-# distribute this file as part of a program that contains a
-# configuration script generated by Autoconf, you may include it under
-# the same distribution terms that you use for the rest of that program.
-
-# Sed that helps us avoid accidentally triggering echo(1) options like -n.
-Xsed="sed -e s/^X//"
-
-# The HP-UX ksh and POSIX shell print the target directory to stdout
-# if CDPATH is set.
-if test "X\${CDPATH+set}" = Xset; then CDPATH=:; export CDPATH; fi
-
-# The names of the tagged configurations supported by this script.
-available_tags=
-
-### BEGIN LIBTOOL CONFIG
-EOF
-  else
-    echo "appending configuration tag \"$tagname\" to $ofile"
-    echo "### BEGIN LIBTOOL TAG CONFIG: $tagname" >> "$ofile"
-  fi
-  cfgfile="$ofile"
-  ;;
-
-*)
-  # Double-quote the variables that need it (for aesthetics).
-  for var in old_AR old_AR_FLAGS old_CC old_LTCC old_CFLAGS old_CPPFLAGS \
-    old_MAGIC_CMD old_LD old_LDFLAGS old_LIBS \
-    old_LN_S old_NM old_RANLIB old_STRIP \
-    old_AS old_DLLTOOL old_OBJDUMP \
-    old_OBJEXT old_EXEEXT old_reload_flag \
-    old_deplibs_check_method old_file_magic_cmd; do
-    eval "$var=\\\"\$var\\\""
-  done
-
-  # Just create a config file.
-  cfgfile="$ofile.cfg"
-  if test -z "$tagname"; then
-    trap "$rm \"$cfgfile\"; exit 1" 1 2 15
-    echo "creating $cfgfile"
-    $rm "$cfgfile"
-    cat <<EOF > "$cfgfile"
-# `$echo "$cfgfile" | sed 's%^.*/%%'` - Libtool configuration file.
-# Generated automatically by $PROGRAM (GNU $PACKAGE $VERSION$TIMESTAMP)
-
-### BEGIN LIBTOOL CONFIG
-EOF
-  else
-    echo "appending to $cfgfile"
-    echo "### BEGIN LIBTOOL TAG CONFIG: $tagname" >> "$ofile"
-  fi
-  ;;
-esac
-
-cat <<EOF >> "$cfgfile"
-# Libtool was configured as follows, on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
-#
-# AR=$old_AR AR_FLAGS=$old_AR_FLAGS LTCC=$old_LTCC CC=$old_CC \\
-# CFLAGS=$old_CFLAGS CPPFLAGS=$old_CPPFLAGS \\
-# MAGIC_CMD=$old_MAGIC_CMD LD=$old_LD LDFLAGS=$old_LDFLAGS LIBS=$old_LIBS \\
-# LN_S=$old_LN_S NM=$old_NM RANLIB=$old_RANLIB STRIP=$old_STRIP \\
-# AS=$old_AS DLLTOOL=$old_DLLTOOL OBJDUMP=$old_OBJDUMP \\
-# objext=$old_OBJEXT exeext=$old_EXEEXT reload_flag=$old_reload_flag \\
-# deplibs_check_method=$old_deplibs_check_method \\
-# file_magic_cmd=$old_file_magic_cmd \\
-#   $0$ltconfig_args
-#
-# Compiler and other test output produced by $progname, useful for
-# debugging $progname, is in ./config.log if it exists.
-
-# The version of $progname that generated this script.
-LTCONFIG_VERSION=$LTCONFIG_VERSION
-
-# Shell to use when invoking shell scripts.
-SHELL=$LTSHELL
-
-# Whether or not to build shared libraries.
-build_libtool_libs=$enable_shared
-
-# Whether or not to add -lc for building shared libraries.
-build_libtool_need_lc=$need_lc
-
-# Whether or not to build static libraries.
-build_old_libs=$enable_static
-
-# Whether or not to optimize for fast installation.
-fast_install=$enable_fast_install
-
-# The host system.
-host_alias=$host_alias
-host=$host
-
-# An echo program that does not interpret backslashes.
-echo=$ltecho
-
-# The archiver.
-AR=$AR
-AR_FLAGS=$AR_FLAGS
-
-# A C compiler.
-LTCC=$LTCC
-
-# A language-specific compiler.
-CC=$CC
-
-# Is the compiler the GNU C compiler?
-with_gcc=$with_gcc
-
-# The linker used to build libraries.
-LD=$LD
-
-# Whether we need hard or soft links.
-LN_S=$LN_S
-
-# A BSD-compatible nm program.
-NM=$NM
-
-# A symbol stripping program
-STRIP=$STRIP
-
-# Used to examine libraries when file_magic_cmd begins "file"
-MAGIC_CMD=$MAGIC_CMD
-
-# Used on cygwin: DLL creation program.
-DLLTOOL="$DLLTOOL"
-
-# Used on cygwin: object dumper.
-OBJDUMP="$OBJDUMP"
-
-# Used on cygwin: assembler.
-AS="$AS"
-
-# The name of the directory that contains temporary libtool files.
-objdir=$objdir
-
-# How to create reloadable object files.
-reload_flag=$reload_flag
-reload_cmds=$reload_cmds
-
-# How to pass a linker flag through the compiler.
-wl=$wl
-
-# Object file suffix (normally "o").
-objext="$objext"
-
-# Old archive suffix (normally "a").
-libext="$libext"
-
-# Executable file suffix (normally "").
-exeext="$exeext"
-
-# Additional compiler flags for building library objects.
-pic_flag=$pic_flag
-pic_mode=$pic_mode
-
-# What is the maximum length of a command?
-max_cmd_len=$max_cmd_len
-
-# Does compiler simultaneously support -c and -o options?
-compiler_c_o=$compiler_c_o
-
-# Must we lock files when doing compilation ?
-need_locks=$need_locks
-
-# Do we need the lib prefix for modules?
-need_lib_prefix=$need_lib_prefix
-
-# Do we need a version for libraries?
-need_version=$need_version
-
-# Whether dlopen is supported.
-dlopen_support=$enable_dlopen
-
-# Whether dlopen of programs is supported.
-dlopen_self=$enable_dlopen_self
-
-# Whether dlopen of statically linked programs is supported.
-dlopen_self_static=$enable_dlopen_self_static
-
-# Compiler flag to prevent dynamic linking.
-link_static_flag=$link_static_flag
-
-# Compiler flag to turn off builtin functions.
-no_builtin_flag=$no_builtin_flag
-
-# Compiler flag to allow reflexive dlopens.
-export_dynamic_flag_spec=$export_dynamic_flag_spec
-
-# Compiler flag to generate shared objects directly from archives.
-whole_archive_flag_spec=$whole_archive_flag_spec
-
-# Compiler flag to generate thread-safe objects.
-thread_safe_flag_spec=$thread_safe_flag_spec
-
-# Library versioning type.
-version_type=$version_type
-
-# Format of library name prefix.
-libname_spec=$libname_spec
-
-# List of archive names.  First name is the real one, the rest are links.
-# The last name is the one that the linker finds with -lNAME.
-library_names_spec=$library_names_spec
-
-# The coded name of the library, if different from the real name.
-soname_spec=$soname_spec
-
-# Commands used to build and install an old-style archive.
-RANLIB=$RANLIB
-old_archive_cmds=$old_archive_cmds
-old_postinstall_cmds=$old_postinstall_cmds
-old_postuninstall_cmds=$old_postuninstall_cmds
-
-# Create an old-style archive from a shared archive.
-old_archive_from_new_cmds=$old_archive_from_new_cmds
-
-# Create a temporary old-style archive to link instead of a shared archive.
-old_archive_from_expsyms_cmds=$old_archive_from_expsyms_cmds
-
-# Commands used to build and install a shared archive.
-archive_cmds=$archive_cmds
-archive_expsym_cmds=$archive_expsym_cmds
-postinstall_cmds=$postinstall_cmds
-postuninstall_cmds=$postuninstall_cmds
-
-# Commands to strip libraries.
-old_striplib=$old_striplib
-striplib=$striplib
-
-# Dependencies to place before the objects being linked to create a
-# shared library.
-predep_objects=$predep_objects
-
-# Dependencies to place after the objects being linked to create a
-# shared library.
-postdep_objects=$postdep_objects
-
-# Dependencies to place before the objects being linked to create a
-# shared library.
-predeps=$predeps
-
-# Dependencies to place after the objects being linked to create a
-# shared library.
-postdeps=$postdeps
-
-# The library search path used internally by the compiler when linking
-# a shared library.
-compiler_lib_search_path=$compiler_lib_search_path
-
-# Method to check whether dependent libraries are shared objects.
-deplibs_check_method=$deplibs_check_method
-
-# Command to use when deplibs_check_method == file_magic.
-file_magic_cmd=$file_magic_cmd
-
-# Flag that allows shared libraries with undefined symbols to be built.
-allow_undefined_flag=$allow_undefined_flag
-
-# Flag that forces no undefined symbols.
-no_undefined_flag=$no_undefined_flag
-
-# Commands used to finish a libtool library installation in a directory.
-finish_cmds=$finish_cmds
-
-# Same as above, but a single script fragment to be evaled but not shown.
-finish_eval=$finish_eval
-
-# Take the output of nm and produce a listing of raw symbols and C names.
-global_symbol_pipe=$global_symbol_pipe
-
-# Transform the output of nm in a proper C declaration
-global_symbol_to_cdecl=$global_symbol_to_cdecl
-
-# This is the shared library runtime path variable.
-runpath_var=$runpath_var
-
-# This is the shared library path variable.
-shlibpath_var=$shlibpath_var
-
-# Is shlibpath searched before the hard-coded library search path?
-shlibpath_overrides_runpath=$shlibpath_overrides_runpath
-
-# How to hardcode a shared library path into an executable.
-hardcode_action=$hardcode_action
-
-# Whether we should hardcode library paths into libraries.
-hardcode_into_libs=$hardcode_into_libs
-
-# Flag to hardcode \$libdir into a binary during linking.
-# This must work even if \$libdir does not exist.
-hardcode_libdir_flag_spec=$hardcode_libdir_flag_spec
-
-# Whether we need a single -rpath flag with a separated argument.
-hardcode_libdir_separator=$hardcode_libdir_separator
-
-# Set to yes if using DIR/libNAME.so during linking hardcodes DIR into the
-# resulting binary.
-hardcode_direct=$hardcode_direct
-
-# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
-# resulting binary.
-hardcode_minus_L=$hardcode_minus_L
-
-# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
-# the resulting binary.
-hardcode_shlibpath_var=$hardcode_shlibpath_var
-
-# Variables whose values should be saved in libtool wrapper scripts and
-# restored at relink time.
-variables_saved_for_relink="$variables_saved_for_relink"
-
-# Whether libtool must link a program against all its dependency libraries.
-link_all_deplibs=$link_all_deplibs
-
-# Compile-time system search path for libraries
-sys_lib_search_path_spec=$sys_lib_search_path_spec
-
-# Run-time system search path for libraries
-sys_lib_dlsearch_path_spec=$sys_lib_dlsearch_path_spec
-
-# Fix the shell variable \$srcfile for the compiler.
-fix_srcfile_path="$fix_srcfile_path"
-
-# Set to yes if exported symbols are required.
-always_export_symbols=$always_export_symbols
-
-# The commands to list exported symbols.
-export_symbols_cmds=$export_symbols_cmds
-
-# The commands to extract the exported symbol list from a shared archive.
-extract_expsyms_cmds=$extract_expsyms_cmds
-
-# Symbols that should not be listed in the preloaded symbols.
-exclude_expsyms=$exclude_expsyms
-
-# Symbols that must always be exported.
-include_expsyms=$include_expsyms
-
-EOF
-
-if test -z "$tagname"; then
-  echo '### END LIBTOOL CONFIG' >> "$ofile"
-else
-  echo "### END LIBTOOL TAG CONFIG: $tagname" >> "$ofile"
-fi
-
-case $ltmain in
-*.sh)
-  echo >> "$ofile"
-  if test -z "$tagname"; then
-    case $host_os in
-    aix3*)
-      cat <<\EOF >> "$ofile"
-
-# AIX sometimes has problems with the GCC collect2 program.  For some
-# reason, if we set the COLLECT_NAMES environment variable, the problems
-# vanish in a puff of smoke.
-if test "X${COLLECT_NAMES+set}" != Xset; then
-  COLLECT_NAMES=
-  export COLLECT_NAMES
-fi
-EOF
-      ;;
-    esac
-    case $host in
-    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
-      cat <<'EOF' >> "$ofile"
-      # This is a source program that is used to create dlls on Windows
-      # Don't remove nor modify the starting and closing comments
-# /* ltdll.c starts here */
-# #define WIN32_LEAN_AND_MEAN
-# #include <windows.h>
-# #undef WIN32_LEAN_AND_MEAN
-# #include <stdio.h>
-#
-# #ifndef __CYGWIN__
-# #  ifdef __CYGWIN32__
-# #    define __CYGWIN__ __CYGWIN32__
-# #  endif
-# #endif
-#
-# #ifdef __cplusplus
-# extern "C" {
-# #endif
-# BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved);
-# #ifdef __cplusplus
-# }
-# #endif
-#
-# #ifdef __CYGWIN__
-# #include <cygwin/cygwin_dll.h>
-# DECLARE_CYGWIN_DLL( DllMain );
-# #endif
-# HINSTANCE __hDllInstance_base;
-#
-# BOOL APIENTRY
-# DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
-# {
-#   __hDllInstance_base = hInst;
-#   return TRUE;
-# }
-# /* ltdll.c ends here */
-      # This is a source program that is used to create import libraries
-      # on Windows for dlls which lack them. Don't remove nor modify the
-      # starting and closing comments
-# /* impgen.c starts here */
-# /*   Copyright (C) 1999-2000 Free Software Foundation, Inc.
-#
-#  This file is part of GNU libtool.
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software
-#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#  */
-#
-#  #include <stdio.h>		/* for printf() */
-#  #include <unistd.h>		/* for open(), lseek(), read() */
-#  #include <fcntl.h>		/* for O_RDONLY, O_BINARY */
-#  #include <string.h>		/* for strdup() */
-#
-#  /* O_BINARY isn't required (or even defined sometimes) under Unix */
-#  #ifndef O_BINARY
-#  #define O_BINARY 0
-#  #endif
-#
-#  static unsigned int
-#  pe_get16 (fd, offset)
-#       int fd;
-#       int offset;
-#  {
-#    unsigned char b[2];
-#    lseek (fd, offset, SEEK_SET);
-#    read (fd, b, 2);
-#    return b[0] + (b[1]<<8);
-#  }
-#
-#  static unsigned int
-#  pe_get32 (fd, offset)
-#      int fd;
-#      int offset;
-#  {
-#    unsigned char b[4];
-#    lseek (fd, offset, SEEK_SET);
-#    read (fd, b, 4);
-#    return b[0] + (b[1]<<8) + (b[2]<<16) + (b[3]<<24);
-#  }
-#
-#  static unsigned int
-#  pe_as32 (ptr)
-#       void *ptr;
-#  {
-#    unsigned char *b = ptr;
-#    return b[0] + (b[1]<<8) + (b[2]<<16) + (b[3]<<24);
-#  }
-#
-#  int
-#  main (argc, argv)
-#      int argc;
-#      char *argv[];
-#  {
-#      int dll;
-#      unsigned long pe_header_offset, opthdr_ofs, num_entries, i;
-#      unsigned long export_rva, export_size, nsections, secptr, expptr;
-#      unsigned long name_rvas, nexp;
-#      unsigned char *expdata, *erva;
-#      char *filename, *dll_name;
-#
-#      filename = argv[1];
-#
-#      dll = open(filename, O_RDONLY|O_BINARY);
-#      if (dll < 1)
-#  	return 1;
-#
-#      dll_name = filename;
-#
-#      for (i=0; filename[i]; i++)
-#  	if (filename[i] == '/' || filename[i] == '\\'  || filename[i] == ':')
-#  	    dll_name = filename + i +1;
-#
-#      pe_header_offset = pe_get32 (dll, 0x3c);
-#      opthdr_ofs = pe_header_offset + 4 + 20;
-#      num_entries = pe_get32 (dll, opthdr_ofs + 92);
-#
-#      if (num_entries < 1) /* no exports */
-#  	return 1;
-#
-#      export_rva = pe_get32 (dll, opthdr_ofs + 96);
-#      export_size = pe_get32 (dll, opthdr_ofs + 100);
-#      nsections = pe_get16 (dll, pe_header_offset + 4 +2);
-#      secptr = (pe_header_offset + 4 + 20 +
-#  	      pe_get16 (dll, pe_header_offset + 4 + 16));
-#
-#      expptr = 0;
-#      for (i = 0; i < nsections; i++)
-#      {
-#  	char sname[8];
-#  	unsigned long secptr1 = secptr + 40 * i;
-#  	unsigned long vaddr = pe_get32 (dll, secptr1 + 12);
-#  	unsigned long vsize = pe_get32 (dll, secptr1 + 16);
-#  	unsigned long fptr = pe_get32 (dll, secptr1 + 20);
-#  	lseek(dll, secptr1, SEEK_SET);
-#  	read(dll, sname, 8);
-#  	if (vaddr <= export_rva && vaddr+vsize > export_rva)
-#  	{
-#  	    expptr = fptr + (export_rva - vaddr);
-#  	    if (export_rva + export_size > vaddr + vsize)
-#  		export_size = vsize - (export_rva - vaddr);
-#  	    break;
-#  	}
-#      }
-#
-#      expdata = (unsigned char*)malloc(export_size);
-#      lseek (dll, expptr, SEEK_SET);
-#      read (dll, expdata, export_size);
-#      erva = expdata - export_rva;
-#
-#      nexp = pe_as32 (expdata+24);
-#      name_rvas = pe_as32 (expdata+32);
-#
-#      printf ("EXPORTS\n");
-#      for (i = 0; i<nexp; i++)
-#      {
-#  	unsigned long name_rva = pe_as32 (erva+name_rvas+i*4);
-#  	printf ("\t%s @ %ld ;\n", erva+name_rva, 1+ i);
-#      }
-#
-#      return 0;
-#  }
-# /* impgen.c ends here */
-
-EOF
-    ;;
-  esac
-
-
-    # Append the ltmain.sh script.
-    sed '$q' "$ltmain" >> "$ofile" || (rm -f "$ofile"; exit 1)
-    # We use sed instead of cat because bash on DJGPP gets confused if
-    # if finds mixed CR/LF and LF-only lines.  Since sed operates in
-    # text mode, it properly converts lines to CR/LF.  This bash problem
-    # is reportedly fixed, but why not run on old versions too?
-
-    chmod +x "$ofile"
-  fi
-  ;;
-
-*)
-  # Compile the libtool program.
-  echo "FIXME: would compile $ltmain"
-  ;;
-esac
-
-# Update the list of available tags.
-if test -n "$tagname"; then
-
-  # Extract list of available tagged configurations in $ofile.
-  # Note that this assumes the entire list is on one line.
-  available_tags=`grep "^available_tags=" $ofile | sed -e 's/available_tags=\(.*$\)/\1/' -e 's/\"//g'`
-
-  # Append the new tag name to the list of available tags.
-  available_tags="$available_tags $tagname"
-
-  # Now substitute the updated of available tags.
-  if eval "sed -e 's/^available_tags=.*\$/available_tags=\"$available_tags\"/' ${ofile} > ${ofile}.new"; then
-    mv ${ofile}.new ${ofile}
-    chmod +x "$ofile"
-  else
-    rm -f ${ofile}.new
-    echo "$progname: unable to update list of available tagged configurations."
-    exit 1
-  fi
-fi
-
-# Don't cache tagged configuration!
-test -n "$cache_file" && test -z "$tagname" || exit 0
-
-# AC_CACHE_SAVE
-trap '' 1 2 15
-cat > confcache <<\EOF
-# This file is a shell script that caches the results of configure
-# tests run on this system so they can be shared between configure
-# scripts and configure runs.  It is not useful on other systems.
-# If it contains results you don't want to keep, you may remove or edit it.
-#
-# By default, configure uses ./config.cache as the cache file,
-# creating it if it does not exist already.  You can give configure
-# the --cache-file=FILE option to use a different cache file; that is
-# what configure does when it calls configure scripts in
-# subdirectories, so they share the cache.
-# Giving --cache-file=/dev/null disables caching, for debugging configure.
-# config.status only pays attention to the cache file if you give it the
-# --recheck option to rerun configure.
-#
-EOF
-# The following way of writing the cache mishandles newlines in values,
-# but we know of no workaround that is simple, portable, and efficient.
-# So, don't put newlines in cache variables' values.
-# Ultrix sh set writes to stderr and can't be redirected directly,
-# and sets the high bit in the cache file unless we assign to the vars.
-(set) 2>&1 |
-  case `(ac_space=' '; set | grep ac_space) 2>&1` in
-  *ac_space=\ *)
-    # `set' does not quote correctly, so add quotes (double-quote substitution
-    # turns \\\\ into \\, and sed turns \\ into \).
-    sed -n \
-      -e "s/'/'\\\\''/g" \
-      -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p"
-    ;;
-  *)
-    # `set' quotes correctly as required by POSIX, so do not add quotes.
-    sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p'
-    ;;
-  esac >> confcache
-if cmp -s $cache_file confcache; then
-  :
-else
-  if test -w $cache_file; then
-    echo "updating cache $cache_file"
-    cat confcache > $cache_file
-  else
-    echo "not updating unwritable cache $cache_file"
-  fi
-fi
-rm -f confcache
-
-exit 0
-
-# Local Variables:
-# mode:shell-script
-# sh-indentation:2
-# End:
diff --git a/ltmain.sh b/ltmain.sh
index 42c20ef..e76e46a 100644
--- a/ltmain.sh
+++ b/ltmain.sh
@@ -1,7 +1,7 @@
 # ltmain.sh - Provide generalized library-building support services.
-# NOTE: Changing this file will not affect anything until you rerun ltconfig.
+# NOTE: Changing this file will not affect anything until you rerun configure.
 #
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005
 # Free Software Foundation, Inc.
 # Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
 #
@@ -17,13 +17,41 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
 # configuration script generated by Autoconf, you may include it under
 # the same distribution terms that you use for the rest of that program.
 
+basename="s,^.*/,,g"
+
+# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh
+# is ksh but when the shell is invoked as "sh" and the current value of
+# the _XPG environment variable is not equal to 1 (one), the special
+# positional parameter $0, within a function call, is the name of the
+# function.
+progpath="$0"
+
+# The name of this program:
+progname=`echo "$progpath" | $SED $basename`
+modename="$progname"
+
+# Global variables:
+EXIT_SUCCESS=0
+EXIT_FAILURE=1
+
+PROGRAM=ltmain.sh
+PACKAGE=libtool
+VERSION=1.5.22
+TIMESTAMP=" (1.1220.2.365 2005/12/18 22:14:06)"
+
+# See if we are running on zsh, and set the options which allow our
+# commands through without removal of \ escapes.
+if test -n "${ZSH_VERSION+set}" ; then
+  setopt NO_GLOB_SUBST
+fi
+
 # Check that we have a working $echo.
 if test "X$1" = X--no-reexec; then
   # Discard the --no-reexec flag, and continue.
@@ -36,7 +64,7 @@
   :
 else
   # Restart under the correct shell, and then maybe $echo will work.
-  exec $SHELL "$0" --no-reexec ${1+"$@"}
+  exec $SHELL "$progpath" --no-reexec ${1+"$@"}
 fi
 
 if test "X$1" = X--fallback-echo; then
@@ -45,19 +73,9 @@
   cat <<EOF
 $*
 EOF
-  exit 0
+  exit $EXIT_SUCCESS
 fi
 
-# The name of this program.
-progname=`$echo "$0" | sed 's%^.*/%%'`
-modename="$progname"
-
-# Constants.
-PROGRAM=ltmain.sh
-PACKAGE=libtool
-VERSION=1.4a
-TIMESTAMP=" (1.641.2.255 2001/05/22 10:39:30)"
-
 default_mode=
 help="Try \`$progname --help' for more information."
 magic="%%%MAGIC variable%%%"
@@ -67,10 +85,20 @@
 
 # Sed substitution that helps us do robust quoting.  It backslashifies
 # metacharacters that are still active within double-quoted strings.
-Xsed='sed -e 1s/^X//'
+Xsed="${SED}"' -e 1s/^X//'
 sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'
-SP2NL='tr \040 \012'
-NL2SP='tr \015\012 \040\040'
+# test EBCDIC or ASCII
+case `echo X|tr X '\101'` in
+ A) # ASCII based system
+    # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr
+  SP2NL='tr \040 \012'
+  NL2SP='tr \015\012 \040\040'
+  ;;
+ *) # EBCDIC based system
+  SP2NL='tr \100 \n'
+  NL2SP='tr \r\n \100\100'
+  ;;
+esac
 
 # NLS nuisances.
 # Only set LANG and LC_ALL to C if already set.
@@ -84,16 +112,15 @@
   save_LANG="$LANG"; LANG=C; export LANG
 fi
 
-if test "$LTCONFIG_VERSION" != "$VERSION"; then
-  echo "$modename: ltconfig version \`$LTCONFIG_VERSION' does not match $PROGRAM version \`$VERSION'" 1>&2
-  echo "Fatal configuration error.  See the $PACKAGE docs for more information." 1>&2
-  exit 1
-fi
+# Make sure IFS has a sensible default
+lt_nl='
+'
+IFS=" 	$lt_nl"
 
 if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then
-  echo "$modename: not configured to build any kind of library" 1>&2
-  echo "Fatal configuration error.  See the $PACKAGE docs for more information." 1>&2
-  exit 1
+  $echo "$modename: not configured to build any kind of library" 1>&2
+  $echo "Fatal configuration error.  See the $PACKAGE docs for more information." 1>&2
+  exit $EXIT_FAILURE
 fi
 
 # Global variables.
@@ -105,11 +132,314 @@
 show="$echo"
 show_help=
 execute_dlfiles=
+duplicate_deps=no
+preserve_args=
 lo2o="s/\\.lo\$/.${objext}/"
 o2lo="s/\\.${objext}\$/.lo/"
 
+#####################################
+# Shell function definitions:
+# This seems to be the best place for them
+
+# func_mktempdir [string]
+# Make a temporary directory that won't clash with other running
+# libtool processes, and avoids race conditions if possible.  If
+# given, STRING is the basename for that directory.
+func_mktempdir ()
+{
+    my_template="${TMPDIR-/tmp}/${1-$progname}"
+
+    if test "$run" = ":"; then
+      # Return a directory name, but don't create it in dry-run mode
+      my_tmpdir="${my_template}-$$"
+    else
+
+      # If mktemp works, use that first and foremost
+      my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null`
+
+      if test ! -d "$my_tmpdir"; then
+	# Failing that, at least try and use $RANDOM to avoid a race
+	my_tmpdir="${my_template}-${RANDOM-0}$$"
+
+	save_mktempdir_umask=`umask`
+	umask 0077
+	$mkdir "$my_tmpdir"
+	umask $save_mktempdir_umask
+      fi
+
+      # If we're not in dry-run mode, bomb out on failure
+      test -d "$my_tmpdir" || {
+        $echo "cannot create temporary directory \`$my_tmpdir'" 1>&2
+	exit $EXIT_FAILURE
+      }
+    fi
+
+    $echo "X$my_tmpdir" | $Xsed
+}
+
+
+# func_win32_libid arg
+# return the library type of file 'arg'
+#
+# Need a lot of goo to handle *both* DLLs and import libs
+# Has to be a shell function in order to 'eat' the argument
+# that is supplied when $file_magic_command is called.
+func_win32_libid ()
+{
+  win32_libid_type="unknown"
+  win32_fileres=`file -L $1 2>/dev/null`
+  case $win32_fileres in
+  *ar\ archive\ import\ library*) # definitely import
+    win32_libid_type="x86 archive import"
+    ;;
+  *ar\ archive*) # could be an import, or static
+    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | \
+      $EGREP -e 'file format pe-i386(.*architecture: i386)?' >/dev/null ; then
+      win32_nmres=`eval $NM -f posix -A $1 | \
+	$SED -n -e '1,100{/ I /{s,.*,import,;p;q;};}'`
+      case $win32_nmres in
+      import*)  win32_libid_type="x86 archive import";;
+      *)        win32_libid_type="x86 archive static";;
+      esac
+    fi
+    ;;
+  *DLL*)
+    win32_libid_type="x86 DLL"
+    ;;
+  *executable*) # but shell scripts are "executable" too...
+    case $win32_fileres in
+    *MS\ Windows\ PE\ Intel*)
+      win32_libid_type="x86 DLL"
+      ;;
+    esac
+    ;;
+  esac
+  $echo $win32_libid_type
+}
+
+
+# func_infer_tag arg
+# Infer tagged configuration to use if any are available and
+# if one wasn't chosen via the "--tag" command line option.
+# Only attempt this if the compiler in the base compile
+# command doesn't match the default compiler.
+# arg is usually of the form 'gcc ...'
+func_infer_tag ()
+{
+    # Set the commonly-used compilers for some tags.
+    tag_compilers_CC="*cc *xlc"
+    tag_compilers_CXX="*++ *CC"
+    tag_compilers_F77="*77 *fort"
+    base_compiler=`set -- "$@"; $echo $1`
+    # If $tagname still isn't set, then try to infer if the default
+    # "CC" tag applies by matching up the base compile command to some
+    # compilers commonly used for the "CC" tag.
+    if test -z "$tagname"; then
+        z=CC
+        eval "tag_compilers=\$tag_compilers_${z}"
+        if test -n "$tag_compilers"; then
+        for zp in $tag_compilers; do
+          case $base_compiler in
+            $zp)
+            # The compiler in the base compile command matches
+            # one of the common compilers for the current tag.
+            # Assume this is the tagged configuration we want.
+            tagname=$z
+            break
+            ;;
+          esac
+        done
+        fi
+    fi
+    if test -n "$available_tags" && test -z "$tagname"; then
+      CC_quoted=
+      for arg in $CC; do
+	case $arg in
+	  *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+	  arg="\"$arg\""
+	  ;;
+	esac
+	CC_quoted="$CC_quoted $arg"
+      done
+      case $@ in
+      # Blanks in the command may have been stripped by the calling shell,
+      # but not from the CC environment variable when configure was run.
+      " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*) ;;
+      # Blanks at the start of $base_compile will cause this to fail
+      # if we don't check for them as well.
+      *)
+	for z in $available_tags; do
+	  if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then
+	    # Evaluate the configuration.
+	    eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`"
+	    CC_quoted=
+	    for arg in $CC; do
+	    # Double-quote args containing other shell metacharacters.
+	    case $arg in
+	      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+	      arg="\"$arg\""
+	      ;;
+	    esac
+	    CC_quoted="$CC_quoted $arg"
+	  done
+	    case "$@ " in
+	      " $CC "* | "$CC "* | " `$echo $CC` "* | "`$echo $CC` "* | " $CC_quoted"* | "$CC_quoted "* | " `$echo $CC_quoted` "* | "`$echo $CC_quoted` "*)
+	      # The compiler in the base compile command matches
+	      # the one in the tagged configuration.
+	      # Assume this is the tagged configuration we want.
+	      tagname=$z
+	      break
+	      ;;
+	    esac
+	    # If $tagname still isn't set, then try to infer it by
+	    # matching up the base compile command to some compilers
+	    # commonly used for certain tags.
+	    base_compiler=`set -- "$@"; $echo $1`
+	    eval "tag_compilers=\$tag_compilers_${z}"
+	    if test -n "$tag_compilers"; then
+	      for zp in $tag_compilers; do
+		case $base_compiler in 
+		  $zp)
+		  # The compiler in the base compile command matches
+		  # one of the common compilers for the current tag.
+		  # Assume this is the tagged configuration we want.
+		  tagname=$z
+		  break
+		  ;;
+		esac
+	      done
+	      if test -n "$tagname"; then
+		break
+	      fi
+	    fi
+	  fi
+	done
+	# If $tagname still isn't set, then no tagged configuration
+	# was found and let the user know that the "--tag" command
+	# line option must be used.
+	if test -z "$tagname"; then
+	  $echo "$modename: unable to infer tagged configuration"
+	  $echo "$modename: specify a tag with \`--tag'" 1>&2
+	  exit $EXIT_FAILURE
+#        else
+#          $echo "$modename: using $tagname tagged configuration"
+	fi
+	;;
+      esac
+    fi
+}
+
+
+# func_extract_an_archive dir oldlib
+func_extract_an_archive ()
+{
+    f_ex_an_ar_dir="$1"; shift
+    f_ex_an_ar_oldlib="$1"
+
+    $show "(cd $f_ex_an_ar_dir && $AR x $f_ex_an_ar_oldlib)"
+    $run eval "(cd \$f_ex_an_ar_dir && $AR x \$f_ex_an_ar_oldlib)" || exit $?
+    if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then
+     :
+    else
+      $echo "$modename: ERROR: object name conflicts: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" 1>&2
+      exit $EXIT_FAILURE
+    fi
+}
+
+# func_extract_archives gentop oldlib ...
+func_extract_archives ()
+{
+    my_gentop="$1"; shift
+    my_oldlibs=${1+"$@"}
+    my_oldobjs=""
+    my_xlib=""
+    my_xabs=""
+    my_xdir=""
+    my_status=""
+
+    $show "${rm}r $my_gentop"
+    $run ${rm}r "$my_gentop"
+    $show "$mkdir $my_gentop"
+    $run $mkdir "$my_gentop"
+    my_status=$?
+    if test "$my_status" -ne 0 && test ! -d "$my_gentop"; then
+      exit $my_status
+    fi
+
+    for my_xlib in $my_oldlibs; do
+      # Extract the objects.
+      case $my_xlib in
+	[\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;;
+	*) my_xabs=`pwd`"/$my_xlib" ;;
+      esac
+      my_xlib=`$echo "X$my_xlib" | $Xsed -e 's%^.*/%%'`
+      my_xdir="$my_gentop/$my_xlib"
+
+      $show "${rm}r $my_xdir"
+      $run ${rm}r "$my_xdir"
+      $show "$mkdir $my_xdir"
+      $run $mkdir "$my_xdir"
+      exit_status=$?
+      if test "$exit_status" -ne 0 && test ! -d "$my_xdir"; then
+	exit $exit_status
+      fi
+      case $host in
+      *-darwin*)
+	$show "Extracting $my_xabs"
+	# Do not bother doing anything if just a dry run
+	if test -z "$run"; then
+	  darwin_orig_dir=`pwd`
+	  cd $my_xdir || exit $?
+	  darwin_archive=$my_xabs
+	  darwin_curdir=`pwd`
+	  darwin_base_archive=`$echo "X$darwin_archive" | $Xsed -e 's%^.*/%%'`
+	  darwin_arches=`lipo -info "$darwin_archive" 2>/dev/null | $EGREP Architectures 2>/dev/null`
+	  if test -n "$darwin_arches"; then 
+	    darwin_arches=`echo "$darwin_arches" | $SED -e 's/.*are://'`
+	    darwin_arch=
+	    $show "$darwin_base_archive has multiple architectures $darwin_arches"
+	    for darwin_arch in  $darwin_arches ; do
+	      mkdir -p "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+	      lipo -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}"
+	      cd "unfat-$$/${darwin_base_archive}-${darwin_arch}"
+	      func_extract_an_archive "`pwd`" "${darwin_base_archive}"
+	      cd "$darwin_curdir"
+	      $rm "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}"
+	    done # $darwin_arches
+      ## Okay now we have a bunch of thin objects, gotta fatten them up :)
+	    darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print| xargs basename | sort -u | $NL2SP`
+	    darwin_file=
+	    darwin_files=
+	    for darwin_file in $darwin_filelist; do
+	      darwin_files=`find unfat-$$ -name $darwin_file -print | $NL2SP`
+	      lipo -create -output "$darwin_file" $darwin_files
+	    done # $darwin_filelist
+	    ${rm}r unfat-$$
+	    cd "$darwin_orig_dir"
+	  else
+	    cd "$darwin_orig_dir"
+ 	    func_extract_an_archive "$my_xdir" "$my_xabs"
+	  fi # $darwin_arches
+	fi # $run
+	;;
+      *)
+        func_extract_an_archive "$my_xdir" "$my_xabs"
+        ;;
+      esac
+      my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
+    done
+    func_extract_archives_result="$my_oldobjs"
+}
+# End of Shell function definitions
+#####################################
+
+# Darwin sucks
+eval std_shrext=\"$shrext_cmds\"
+
+disable_libs=no
+
 # Parse our command line options once, thoroughly.
-while test $# -gt 0
+while test "$#" -gt 0
 do
   arg="$1"
   shift
@@ -127,13 +457,14 @@
       ;;
     tag)
       tagname="$arg"
+      preserve_args="${preserve_args}=$arg"
 
       # Check whether tagname contains only valid characters
       case $tagname in
       *[!-_A-Za-z0-9,/]*)
-	echo "$progname: invalid tag name: $tagname" 1>&2
-	exit 1
-        ;;
+	$echo "$progname: invalid tag name: $tagname" 1>&2
+	exit $EXIT_FAILURE
+	;;
       esac
 
       case $tagname in
@@ -142,14 +473,14 @@
 	# not specially marked.
 	;;
       *)
-        if grep "^### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$0" > /dev/null; then
-          taglist="$taglist $tagname"
+	if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "$progpath" > /dev/null; then
+	  taglist="$taglist $tagname"
 	  # Evaluate the configuration.
-	  eval "`sed -n -e '/^### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $0`"
-        else
-	  echo "$progname: ignoring unknown tag $tagname" 1>&2
-        fi
-        ;;
+	  eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^# ### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $progpath`"
+	else
+	  $echo "$progname: ignoring unknown tag $tagname" 1>&2
+	fi
+	;;
       esac
       ;;
     *)
@@ -169,22 +500,27 @@
     ;;
 
   --version)
-    echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP"
-    exit 0
+    $echo "$PROGRAM (GNU $PACKAGE) $VERSION$TIMESTAMP"
+    $echo
+    $echo "Copyright (C) 2005  Free Software Foundation, Inc."
+    $echo "This is free software; see the source for copying conditions.  There is NO"
+    $echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+    exit $?
     ;;
 
   --config)
-    sed -n -e '/^### BEGIN LIBTOOL CONFIG/,/^### END LIBTOOL CONFIG/p' < "$0"
+    ${SED} -e '1,/^# ### BEGIN LIBTOOL CONFIG/d' -e '/^# ### END LIBTOOL CONFIG/,$d' $progpath
     # Now print the configurations for the tags.
     for tagname in $taglist; do
-      sed -n -e "/^### BEGIN LIBTOOL TAG CONFIG: $tagname$/,/^### END LIBTOOL TAG CONFIG: $tagname$/p" < "$0"
+      ${SED} -n -e "/^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$/,/^# ### END LIBTOOL TAG CONFIG: $tagname$/p" < "$progpath"
     done
-    exit 0
+    exit $?
     ;;
 
   --debug)
-    echo "$progname: enabling shell trace mode"
+    $echo "$progname: enabling shell trace mode"
     set -x
+    preserve_args="$preserve_args $arg"
     ;;
 
   --dry-run | -n)
@@ -192,18 +528,18 @@
     ;;
 
   --features)
-    echo "host: $host"
+    $echo "host: $host"
     if test "$build_libtool_libs" = yes; then
-      echo "enable shared libraries"
+      $echo "enable shared libraries"
     else
-      echo "disable shared libraries"
+      $echo "disable shared libraries"
     fi
     if test "$build_old_libs" = yes; then
-      echo "enable static libraries"
+      $echo "enable static libraries"
     else
-      echo "disable static libraries"
+      $echo "disable static libraries"
     fi
-    exit 0
+    exit $?
     ;;
 
   --finish) mode="finish" ;;
@@ -215,13 +551,19 @@
 
   --quiet | --silent)
     show=:
+    preserve_args="$preserve_args $arg"
     ;;
 
-  --tag) prevopt="--tag" prev=tag ;;
+  --tag)
+    prevopt="--tag"
+    prev=tag
+    preserve_args="$preserve_args --tag"
+    ;;
   --tag=*)
     set tag "$optarg" ${1+"$@"}
     shift
     prev=tag
+    preserve_args="$preserve_args --tag"
     ;;
 
   -dlopen)
@@ -232,7 +574,7 @@
   -*)
     $echo "$modename: unrecognized option \`$arg'" 1>&2
     $echo "$help" 1>&2
-    exit 1
+    exit $EXIT_FAILURE
     ;;
 
   *)
@@ -245,9 +587,21 @@
 if test -n "$prevopt"; then
   $echo "$modename: option \`$prevopt' requires an argument" 1>&2
   $echo "$help" 1>&2
-  exit 1
+  exit $EXIT_FAILURE
 fi
 
+case $disable_libs in
+no) 
+  ;;
+shared)
+  build_libtool_libs=no
+  build_old_libs=yes
+  ;;
+static)
+  build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
+  ;;
+esac
+
 # If this variable is set in any of the actions, the command in it
 # will be execed at the end.  This prevents here-documents from being
 # left over by shells.
@@ -257,8 +611,10 @@
 
   # Infer the operation mode.
   if test -z "$mode"; then
+    $echo "*** Warning: inferring the mode of operation is deprecated." 1>&2
+    $echo "*** Future versions of Libtool will require --mode=MODE be specified." 1>&2
     case $nonopt in
-    *cc | *++ | gcc* | *-gcc* | *CC)
+    *cc | cc* | *++ | gcc* | *-gcc* | g++* | xlc* | *CC)
       mode=link
       for arg
       do
@@ -299,7 +655,7 @@
   if test -n "$execute_dlfiles" && test "$mode" != execute; then
     $echo "$modename: unrecognized option \`-dlopen'" 1>&2
     $echo "$help" 1>&2
-    exit 1
+    exit $EXIT_FAILURE
   fi
 
   # Change the help message to a mode-specific one.
@@ -313,158 +669,127 @@
     modename="$modename: compile"
     # Get the compilation command and the source file.
     base_compile=
-    prev=
-    lastarg=
-    srcfile="$nonopt"
+    srcfile="$nonopt"  #  always keep a non-empty value in "srcfile"
+    suppress_opt=yes
     suppress_output=
+    arg_mode=normal
+    libobj=
+    later=
 
-    user_target=no
     for arg
     do
-      case $prev in
-      "") ;;
-      xcompiler)
-	# Aesthetically quote the previous argument.
-	prev=
-	lastarg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
-
-	case $arg in
-	# Double-quote args containing other shell metacharacters.
-	# Many Bourne shells cannot handle close brackets correctly
-	# in scan sets, so we specify it separately.
-	*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
-	  arg="\"$arg\""
-	  ;;
-	esac
-
-	# Add the previous argument to base_compile.
-	if test -z "$base_compile"; then
-	  base_compile="$lastarg"
-	else
-	  base_compile="$base_compile $lastarg"
-	fi
-	continue
-	;;
-      esac
-
-      # Accept any command-line options.
-      case $arg in
-      -o)
-	if test "$user_target" != "no"; then
-	  $echo "$modename: you cannot specify \`-o' more than once" 1>&2
-	  exit 1
-	fi
-	user_target=next
+      case $arg_mode in
+      arg  )
+	# do not "continue".  Instead, add this to base_compile
+	lastarg="$arg"
+	arg_mode=normal
 	;;
 
-      -static)
-	build_old_libs=yes
-	continue
-	;;
-
-      -prefer-pic)
-	pic_mode=yes
-	continue
-	;;
-
-      -prefer-non-pic)
-	pic_mode=no
-	continue
-	;;
-
-      -Xcompiler)
-	prev=xcompiler
-	continue
-	;;
-
-      -Wc,*)
-	args=`$echo "X$arg" | $Xsed -e "s/^-Wc,//"`
-	lastarg=
-	IFS="${IFS= 	}"; save_ifs="$IFS"; IFS=','
-	for arg in $args; do
-	  IFS="$save_ifs"
-
-	  # Double-quote args containing other shell metacharacters.
-	  # Many Bourne shells cannot handle close brackets correctly
-	  # in scan sets, so we specify it separately.
-	  case $arg in
-	    *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
-	    arg="\"$arg\""
-	    ;;
-	  esac
-	  lastarg="$lastarg $arg"
-	done
-	IFS="$save_ifs"
-	lastarg=`$echo "X$lastarg" | $Xsed -e "s/^ //"`
-
-	# Add the arguments to base_compile.
-	if test -z "$base_compile"; then
-	  base_compile="$lastarg"
-	else
-	  base_compile="$base_compile $lastarg"
-	fi
-	continue
-	;;
-      esac
-
-      case $user_target in
-      next)
-	# The next one is the -o target name
-	user_target=yes
-	continue
-	;;
-      yes)
-	# We got the output file
-	user_target=set
+      target )
 	libobj="$arg"
+	arg_mode=normal
 	continue
 	;;
-      esac
 
-      # Accept the current argument as the source file.
-      lastarg="$srcfile"
-      srcfile="$arg"
+      normal )
+	# Accept any command-line options.
+	case $arg in
+	-o)
+	  if test -n "$libobj" ; then
+	    $echo "$modename: you cannot specify \`-o' more than once" 1>&2
+	    exit $EXIT_FAILURE
+	  fi
+	  arg_mode=target
+	  continue
+	  ;;
+
+	-static | -prefer-pic | -prefer-non-pic)
+	  later="$later $arg"
+	  continue
+	  ;;
+
+	-no-suppress)
+	  suppress_opt=no
+	  continue
+	  ;;
+
+	-Xcompiler)
+	  arg_mode=arg  #  the next one goes into the "base_compile" arg list
+	  continue      #  The current "srcfile" will either be retained or
+	  ;;            #  replaced later.  I would guess that would be a bug.
+
+	-Wc,*)
+	  args=`$echo "X$arg" | $Xsed -e "s/^-Wc,//"`
+	  lastarg=
+	  save_ifs="$IFS"; IFS=','
+ 	  for arg in $args; do
+	    IFS="$save_ifs"
+
+	    # Double-quote args containing other shell metacharacters.
+	    # Many Bourne shells cannot handle close brackets correctly
+	    # in scan sets, so we specify it separately.
+	    case $arg in
+	      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+	      arg="\"$arg\""
+	      ;;
+	    esac
+	    lastarg="$lastarg $arg"
+	  done
+	  IFS="$save_ifs"
+	  lastarg=`$echo "X$lastarg" | $Xsed -e "s/^ //"`
+
+	  # Add the arguments to base_compile.
+	  base_compile="$base_compile $lastarg"
+	  continue
+	  ;;
+
+	* )
+	  # Accept the current argument as the source file.
+	  # The previous "srcfile" becomes the current argument.
+	  #
+	  lastarg="$srcfile"
+	  srcfile="$arg"
+	  ;;
+	esac  #  case $arg
+	;;
+      esac    #  case $arg_mode
 
       # Aesthetically quote the previous argument.
-
-      # Backslashify any backslashes, double quotes, and dollar signs.
-      # These are the only characters that are still specially
-      # interpreted inside of double-quoted scrings.
       lastarg=`$echo "X$lastarg" | $Xsed -e "$sed_quote_subst"`
 
+      case $lastarg in
       # Double-quote args containing other shell metacharacters.
       # Many Bourne shells cannot handle close brackets correctly
-      # in scan sets, so we specify it separately.
-      case $lastarg in
+      # in scan sets, and some SunOS ksh mistreat backslash-escaping
+      # in scan sets (worked around with variable expansion),
+      # and furthermore cannot handle '|' '&' '(' ')' in scan sets 
+      # at all, so we specify them separately.
       *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
 	lastarg="\"$lastarg\""
 	;;
       esac
 
-      # Add the previous argument to base_compile.
-      if test -z "$base_compile"; then
-	base_compile="$lastarg"
-      else
-	base_compile="$base_compile $lastarg"
-      fi
-    done
+      base_compile="$base_compile $lastarg"
+    done # for arg
 
-    case $user_target in
-    set)
+    case $arg_mode in
+    arg)
+      $echo "$modename: you must specify an argument for -Xcompile"
+      exit $EXIT_FAILURE
       ;;
-    no)
-      # Get the name of the library object.
-      libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'`
+    target)
+      $echo "$modename: you must specify a target with \`-o'" 1>&2
+      exit $EXIT_FAILURE
       ;;
     *)
-      $echo "$modename: you must specify a target with \`-o'" 1>&2
-      exit 1
+      # Get the name of the library object.
+      [ -z "$libobj" ] && libobj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%'`
       ;;
     esac
 
     # Recognize several different file suffixes.
     # If the user specifies -o file.o, it is replaced with file.lo
-    xform='[cCFSfmso]'
+    xform='[cCFSifmso]'
     case $libobj in
     *.ada) xform=ada ;;
     *.adb) xform=adb ;;
@@ -472,6 +797,7 @@
     *.asm) xform=asm ;;
     *.c++) xform=c++ ;;
     *.cc) xform=cc ;;
+    *.ii) xform=ii ;;
     *.class) xform=class ;;
     *.cpp) xform=cpp ;;
     *.cxx) xform=cxx ;;
@@ -486,62 +812,39 @@
     *.lo) obj=`$echo "X$libobj" | $Xsed -e "$lo2o"` ;;
     *)
       $echo "$modename: cannot determine name of library object from \`$libobj'" 1>&2
-      exit 1
+      exit $EXIT_FAILURE
       ;;
     esac
 
-    # Infer tagged configuration to use if any are available and
-    # if one wasn't chosen via the "--tag" command line option.
-    # Only attempt this if the compiler in the base compile
-    # command doesn't match the default compiler.
-    if test -n "$available_tags" && test -z "$tagname"; then
-      case $base_compile in
-      "$CC "*) tagname=CC ;;
-      # Blanks in the command may have been stripped by the calling shell,
-      # but not from the CC environment variable when ltconfig was run.
-      "`$echo $CC` "*) tagname=CC ;;
-      *)   base_compiler=`echo $base_compile | awk '{ print $1 }'`
-	   case $base_compiler in
-	   *cc)	tagname=CC ;;
-	   *++)
-	     tagname=CXX
-	     eval "`sed -n -e '/^### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $0`"
-	     ;;
-	   esac ;;
-      esac
-    fi
-    if test -n "$available_tags" && test -z "$tagname"; then
-        for z in $available_tags; do
-          if grep "^### BEGIN LIBTOOL TAG CONFIG: $z$" < "$0" > /dev/null; then
-	    # Evaluate the configuration.
-	    eval "`sed -n -e '/^### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^### END LIBTOOL TAG CONFIG: '$z'$/p' < $0`"
-            case $base_compile in
-	    "$CC "*)
-              # The compiler in the base compile command matches
-              # the one in the tagged configuration.
-              # Assume this is the tagged configuration we want.
-              tagname=$z
-              break
-              ;;
-	    "`$echo $CC` "*)
-	      tagname=$z
-	      break
-	      ;;
-	    esac
-          fi
-        done
-        # If $tagname still isn't set, then no tagged configuration
-        # was found and let the user know that the "--tag" command
-        # line option must be used.
-        if test -z "$tagname"; then
-          echo "$modename: unable to infer tagged configuration"
-          echo "$modename: specify a tag with \`--tag'" 1>&2
-	  exit 1
-#        else
-#          echo "$modename: using $tagname tagged configuration"
-        fi
-    fi
+    func_infer_tag $base_compile
 
+    for arg in $later; do
+      case $arg in
+      -static)
+	build_old_libs=yes
+	continue
+	;;
+
+      -prefer-pic)
+	pic_mode=yes
+	continue
+	;;
+
+      -prefer-non-pic)
+	pic_mode=no
+	continue
+	;;
+      esac
+    done
+
+    qlibobj=`$echo "X$libobj" | $Xsed -e "$sed_quote_subst"`
+    case $qlibobj in
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+	qlibobj="\"$qlibobj\"" ;;
+    esac
+    test "X$libobj" != "X$qlibobj" \
+	&& $echo "X$libobj" | grep '[]~#^*{};<>?"'"'"' 	&()|`$[]' \
+	&& $echo "$modename: libobj name \`$libobj' may not contain shell special characters."
     objname=`$echo "X$obj" | $Xsed -e 's%^.*/%%'`
     xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'`
     if test "X$xdir" = "X$obj"; then
@@ -554,7 +857,7 @@
     if test -z "$base_compile"; then
       $echo "$modename: you must specify a compilation command" 1>&2
       $echo "$help" 1>&2
-      exit 1
+      exit $EXIT_FAILURE
     fi
 
     # Delete any leftover library objects.
@@ -565,7 +868,7 @@
     fi
 
     $run $rm $removelist
-    trap "$run $rm $removelist; exit 1" 1 2 15
+    trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15
 
     # On Cygwin there's no "real" PIC flag so we must build both object types
     case $host_os in
@@ -573,7 +876,7 @@
       pic_mode=default
       ;;
     esac
-    if test $pic_mode = no && test "$deplibs_check_method" != pass_all; then
+    if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then
       # non-PIC code in shared libraries is not supported
       pic_mode=default
     fi
@@ -584,7 +887,7 @@
       output_obj=`$echo "X$srcfile" | $Xsed -e 's%^.*/%%' -e 's%\.[^.]*$%%'`.${objext}
       lockfile="$output_obj.lock"
       removelist="$removelist $output_obj $lockfile"
-      trap "$run $rm $removelist; exit 1" 1 2 15
+      trap "$run $rm $removelist; exit $EXIT_FAILURE" 1 2 15
     else
       output_obj=
       need_locks=no
@@ -594,13 +897,13 @@
     # Lock this critical section if it is needed
     # We use this script file to make the link, it avoids creating a new file
     if test "$need_locks" = yes; then
-      until $run ln "$0" "$lockfile" 2>/dev/null; do
+      until $run ln "$progpath" "$lockfile" 2>/dev/null; do
 	$show "Waiting for $lockfile to be removed"
 	sleep 2
       done
     elif test "$need_locks" = warn; then
       if test -f "$lockfile"; then
-	echo "\
+	$echo "\
 *** ERROR, $lockfile exists and contains:
 `cat $lockfile 2>/dev/null`
 
@@ -612,14 +915,19 @@
 compiler."
 
 	$run $rm $removelist
-	exit 1
+	exit $EXIT_FAILURE
       fi
-      echo $srcfile > "$lockfile"
+      $echo "$srcfile" > "$lockfile"
     fi
 
     if test -n "$fix_srcfile_path"; then
       eval srcfile=\"$fix_srcfile_path\"
     fi
+    qsrcfile=`$echo "X$srcfile" | $Xsed -e "$sed_quote_subst"`
+    case $qsrcfile in
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+      qsrcfile="\"$qsrcfile\"" ;;
+    esac
 
     $run $rm "$libobj" "${libobj}T"
 
@@ -641,24 +949,24 @@
       fbsd_hideous_sh_bug=$base_compile
 
       if test "$pic_mode" != no; then
-	command="$base_compile $srcfile $pic_flag"
+	command="$base_compile $qsrcfile $pic_flag"
       else
 	# Don't build PIC code
-	command="$base_compile $srcfile"
+	command="$base_compile $qsrcfile"
       fi
 
-      if test ! -d ${xdir}$objdir; then
+      if test ! -d "${xdir}$objdir"; then
 	$show "$mkdir ${xdir}$objdir"
 	$run $mkdir ${xdir}$objdir
-	status=$?
-	if test $status -ne 0 && test ! -d ${xdir}$objdir; then
-	  exit $status
-        fi
-      fi 
+	exit_status=$?
+	if test "$exit_status" -ne 0 && test ! -d "${xdir}$objdir"; then
+	  exit $exit_status
+	fi
+      fi
 
       if test -z "$output_obj"; then
-        # Place PIC objects in $objdir
-        command="$command -o $lobj"
+	# Place PIC objects in $objdir
+	command="$command -o $lobj"
       fi
 
       $run $rm "$lobj" "$output_obj"
@@ -667,12 +975,12 @@
       if $run eval "$command"; then :
       else
 	test -n "$output_obj" && $run $rm $removelist
-	exit 1
+	exit $EXIT_FAILURE
       fi
 
       if test "$need_locks" = warn &&
-	 test x"`cat $lockfile 2>/dev/null`" != x"$srcfile"; then
-	echo "\
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$echo "\
 *** ERROR, $lockfile contains:
 `cat $lockfile 2>/dev/null`
 
@@ -687,11 +995,11 @@
 compiler."
 
 	$run $rm $removelist
-	exit 1
+	exit $EXIT_FAILURE
       fi
 
       # Just move the object if needed, then go on to compile the next one
-      if test -n "$output_obj" && test "x$output_obj" != "x$lobj"; then
+      if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then
 	$show "$mv $output_obj $lobj"
 	if $run $mv $output_obj $lobj; then :
 	else
@@ -708,7 +1016,9 @@
 EOF
 
       # Allow error messages only from the first compilation.
-      suppress_output=' >/dev/null 2>&1'
+      if test "$suppress_opt" = yes; then
+        suppress_output=' >/dev/null 2>&1'
+      fi
     else
       # No PIC object so indicate it doesn't exist in the libtool
       # object file.
@@ -722,9 +1032,9 @@
     if test "$build_old_libs" = yes; then
       if test "$pic_mode" != yes; then
 	# Don't build PIC code
-	command="$base_compile $srcfile"
+	command="$base_compile $qsrcfile"
       else
-	command="$base_compile $srcfile $pic_flag"
+	command="$base_compile $qsrcfile $pic_flag"
       fi
       if test "$compiler_c_o" = yes; then
 	command="$command -o $obj"
@@ -737,12 +1047,12 @@
       if $run eval "$command"; then :
       else
 	$run $rm $removelist
-	exit 1
+	exit $EXIT_FAILURE
       fi
 
       if test "$need_locks" = warn &&
-	 test x"`cat $lockfile 2>/dev/null`" != x"$srcfile"; then
-	echo "\
+	 test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then
+	$echo "\
 *** ERROR, $lockfile contains:
 `cat $lockfile 2>/dev/null`
 
@@ -757,11 +1067,11 @@
 compiler."
 
 	$run $rm $removelist
-	exit 1
+	exit $EXIT_FAILURE
       fi
 
       # Just move the object if needed
-      if test -n "$output_obj" && test "x$output_obj" != "x$obj"; then
+      if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then
 	$show "$mv $output_obj $obj"
 	if $run $mv $output_obj $obj; then :
 	else
@@ -795,7 +1105,7 @@
       $run $rm "$lockfile"
     fi
 
-    exit 0
+    exit $EXIT_SUCCESS
     ;;
 
   # libtool link mode
@@ -806,7 +1116,7 @@
       # It is impossible to link a dll without this setting, and
       # we shouldn't force the makefile maintainer to figure out
       # which system we are compiling for in order to pass an extra
-      # flag for every libtool invokation.
+      # flag for every libtool invocation.
       # allow_undefined=no
 
       # FIXME: Unfortunately, there are problems with the above when trying
@@ -821,7 +1131,7 @@
       ;;
     esac
     libtool_args="$nonopt"
-    base_compile="$nonopt"
+    base_compile="$nonopt $@"
     compile_command="$nonopt"
     finalize_command="$nonopt"
 
@@ -837,6 +1147,7 @@
     linker_flags=
     dllsearchpath=
     lib_search_path=`pwd`
+    inst_prefix_dir=
 
     avoid_version=no
     dlfiles=
@@ -852,6 +1163,8 @@
     no_install=no
     objs=
     non_pic_objects=
+    notinst_path= # paths that contain not-installed libtool libraries
+    precious_files_regex=
     prefer_static_libs=no
     preload=no
     prev=
@@ -863,6 +1176,9 @@
     temp_rpath=
     thread_safe=no
     vinfo=
+    vinfo_number=no
+
+    func_infer_tag $base_compile
 
     # We need to know -static, to get the right output filenames.
     for arg
@@ -876,14 +1192,15 @@
 	  if test -n "$link_static_flag"; then
 	    dlopen_self=$dlopen_self_static
 	  fi
+	  prefer_static_libs=yes
 	else
 	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
 	    dlopen_self=$dlopen_self_static
 	  fi
+	  prefer_static_libs=built
 	fi
 	build_libtool_libs=no
 	build_old_libs=yes
-	prefer_static_libs=yes
 	break
 	;;
       esac
@@ -893,9 +1210,8 @@
     test -n "$old_archive_from_new_cmds" && build_old_libs=yes
 
     # Go through the arguments, transforming them on the way.
-    while test $# -gt 0; do
+    while test "$#" -gt 0; do
       arg="$1"
-      base_compile="$base_compile $arg"
       shift
       case $arg in
       *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
@@ -959,7 +1275,7 @@
 	  export_symbols="$arg"
 	  if test ! -f "$arg"; then
 	    $echo "$modename: symbol file \`$arg' does not exist"
-	    exit 1
+	    exit $EXIT_FAILURE
 	  fi
 	  prev=
 	  continue
@@ -969,6 +1285,16 @@
 	  prev=
 	  continue
 	  ;;
+	inst_prefix)
+	  inst_prefix_dir="$arg"
+	  prev=
+	  continue
+	  ;;
+	precious_regex)
+	  precious_files_regex="$arg"
+	  prev=
+	  continue
+	  ;;
 	release)
 	  release="-$arg"
 	  prev=
@@ -976,108 +1302,113 @@
 	  ;;
 	objectlist)
 	  if test -f "$arg"; then
-            save_arg=$arg
+	    save_arg=$arg
 	    moreargs=
 	    for fil in `cat $save_arg`
 	    do
 #	      moreargs="$moreargs $fil"
-              arg=$fil
-              # A libtool-controlled object.
+	      arg=$fil
+	      # A libtool-controlled object.
 
 	      # Check to see that this really is a libtool object.
-	      if (sed -e '2q' $arg | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
-                pic_object=
-                non_pic_object=
+	      if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
+		pic_object=
+		non_pic_object=
 
-                # Read the .lo file
-                # If there is no directory component, then add one.
-                case $arg in
-                */* | *\\*) . $arg ;;
-                *) . ./$arg ;;
-                esac
+		# Read the .lo file
+		# If there is no directory component, then add one.
+		case $arg in
+		*/* | *\\*) . $arg ;;
+		*) . ./$arg ;;
+		esac
 
-                if test -z "$pic_object" || \
-                   test -z "$non_pic_object" ||
-                   test "$pic_object" = none && \
-                   test "$non_pic_object" = none; then
-                  $echo "$modename: cannot find name of object for \`$arg'" 1>&2
-                  exit 1
-                fi
+		if test -z "$pic_object" || \
+		   test -z "$non_pic_object" ||
+		   test "$pic_object" = none && \
+		   test "$non_pic_object" = none; then
+		  $echo "$modename: cannot find name of object for \`$arg'" 1>&2
+		  exit $EXIT_FAILURE
+		fi
 
-	        # Extract subdirectory from the argument.
-	        xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
-	        if test "X$xdir" = "X$arg"; then
-	          xdir=
-	        else
-	          xdir="$xdir/"
-	        fi
+		# Extract subdirectory from the argument.
+		xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
+		if test "X$xdir" = "X$arg"; then
+		  xdir=
+		else
+		  xdir="$xdir/"
+		fi
 
-                if test "$pic_object" != none; then
-                  # Prepend the subdirectory the object is found in.
-	          pic_object="$xdir$pic_object"
+		if test "$pic_object" != none; then
+		  # Prepend the subdirectory the object is found in.
+		  pic_object="$xdir$pic_object"
 
-	          if test "$prev" = dlfiles; then
-	            if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
-	              dlfiles="$dlfiles $pic_object"
-	              prev=
-	              continue
-	            else
-	              # If libtool objects are unsupported, then we need to preload.
-	              prev=dlprefiles
-	            fi
-	          fi
+		  if test "$prev" = dlfiles; then
+		    if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
+		      dlfiles="$dlfiles $pic_object"
+		      prev=
+		      continue
+		    else
+		      # If libtool objects are unsupported, then we need to preload.
+		      prev=dlprefiles
+		    fi
+		  fi
 
-	          # CHECK ME:  I think I busted this.  -Ossama
-                  if test "$prev" = dlprefiles; then
-	            # Preload the old-style object.
-	            dlprefiles="$dlprefiles $pic_object"
-	            prev=
-                  fi
+		  # CHECK ME:  I think I busted this.  -Ossama
+		  if test "$prev" = dlprefiles; then
+		    # Preload the old-style object.
+		    dlprefiles="$dlprefiles $pic_object"
+		    prev=
+		  fi
 
-                  # A PIC object.
-	          libobjs="$libobjs $pic_object"
-	          arg="$pic_object"
-                fi
+		  # A PIC object.
+		  libobjs="$libobjs $pic_object"
+		  arg="$pic_object"
+		fi
 
-                # Non-PIC object.
-                if test "$non_pic_object" != none; then
-                  # Prepend the subdirectory the object is found in.
-	          non_pic_object="$xdir$non_pic_object"
+		# Non-PIC object.
+		if test "$non_pic_object" != none; then
+		  # Prepend the subdirectory the object is found in.
+		  non_pic_object="$xdir$non_pic_object"
 
-                  # A standard non-PIC object
-                  non_pic_objects="$non_pic_objects $non_pic_object"
-                  if test -z "$pic_object" || test "$pic_object" = none ; then
-                    arg="$non_pic_object"
-                  fi
-                fi
-              else
-                # Only an error if not doing a dry-run.
-                if test -z "$run"; then
-                  $echo "$modename: \`$arg' is not a valid libtool object" 1>&2
-                  exit 1
-                else
-                  # Dry-run case.
+		  # A standard non-PIC object
+		  non_pic_objects="$non_pic_objects $non_pic_object"
+		  if test -z "$pic_object" || test "$pic_object" = none ; then
+		    arg="$non_pic_object"
+		  fi
+		else
+		  # If the PIC object exists, use it instead.
+		  # $xdir was prepended to $pic_object above.
+		  non_pic_object="$pic_object"
+		  non_pic_objects="$non_pic_objects $non_pic_object"
+		fi
+	      else
+		# Only an error if not doing a dry-run.
+		if test -z "$run"; then
+		  $echo "$modename: \`$arg' is not a valid libtool object" 1>&2
+		  exit $EXIT_FAILURE
+		else
+		  # Dry-run case.
 
-	          # Extract subdirectory from the argument.
-	          xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
-	          if test "X$xdir" = "X$arg"; then
-	            xdir=
-	          else
-	            xdir="$xdir/"
-	          fi
+		  # Extract subdirectory from the argument.
+		  xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
+		  if test "X$xdir" = "X$arg"; then
+		    xdir=
+		  else
+		    xdir="$xdir/"
+		  fi
 
-                  pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"`
-                  non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"`
-	          libobjs="$libobjs $pic_object"
-                  non_pic_objects="$non_pic_objects $non_pic_object"
-                fi
+		  pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"`
+		  non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"`
+		  libobjs="$libobjs $pic_object"
+		  non_pic_objects="$non_pic_objects $non_pic_object"
+		fi
 	      fi
 	    done
 	  else
 	    $echo "$modename: link input file \`$save_arg' does not exist"
-	    exit 1
+	    exit $EXIT_FAILURE
 	  fi
-          arg=$save_arg
+	  arg=$save_arg
 	  prev=
 	  continue
 	  ;;
@@ -1087,9 +1418,16 @@
 	  [\\/]* | [A-Za-z]:[\\/]*) ;;
 	  *)
 	    $echo "$modename: only absolute run-paths are allowed" 1>&2
-	    exit 1
+	    exit $EXIT_FAILURE
 	    ;;
 	  esac
+	  # Canonicalise the pathname
+	  tmp=""
+	  while test "$arg" != "$tmp"
+          do
+            tmp=$arg
+            arg=`$echo "X$arg" | $Xsed -e 's%[^/.][^/.]*/\.\.%%g' -e 's%/\./%/%g' -e 's%//*%/%g' -e 's%/$%%g'`
+          done
 	  if test "$prev" = rpath; then
 	    case "$rpath " in
 	    *" $arg "*) ;;
@@ -1119,13 +1457,33 @@
 	  finalize_command="$finalize_command $wl$qarg"
 	  continue
 	  ;;
+	xcclinker)
+	  linker_flags="$linker_flags $qarg"
+	  compiler_flags="$compiler_flags $qarg"
+	  prev=
+	  compile_command="$compile_command $qarg"
+	  finalize_command="$finalize_command $qarg"
+	  continue
+	  ;;
+	shrext)
+  	  shrext_cmds="$arg"
+	  prev=
+	  continue
+	  ;;
+	darwin_framework|darwin_framework_skip)
+	  test "$prev" = "darwin_framework" && compiler_flags="$compiler_flags $arg"
+	  compile_command="$compile_command $arg"
+	  finalize_command="$finalize_command $arg"
+	  prev=
+	  continue
+	  ;;
 	*)
 	  eval "$prev=\"\$arg\""
 	  prev=
 	  continue
 	  ;;
 	esac
-      fi # test -n $prev
+      fi # test -n "$prev"
 
       prevarg="$arg"
 
@@ -1167,7 +1525,7 @@
       -export-symbols | -export-symbols-regex)
 	if test -n "$export_symbols" || test -n "$export_symbols_regex"; then
 	  $echo "$modename: more than one -exported-symbols argument is not allowed"
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 	if test "X$arg" = "X-export-symbols"; then
 	  prev=expsyms
@@ -1177,11 +1535,28 @@
 	continue
 	;;
 
+      -framework|-arch|-isysroot)
+	case " $CC " in
+	  *" ${arg} ${1} "* | *" ${arg}	${1} "*) 
+		prev=darwin_framework_skip ;;
+	  *) compiler_flags="$compiler_flags $arg"
+	     prev=darwin_framework ;;
+	esac
+	compile_command="$compile_command $arg"
+	finalize_command="$finalize_command $arg"
+	continue
+	;;
+
+      -inst-prefix-dir)
+	prev=inst_prefix
+	continue
+	;;
+
       # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*
       # so, if we see these flags be careful not to treat them like -L
       -L[A-Z][A-Z]*:*)
 	case $with_gcc/$host in
-	no/*-*-irix*)
+	no/*-*-irix* | /*-*-irix*)
 	  compile_command="$compile_command $arg"
 	  finalize_command="$finalize_command $arg"
 	  ;;
@@ -1198,7 +1573,8 @@
 	  absdir=`cd "$dir" && pwd`
 	  if test -z "$absdir"; then
 	    $echo "$modename: cannot determine absolute directory name of \`$dir'" 1>&2
-	    exit 1
+	    absdir="$dir"
+	    notinst_path="$notinst_path $dir"
 	  fi
 	  dir="$absdir"
 	  ;;
@@ -1212,10 +1588,15 @@
 	esac
 	case $host in
 	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
+	  testbindir=`$echo "X$dir" | $Xsed -e 's*/lib$*/bin*'`
 	  case :$dllsearchpath: in
 	  *":$dir:"*) ;;
 	  *) dllsearchpath="$dllsearchpath:$dir";;
 	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  *) dllsearchpath="$dllsearchpath:$testbindir";;
+	  esac
 	  ;;
 	esac
 	continue
@@ -1224,25 +1605,104 @@
       -l*)
 	if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then
 	  case $host in
-	  *-*-cygwin* | *-*-pw32* | *-*-beos*)
+	  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos*)
 	    # These systems don't actually have a C or math library (as such)
 	    continue
 	    ;;
-	  *-*-mingw* | *-*-os2*)
+	  *-*-os2*)
 	    # These systems don't actually have a C library (as such)
 	    test "X$arg" = "X-lc" && continue
 	    ;;
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	    # Do not include libc due to us having libc/libc_r.
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-rhapsody* | *-*-darwin1.[012])
+	    # Rhapsody C and math libraries are in the System framework
+	    deplibs="$deplibs -framework System"
+	    continue
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    test "X$arg" = "X-lc" && continue
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    test "X$arg" = "X-lc" && continue
+	    ;;
 	  esac
+	elif test "X$arg" = "X-lc_r"; then
+	 case $host in
+	 *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	   # Do not include libc_r directly, use -pthread flag.
+	   continue
+	   ;;
+	 esac
 	fi
 	deplibs="$deplibs $arg"
 	continue
 	;;
 
+      # Tru64 UNIX uses -model [arg] to determine the layout of C++
+      # classes, name mangling, and exception handling.
+      -model)
+	compile_command="$compile_command $arg"
+	compiler_flags="$compiler_flags $arg"
+	finalize_command="$finalize_command $arg"
+	prev=xcompiler
+	continue
+	;;
+
+     -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe)
+	compiler_flags="$compiler_flags $arg"
+	compile_command="$compile_command $arg"
+	finalize_command="$finalize_command $arg"
+	case $host:$arg in
+	*-*-dragonfly*:-pthread)
+	  # pkgsrc hack to use -pthread in .la file for final linking
+	  deplibs="$deplibs $arg"
+	  ;;
+	esac
+	continue
+	;;
+
       -module)
 	module=yes
 	continue
 	;;
 
+      # -64, -mips[0-9] enable 64-bit mode on the SGI compiler
+      # -r[0-9][0-9]* specifies the processor on the SGI compiler
+      # -xarch=*, -xtarget=* enable 64-bit mode on the Sun compiler
+      # +DA*, +DD* enable 64-bit mode on the HP compiler
+      # -q* pass through compiler args for the IBM compiler
+      # -m* pass through architecture-specific compiler args for GCC
+      # -m*, -t[45]*, -txscale* pass through architecture-specific
+      # compiler args for GCC
+      # -pg pass through profiling flag for GCC
+      # @file GCC response files
+      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*|-pg| \
+      -t[45]*|-txscale*|@*)
+
+	# Unknown arguments in both finalize_command and compile_command need
+	# to be aesthetically quoted because they are evaled later.
+	arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
+	case $arg in
+	*[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
+	  arg="\"$arg\""
+	  ;;
+	esac
+        compile_command="$compile_command $arg"
+        finalize_command="$finalize_command $arg"
+        compiler_flags="$compiler_flags $arg"
+        continue
+        ;;
+
+      -shrext)
+	prev=shrext
+	continue
+	;;
+
       -no-fast-install)
 	fast_install=no
 	continue
@@ -1274,6 +1734,11 @@
 
       -o) prev=output ;;
 
+      -precious-files-regex)
+	prev=precious_regex
+	continue
+	;;
+
       -release)
 	prev=release
 	continue
@@ -1296,7 +1761,7 @@
 	[\\/]* | [A-Za-z]:[\\/]*) ;;
 	*)
 	  $echo "$modename: only absolute run-paths are allowed" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	  ;;
 	esac
 	case "$xrpath " in
@@ -1324,11 +1789,16 @@
 	prev=vinfo
 	continue
 	;;
+      -version-number)
+	prev=vinfo
+	vinfo_number=yes
+	continue
+	;;
 
       -Wc,*)
 	args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wc,//'`
 	arg=
-	IFS="${IFS= 	}"; save_ifs="$IFS"; IFS=','
+	save_ifs="$IFS"; IFS=','
 	for flag in $args; do
 	  IFS="$save_ifs"
 	  case $flag in
@@ -1346,7 +1816,7 @@
       -Wl,*)
 	args=`$echo "X$arg" | $Xsed -e "$sed_quote_subst" -e 's/^-Wl,//'`
 	arg=
-	IFS="${IFS= 	}"; save_ifs="$IFS"; IFS=','
+	save_ifs="$IFS"; IFS=','
 	for flag in $args; do
 	  IFS="$save_ifs"
 	  case $flag in
@@ -1372,6 +1842,11 @@
 	continue
 	;;
 
+      -XCClinker)
+	prev=xcclinker
+	continue
+	;;
+
       # Some other compiler flag.
       -* | +*)
 	# Unknown arguments in both finalize_command and compile_command need
@@ -1393,78 +1868,83 @@
 	# A libtool-controlled object.
 
 	# Check to see that this really is a libtool object.
-	if (sed -e '2q' $arg | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
-          pic_object=
-          non_pic_object=
+	if (${SED} -e '2q' $arg | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
+	  pic_object=
+	  non_pic_object=
 
-          # Read the .lo file
-          # If there is no directory component, then add one.
-          case $arg in
-          */* | *\\*) . $arg ;;
-          *) . ./$arg ;;
-          esac
+	  # Read the .lo file
+	  # If there is no directory component, then add one.
+	  case $arg in
+	  */* | *\\*) . $arg ;;
+	  *) . ./$arg ;;
+	  esac
 
-          if test -z "$pic_object" || \
-             test -z "$non_pic_object" ||
-             test "$pic_object" = none && \
-             test "$non_pic_object" = none; then
-            $echo "$modename: cannot find name of object for \`$arg'" 1>&2
-            exit 1
-          fi
+	  if test -z "$pic_object" || \
+	     test -z "$non_pic_object" ||
+	     test "$pic_object" = none && \
+	     test "$non_pic_object" = none; then
+	    $echo "$modename: cannot find name of object for \`$arg'" 1>&2
+	    exit $EXIT_FAILURE
+	  fi
 
 	  # Extract subdirectory from the argument.
 	  xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
 	  if test "X$xdir" = "X$arg"; then
 	    xdir=
-	  else
+ 	  else
 	    xdir="$xdir/"
 	  fi
 
-          if test "$pic_object" != none; then
-            # Prepend the subdirectory the object is found in.
+	  if test "$pic_object" != none; then
+	    # Prepend the subdirectory the object is found in.
 	    pic_object="$xdir$pic_object"
 
 	    if test "$prev" = dlfiles; then
 	      if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then
-	        dlfiles="$dlfiles $pic_object"
-	        prev=
-	        continue
+		dlfiles="$dlfiles $pic_object"
+		prev=
+		continue
 	      else
-	        # If libtool objects are unsupported, then we need to preload.
-	        prev=dlprefiles
+		# If libtool objects are unsupported, then we need to preload.
+		prev=dlprefiles
 	      fi
 	    fi
 
 	    # CHECK ME:  I think I busted this.  -Ossama
-            if test "$prev" = dlprefiles; then
+	    if test "$prev" = dlprefiles; then
 	      # Preload the old-style object.
 	      dlprefiles="$dlprefiles $pic_object"
 	      prev=
-            fi
+	    fi
 
-            # A PIC object.
+	    # A PIC object.
 	    libobjs="$libobjs $pic_object"
 	    arg="$pic_object"
-          fi
+	  fi
 
-          # Non-PIC object.
-          if test "$non_pic_object" != none; then
-            # Prepend the subdirectory the object is found in.
+	  # Non-PIC object.
+	  if test "$non_pic_object" != none; then
+	    # Prepend the subdirectory the object is found in.
 	    non_pic_object="$xdir$non_pic_object"
 
-            # A standard non-PIC object
-            non_pic_objects="$non_pic_objects $non_pic_object"
-            if test -z "$pic_object" || test "$pic_object" = none ; then
-              arg="$non_pic_object"
-            fi
-          fi
-        else
-          # Only an error if not doing a dry-run.
-          if test -z "$run"; then
-            $echo "$modename: \`$arg' is not a valid libtool object" 1>&2
-            exit 1
-          else
-            # Dry-run case.
+	    # A standard non-PIC object
+	    non_pic_objects="$non_pic_objects $non_pic_object"
+	    if test -z "$pic_object" || test "$pic_object" = none ; then
+	      arg="$non_pic_object"
+	    fi
+	  else
+	    # If the PIC object exists, use it instead.
+	    # $xdir was prepended to $pic_object above.
+	    non_pic_object="$pic_object"
+	    non_pic_objects="$non_pic_objects $non_pic_object"
+	  fi
+	else
+	  # Only an error if not doing a dry-run.
+	  if test -z "$run"; then
+	    $echo "$modename: \`$arg' is not a valid libtool object" 1>&2
+	    exit $EXIT_FAILURE
+	  else
+	    # Dry-run case.
 
 	    # Extract subdirectory from the argument.
 	    xdir=`$echo "X$arg" | $Xsed -e 's%/[^/]*$%%'`
@@ -1474,11 +1954,11 @@
 	      xdir="$xdir/"
 	    fi
 
-            pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"`
-            non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"`
+	    pic_object=`$echo "X${xdir}${objdir}/${arg}" | $Xsed -e "$lo2o"`
+	    non_pic_object=`$echo "X${xdir}${arg}" | $Xsed -e "$lo2o"`
 	    libobjs="$libobjs $pic_object"
-            non_pic_objects="$non_pic_objects $non_pic_object"
-          fi
+	    non_pic_objects="$non_pic_objects $non_pic_object"
+	  fi
 	fi
 	;;
 
@@ -1529,59 +2009,7 @@
     if test -n "$prev"; then
       $echo "$modename: the \`$prevarg' option requires an argument" 1>&2
       $echo "$help" 1>&2
-      exit 1
-    fi
-
-    # Infer tagged configuration to use if any are available and
-    # if one wasn't chosen via the "--tag" command line option.
-    # Only attempt this if the compiler in the base link
-    # command doesn't match the default compiler.
-    if test -n "$available_tags" && test -z "$tagname"; then
-      case $base_compile in
-      "$CC "*) tagname=CC ;;
-      # Blanks in the command may have been stripped by the calling shell,
-      # but not from the CC environment variable when ltconfig was run.
-      "`$echo $CC` "*) tagname=CC ;;
-      *)   base_compiler=`echo $base_compile | awk '{ print $1 }'`
-	   case $base_compiler in
-	   *cc)	tagname=CC ;;
-	   *++)
-	     tagname=CXX
-	     eval "`sed -n -e '/^### BEGIN LIBTOOL TAG CONFIG: '$tagname'$/,/^### END LIBTOOL TAG CONFIG: '$tagname'$/p' < $0`"
-	     ;;
-	   esac ;;
-      esac
-    fi
-    if test -n "$available_tags" && test -z "$tagname"; then
-        for z in $available_tags; do
-          if grep "^### BEGIN LIBTOOL TAG CONFIG: $z$" < "$0" > /dev/null; then
-	    # Evaluate the configuration.
-	    eval "`sed -n -e '/^### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^### END LIBTOOL TAG CONFIG: '$z'$/p' < $0`"
-            case $base_compile in
-	    "$CC "*)
-              # The compiler in $compile_command matches
-              # the one in the tagged configuration.
-              # Assume this is the tagged configuration we want.
-              tagname=$z
-              break
-	      ;;
-	    "`$echo $CC` "*)
-	      tagname=$z
-	      break
-	      ;;
-	    esac
-          fi
-        done
-        # If $tagname still isn't set, then no tagged configuration
-        # was found and let the user know that the "--tag" command
-        # line option must be used.
-        if test -z "$tagname"; then
-          echo "$modename: unable to infer tagged configuration"
-          echo "$modename: specify a tag with \`--tag'" 1>&2
-	  exit 1
-#       else
-#         echo "$modename: using $tagname tagged configuration"
-        fi
+      exit $EXIT_FAILURE
     fi
 
     if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then
@@ -1590,6 +2018,7 @@
       finalize_command="$finalize_command $arg"
     fi
 
+    oldlibs=
     # calculate the name of the file, without its directory
     outputname=`$echo "X$output" | $Xsed -e 's%^.*/%%'`
     libobjs_save="$libobjs"
@@ -1610,12 +2039,12 @@
       output_objdir="$output_objdir/$objdir"
     fi
     # Create the object directory.
-    if test ! -d $output_objdir; then
+    if test ! -d "$output_objdir"; then
       $show "$mkdir $output_objdir"
       $run $mkdir $output_objdir
-      status=$?
-      if test $status -ne 0 && test ! -d $output_objdir; then
-	exit $status
+      exit_status=$?
+      if test "$exit_status" -ne 0 && test ! -d "$output_objdir"; then
+	exit $exit_status
       fi
     fi
 
@@ -1624,7 +2053,7 @@
     "")
       $echo "$modename: you must specify an output file" 1>&2
       $echo "$help" 1>&2
-      exit 1
+      exit $EXIT_FAILURE
       ;;
     *.$libext) linkmode=oldlib ;;
     *.lo | *.$objext) linkmode=obj ;;
@@ -1632,33 +2061,43 @@
     *) linkmode=prog ;; # Anything else should be a program.
     esac
 
+    case $host in
+    *cygwin* | *mingw* | *pw32*)
+      # don't eliminate duplications in $postdeps and $predeps
+      duplicate_compiler_generated_deps=yes
+      ;;
+    *)
+      duplicate_compiler_generated_deps=$duplicate_deps
+      ;;
+    esac
     specialdeplibs=
+
     libs=
     # Find all interdependent deplibs by searching for libraries
     # that are linked more than once (e.g. -la -lb -la)
     for deplib in $deplibs; do
       if test "X$duplicate_deps" = "Xyes" ; then
-      case "$libs " in
-      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
-      esac
+	case "$libs " in
+	*" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	esac
       fi
       libs="$libs $deplib"
     done
 
-    if test $linkmode = lib; then
+    if test "$linkmode" = lib; then
       libs="$predeps $libs $compiler_lib_search_path $postdeps"
 
       # Compute libraries that are listed more than once in $predeps
       # $postdeps and mark them as special (i.e., whose duplicates are
       # not to be eliminated).
       pre_post_deps=
-      if test "X$duplicate_deps" = "Xyes" ; then
-      for pre_post_dep in $predeps $postdeps; do
-        case "$pre_post_deps " in
-	*" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;;
-	esac
-	pre_post_deps="$pre_post_deps $pre_post_dep"
-      done
+      if test "X$duplicate_compiler_generated_deps" = "Xyes" ; then
+	for pre_post_dep in $predeps $postdeps; do
+	  case "$pre_post_deps " in
+	  *" $pre_post_dep "*) specialdeplibs="$specialdeplibs $pre_post_deps" ;;
+	  esac
+	  pre_post_deps="$pre_post_deps $pre_post_dep"
+	done
       fi
       pre_post_deps=
     fi
@@ -1668,7 +2107,6 @@
     newlib_search_path=
     need_relink=no # whether we're linking any uninstalled libtool libraries
     notinst_deplibs= # not-installed libtool libraries
-    notinst_path= # paths that contain not-installed libtool libraries
     case $linkmode in
     lib)
 	passes="conv link"
@@ -1677,7 +2115,7 @@
 	  *.la) ;;
 	  *)
 	    $echo "$modename: libraries can \`-dlopen' only libtool libraries: $file" 1>&2
-	    exit 1
+	    exit $EXIT_FAILURE
 	    ;;
 	  esac
 	done
@@ -1694,39 +2132,79 @@
 	;;
     esac
     for pass in $passes; do
-      if test $linkmode = prog; then
-	# Determine which files to process
+      if test "$linkmode,$pass" = "lib,link" ||
+	 test "$linkmode,$pass" = "prog,scan"; then
+	libs="$deplibs"
+	deplibs=
+      fi
+      if test "$linkmode" = prog; then
 	case $pass in
-	dlopen)
-	  libs="$dlfiles"
-	  save_deplibs="$deplibs" # Collect dlpreopened libraries
-	  deplibs=
-	  ;;
+	dlopen) libs="$dlfiles" ;;
 	dlpreopen) libs="$dlprefiles" ;;
 	link) libs="$deplibs %DEPLIBS% $dependency_libs" ;;
 	esac
       fi
+      if test "$pass" = dlopen; then
+	# Collect dlpreopened libraries
+	save_deplibs="$deplibs"
+	deplibs=
+      fi
       for deplib in $libs; do
 	lib=
 	found=no
 	case $deplib in
-	-l*)
-	  if test $linkmode = oldlib && test $linkmode = obj; then
-	    $echo "$modename: warning: \`-l' is ignored for archives/objects: $deplib" 1>&2
-	    continue
+	-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe)
+	  if test "$linkmode,$pass" = "prog,link"; then
+	    compile_deplibs="$deplib $compile_deplibs"
+	    finalize_deplibs="$deplib $finalize_deplibs"
+	  else
+	    compiler_flags="$compiler_flags $deplib"
 	  fi
-	  if test $pass = conv; then
-	    deplibs="$deplib $deplibs"
+	  case $host:$deplib in
+	  *-*-dragonfly*:-pthread)
+	    # pkgsrc hack to use -pthread in .la file for final linking
+	    case $linkmode in
+	    lib)
+	      deplibs="$deplib $deplibs"
+	      test "$pass" = conv && continue
+	      newdependency_libs="$deplib $newdependency_libs"
+	      ;;
+	    prog)
+	      if test "$pass" = conv; then
+		deplibs="$deplib $deplibs"
+		continue
+	      fi
+	      if test "$pass" = scan; then
+		deplibs="$deplib $deplibs"
+	      else
+		compile_deplibs="$deplib $compile_deplibs"
+		finalize_deplibs="$deplib $finalize_deplibs"
+	      fi
+	      ;;
+	    esac
+	    ;;
+	  esac
+	  continue
+	  ;;
+	-l*)
+	  if test "$linkmode" != lib && test "$linkmode" != prog; then
+	    $echo "$modename: warning: \`-l' is ignored for archives/objects" 1>&2
 	    continue
 	  fi
 	  name=`$echo "X$deplib" | $Xsed -e 's/^-l//'`
 	  for searchdir in $newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path; do
-	    # Search the libtool library
-	    lib="$searchdir/lib${name}.la"
-	    if test -f "$lib"; then
-	      found=yes
-	      break
-	    fi
+	    for search_ext in .la $std_shrext .so .a; do
+	      # Search the libtool library
+	      lib="$searchdir/lib${name}${search_ext}"
+	      if test -f "$lib"; then
+		if test "$search_ext" = ".la"; then
+		  found=yes
+		else
+		  found=no
+		fi
+		break 2
+	      fi
+	    done
 	  done
 	  if test "$found" != yes; then
 	    # deplib doesn't seem to be a libtool library
@@ -1735,40 +2213,76 @@
 	      finalize_deplibs="$deplib $finalize_deplibs"
 	    else
 	      deplibs="$deplib $deplibs"
-	      test $linkmode = lib && newdependency_libs="$deplib $newdependency_libs"
+	      test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
 	    fi
 	    continue
+	  else # deplib is a libtool library
+	    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,
+	    # We need to do some special things here, and not later.
+	    if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+	      case " $predeps $postdeps " in
+	      *" $deplib "*)
+		if (${SED} -e '2q' $lib |
+                    grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
+		  library_names=
+		  old_library=
+		  case $lib in
+		  */* | *\\*) . $lib ;;
+		  *) . ./$lib ;;
+		  esac
+		  for l in $old_library $library_names; do
+		    ll="$l"
+		  done
+		  if test "X$ll" = "X$old_library" ; then # only static version available
+		    found=no
+		    ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'`
+		    test "X$ladir" = "X$lib" && ladir="."
+		    lib=$ladir/$old_library
+		    if test "$linkmode,$pass" = "prog,link"; then
+		      compile_deplibs="$deplib $compile_deplibs"
+		      finalize_deplibs="$deplib $finalize_deplibs"
+		    else
+		      deplibs="$deplib $deplibs"
+		      test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs"
+		    fi
+		    continue
+		  fi
+		fi
+	        ;;
+	      *) ;;
+	      esac
+	    fi
 	  fi
 	  ;; # -l
 	-L*)
 	  case $linkmode in
 	  lib)
 	    deplibs="$deplib $deplibs"
-	    test $pass = conv && continue
+	    test "$pass" = conv && continue
 	    newdependency_libs="$deplib $newdependency_libs"
 	    newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`
 	    ;;
 	  prog)
-	    if test $pass = conv; then
+	    if test "$pass" = conv; then
 	      deplibs="$deplib $deplibs"
 	      continue
 	    fi
-	    if test $pass = scan; then
+	    if test "$pass" = scan; then
 	      deplibs="$deplib $deplibs"
-	      newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`
 	    else
 	      compile_deplibs="$deplib $compile_deplibs"
 	      finalize_deplibs="$deplib $finalize_deplibs"
 	    fi
+	    newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`
 	    ;;
 	  *)
-	    $echo "$modename: warning: \`-L' is ignored for archives/objects: $deplib" 1>&2
+	    $echo "$modename: warning: \`-L' is ignored for archives/objects" 1>&2
 	    ;;
 	  esac # linkmode
 	  continue
 	  ;; # -L
 	-R*)
-	  if test $pass = link; then
+	  if test "$pass" = link; then
 	    dir=`$echo "X$deplib" | $Xsed -e 's/^-R//'`
 	    # Make sure the xrpath contains only unique directories.
 	    case "$xrpath " in
@@ -1781,28 +2295,45 @@
 	  ;;
 	*.la) lib="$deplib" ;;
 	*.$libext)
-	  if test $pass = conv; then
+	  if test "$pass" = conv; then
 	    deplibs="$deplib $deplibs"
 	    continue
 	  fi
 	  case $linkmode in
 	  lib)
-	    if test "$deplibs_check_method" != pass_all; then
-	      echo
-	      echo "*** Warning: This library needs some functionality provided by $deplib."
-	      echo "*** I have the capability to make that library automatically link in when"
-	      echo "*** you link to this library.  But I can only do this if you have a"
-	      echo "*** shared version of the library, which you do not appear to have."
+	    valid_a_lib=no
+	    case $deplibs_check_method in
+	      match_pattern*)
+		set dummy $deplibs_check_method
+	        match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"`
+		if eval $echo \"$deplib\" 2>/dev/null \
+		    | $SED 10q \
+		    | $EGREP "$match_pattern_regex" > /dev/null; then
+		  valid_a_lib=yes
+		fi
+		;;
+	      pass_all)
+		valid_a_lib=yes
+		;;
+            esac
+	    if test "$valid_a_lib" != yes; then
+	      $echo
+	      $echo "*** Warning: Trying to link with static lib archive $deplib."
+	      $echo "*** I have the capability to make that library automatically link in when"
+	      $echo "*** you link to this library.  But I can only do this if you have a"
+	      $echo "*** shared version of the library, which you do not appear to have"
+	      $echo "*** because the file extensions .$libext of this argument makes me believe"
+	      $echo "*** that it is just a static archive that I should not used here."
 	    else
-	      echo
-	      echo "*** Warning: Linking the shared library $output against the"
-	      echo "*** static library $deplib is not portable!"
+	      $echo
+	      $echo "*** Warning: Linking the shared library $output against the"
+	      $echo "*** static library $deplib is not portable!"
 	      deplibs="$deplib $deplibs"
 	    fi
 	    continue
 	    ;;
 	  prog)
-	    if test $pass != link; then
+	    if test "$pass" != link; then
 	      deplibs="$deplib $deplibs"
 	    else
 	      compile_deplibs="$deplib $compile_deplibs"
@@ -1813,14 +2344,18 @@
 	  esac # linkmode
 	  ;; # *.$libext
 	*.lo | *.$objext)
-	  if test $pass = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
-	    # If there is no dlopen support or we're linking statically,
-	    # we need to preload.
-	    newdlprefiles="$newdlprefiles $deplib"
-	    compile_deplibs="$deplib $compile_deplibs"
-	    finalize_deplibs="$deplib $finalize_deplibs"
-	  else
-	    newdlfiles="$newdlfiles $deplib"
+	  if test "$pass" = conv; then
+	    deplibs="$deplib $deplibs"
+	  elif test "$linkmode" = prog; then
+	    if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
+	      # If there is no dlopen support or we're linking statically,
+	      # we need to preload.
+	      newdlprefiles="$newdlprefiles $deplib"
+	      compile_deplibs="$deplib $compile_deplibs"
+	      finalize_deplibs="$deplib $finalize_deplibs"
+	    else
+	      newdlfiles="$newdlfiles $deplib"
+	    fi
 	  fi
 	  continue
 	  ;;
@@ -1829,17 +2364,17 @@
 	  continue
 	  ;;
 	esac # case $deplib
-	if test $found = yes || test -f "$lib"; then :
+	if test "$found" = yes || test -f "$lib"; then :
 	else
-	  $echo "$modename: cannot find the library \`$lib'" 1>&2
-	  exit 1
+	  $echo "$modename: cannot find the library \`$lib' or unhandled argument \`$deplib'" 1>&2
+	  exit $EXIT_FAILURE
 	fi
 
 	# Check to see that this really is a libtool archive.
-	if (sed -e '2q' $lib | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
+	if (${SED} -e '2q' $lib | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
 	else
 	  $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 
 	ladir=`$echo "X$lib" | $Xsed -e 's%/[^/]*$%%'`
@@ -1852,8 +2387,11 @@
 	library_names=
 	old_library=
 	# If the library was installed with an old release of libtool,
-	# it will not redefine variable installed.
+	# it will not redefine variables installed, or shouldnotlink
 	installed=yes
+	shouldnotlink=no
+	avoidtemprpath=
+
 
 	# Read the .la file
 	case $lib in
@@ -1863,19 +2401,18 @@
 
 	if test "$linkmode,$pass" = "lib,link" ||
 	   test "$linkmode,$pass" = "prog,scan" ||
-	   { test $linkmode = oldlib && test $linkmode = obj; }; then
-	   # Add dl[pre]opened files of deplib
+	   { test "$linkmode" != prog && test "$linkmode" != lib; }; then
 	  test -n "$dlopen" && dlfiles="$dlfiles $dlopen"
 	  test -n "$dlpreopen" && dlprefiles="$dlprefiles $dlpreopen"
 	fi
 
-	if test $pass = conv; then
+	if test "$pass" = conv; then
 	  # Only check for convenience libraries
 	  deplibs="$lib $deplibs"
 	  if test -z "$libdir"; then
 	    if test -z "$old_library"; then
 	      $echo "$modename: cannot find name of link library for \`$lib'" 1>&2
-	      exit 1
+	      exit $EXIT_FAILURE
 	    fi
 	    # It is a libtool convenience library, so add in its objects.
 	    convenience="$convenience $ladir/$objdir/$old_library"
@@ -1884,19 +2421,20 @@
 	    for deplib in $dependency_libs; do
 	      deplibs="$deplib $deplibs"
               if test "X$duplicate_deps" = "Xyes" ; then
-	      case "$tmp_libs " in
-	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
-	      esac
+	        case "$tmp_libs " in
+	        *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	        esac
               fi
 	      tmp_libs="$tmp_libs $deplib"
 	    done
-	  elif test $linkmode != prog && test $linkmode != lib; then
+	  elif test "$linkmode" != prog && test "$linkmode" != lib; then
 	    $echo "$modename: \`$lib' is not a convenience library" 1>&2
-	    exit 1
+	    exit $EXIT_FAILURE
 	  fi
 	  continue
 	fi # $pass = conv
 
+
 	# Get the name of the library we link against.
 	linklib=
 	for l in $old_library $library_names; do
@@ -1904,19 +2442,23 @@
 	done
 	if test -z "$linklib"; then
 	  $echo "$modename: cannot find name of link library for \`$lib'" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 
 	# This library was specified with -dlopen.
-	if test $pass = dlopen; then
+	if test "$pass" = dlopen; then
 	  if test -z "$libdir"; then
 	    $echo "$modename: cannot -dlopen a convenience library: \`$lib'" 1>&2
-	    exit 1
+	    exit $EXIT_FAILURE
 	  fi
-	  if test -z "$dlname" || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then
+	  if test -z "$dlname" ||
+	     test "$dlopen_support" != yes ||
+	     test "$build_libtool_libs" = no; then
 	    # If there is no dlname, no dlopen support or we're linking
-	    # statically, we need to preload.
-	    dlprefiles="$dlprefiles $lib"
+	    # statically, we need to preload.  We also need to preload any
+	    # dependent libraries so libltdl's deplib preloader doesn't
+	    # bomb out in the load deplibs phase.
+	    dlprefiles="$dlprefiles $lib $dependency_libs"
 	  else
 	    newdlfiles="$newdlfiles $lib"
 	  fi
@@ -1948,19 +2490,27 @@
 	    dir="$libdir"
 	    absdir="$libdir"
 	  fi
+	  test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes
 	else
-	  dir="$ladir/$objdir"
-	  absdir="$abs_ladir/$objdir"
-	  # Remove this search path later
-	  notinst_path="$notinst_path $abs_ladir"
+	  if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then
+	    dir="$ladir"
+	    absdir="$abs_ladir"
+	    # Remove this search path later
+	    notinst_path="$notinst_path $abs_ladir"
+	  else
+	    dir="$ladir/$objdir"
+	    absdir="$abs_ladir/$objdir"
+	    # Remove this search path later
+	    notinst_path="$notinst_path $abs_ladir"
+	  fi
 	fi # $installed = yes
 	name=`$echo "X$laname" | $Xsed -e 's/\.la$//' -e 's/^lib//'`
 
 	# This library was specified with -dlpreopen.
-	if test $pass = dlpreopen; then
+	if test "$pass" = dlpreopen; then
 	  if test -z "$libdir"; then
 	    $echo "$modename: cannot -dlpreopen a convenience library: \`$lib'" 1>&2
-	    exit 1
+	    exit $EXIT_FAILURE
 	  fi
 	  # Prefer using a static library (so that no silly _DYNAMIC symbols
 	  # are required to link).
@@ -1976,18 +2526,19 @@
 
 	if test -z "$libdir"; then
 	  # Link the convenience library
-	  if test $linkmode = lib; then
+	  if test "$linkmode" = lib; then
 	    deplibs="$dir/$old_library $deplibs"
 	  elif test "$linkmode,$pass" = "prog,link"; then
 	    compile_deplibs="$dir/$old_library $compile_deplibs"
 	    finalize_deplibs="$dir/$old_library $finalize_deplibs"
 	  else
-	    deplibs="$lib $deplibs"
+	    deplibs="$lib $deplibs" # used for prog,scan pass
 	  fi
 	  continue
 	fi
 
-	if test $linkmode = prog && test $pass != link; then
+
+	if test "$linkmode" = prog && test "$pass" != link; then
 	  newlib_search_path="$newlib_search_path $ladir"
 	  deplibs="$lib $deplibs"
 
@@ -2003,7 +2554,7 @@
 	    -L*) newlib_search_path="$newlib_search_path "`$echo "X$deplib" | $Xsed -e 's/^-L//'`;; ### testsuite: skip nested quoting test
 	    esac
 	    # Need to link against all dependency_libs?
-	    if test $linkalldeplibs = yes; then
+	    if test "$linkalldeplibs" = yes; then
 	      deplibs="$deplib $deplibs"
 	    else
 	      # Need to hardcode shared library paths
@@ -2011,22 +2562,28 @@
 	      newdependency_libs="$deplib $newdependency_libs"
 	    fi
 	    if test "X$duplicate_deps" = "Xyes" ; then
-	    case "$tmp_libs " in
-	    *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
-	    esac
+	      case "$tmp_libs " in
+	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	      esac
 	    fi
 	    tmp_libs="$tmp_libs $deplib"
 	  done # for deplib
 	  continue
 	fi # $linkmode = prog...
 
-	link_static=no # Whether the deplib will be linked statically
-	if test -n "$library_names" &&
-	   { test "$prefer_static_libs" = no || test -z "$old_library"; }; then
-	  # Link against this shared library
+	if test "$linkmode,$pass" = "prog,link"; then
+	  if test -n "$library_names" &&
+	     { test "$prefer_static_libs" = no || test -z "$old_library"; }; then
+	    # We need to hardcode the library path
+	    if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then
+	      # Make sure the rpath contains only unique directories.
+	      case "$temp_rpath " in
+	      *" $dir "*) ;;
+	      *" $absdir "*) ;;
+	      *) temp_rpath="$temp_rpath $absdir" ;;
+	      esac
+	    fi
 
-	  if test "$linkmode,$pass" = "prog,link" ||
-	   { test $linkmode = lib && test $hardcode_into_libs = yes; }; then
 	    # Hardcode the library path.
 	    # Skip directories that are in the system default run-time
 	    # search path.
@@ -2048,17 +2605,6 @@
 	      esac
 	      ;;
 	    esac
-	    if test $linkmode = prog; then
-	      # We need to hardcode the library path
-	      if test -n "$shlibpath_var"; then
-		# Make sure the rpath contains only unique directories.
-		case "$temp_rpath " in
-		*" $dir "*) ;;
-		*" $absdir "*) ;;
-		*) temp_rpath="$temp_rpath $dir" ;;
-		esac
-	      fi
-	    fi
 	  fi # $linkmode,$pass = prog,link...
 
 	  if test "$alldeplibs" = yes &&
@@ -2068,11 +2614,56 @@
 	    # We only need to search for static libraries
 	    continue
 	  fi
+	fi
 
+	link_static=no # Whether the deplib will be linked statically
+	use_static_libs=$prefer_static_libs
+	if test "$use_static_libs" = built && test "$installed" = yes ; then
+	  use_static_libs=no
+	fi
+	if test -n "$library_names" &&
+	   { test "$use_static_libs" = no || test -z "$old_library"; }; then
 	  if test "$installed" = no; then
 	    notinst_deplibs="$notinst_deplibs $lib"
 	    need_relink=yes
 	  fi
+	  # This is a shared library
+
+	  # Warn about portability, can't link against -module's on
+	  # some systems (darwin)
+	  if test "$shouldnotlink" = yes && test "$pass" = link ; then
+	    $echo
+	    if test "$linkmode" = prog; then
+	      $echo "*** Warning: Linking the executable $output against the loadable module"
+	    else
+	      $echo "*** Warning: Linking the shared library $output against the loadable module"
+	    fi
+	    $echo "*** $linklib is not portable!"
+	  fi
+	  if test "$linkmode" = lib &&
+	     test "$hardcode_into_libs" = yes; then
+	    # Hardcode the library path.
+	    # Skip directories that are in the system default run-time
+	    # search path.
+	    case " $sys_lib_dlsearch_path " in
+	    *" $absdir "*) ;;
+	    *)
+	      case "$compile_rpath " in
+	      *" $absdir "*) ;;
+	      *) compile_rpath="$compile_rpath $absdir"
+	      esac
+	      ;;
+	    esac
+	    case " $sys_lib_dlsearch_path " in
+	    *" $libdir "*) ;;
+	    *)
+	      case "$finalize_rpath " in
+	      *" $libdir "*) ;;
+	      *) finalize_rpath="$finalize_rpath $libdir"
+	      esac
+	      ;;
+	    esac
+	  fi
 
 	  if test -n "$old_archive_from_expsyms_cmds"; then
 	    # figure out the soname
@@ -2086,7 +2677,7 @@
 	    elif test -n "$soname_spec"; then
 	      # bleh windows
 	      case $host in
-	      *cygwin*)
+	      *cygwin* | mingw*)
 		major=`expr $current - $age`
 		versuffix="-$major"
 		;;
@@ -2098,17 +2689,18 @@
 
 	    # Make a new name for the extract_expsyms_cmds to use
 	    soroot="$soname"
-	    soname=`echo $soroot | sed -e 's/^.*\///'`
-	    newlib="libimp-`echo $soname | sed 's/^lib//;s/\.dll$//'`.a"
+	    soname=`$echo $soroot | ${SED} -e 's/^.*\///'`
+	    newlib="libimp-`$echo $soname | ${SED} 's/^lib//;s/\.dll$//'`.a"
 
 	    # If the library has no export list, then create one now
 	    if test -f "$output_objdir/$soname-def"; then :
 	    else
 	      $show "extracting exported symbol list from \`$soname'"
-	      IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
-	      eval cmds=\"$extract_expsyms_cmds\"
+	      save_ifs="$IFS"; IFS='~'
+	      cmds=$extract_expsyms_cmds
 	      for cmd in $cmds; do
 		IFS="$save_ifs"
+		eval cmd=\"$cmd\"
 		$show "$cmd"
 		$run eval "$cmd" || exit $?
 	      done
@@ -2118,10 +2710,11 @@
 	    # Create $newlib
 	    if test -f "$output_objdir/$newlib"; then :; else
 	      $show "generating import library for \`$soname'"
-	      IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
-	      eval cmds=\"$old_archive_from_expsyms_cmds\"
+	      save_ifs="$IFS"; IFS='~'
+	      cmds=$old_archive_from_expsyms_cmds
 	      for cmd in $cmds; do
 		IFS="$save_ifs"
+		eval cmd=\"$cmd\"
 		$show "$cmd"
 		$run eval "$cmd" || exit $?
 	      done
@@ -2130,9 +2723,9 @@
 	    # make sure the library variables are pointing to the new library
 	    dir=$output_objdir
 	    linklib=$newlib
-	  fi # test -n $old_archive_from_expsyms_cmds
+	  fi # test -n "$old_archive_from_expsyms_cmds"
 
-	  if test $linkmode = prog || test "$mode" != relink; then
+	  if test "$linkmode" = prog || test "$mode" != relink; then
 	    add_shlibpath=
 	    add_dir=
 	    add=
@@ -2141,6 +2734,26 @@
 	    immediate | unsupported)
 	      if test "$hardcode_direct" = no; then
 		add="$dir/$linklib"
+		case $host in
+		  *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;;
+		  *-*-sysv4*uw2*) add_dir="-L$dir" ;;
+		  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \
+		    *-*-unixware7*) add_dir="-L$dir" ;;
+		  *-*-darwin* )
+		    # if the lib is a module then we can not link against
+		    # it, someone is ignoring the new warnings I added
+		    if /usr/bin/file -L $add 2> /dev/null |
+                      $EGREP ": [^:]* bundle" >/dev/null ; then
+		      $echo "** Warning, lib $linklib is a module, not a shared library"
+		      if test -z "$old_library" ; then
+		        $echo
+		        $echo "** And there doesn't seem to be a static archive available"
+		        $echo "** The link will probably fail, sorry"
+		      else
+		        add="$dir/$old_library"
+		      fi
+		    fi
+		esac
 	      elif test "$hardcode_minus_L" = no; then
 		case $host in
 		*-*-sunos*) add_shlibpath="$dir" ;;
@@ -2159,6 +2772,14 @@
 		add="$dir/$linklib"
 	      elif test "$hardcode_minus_L" = yes; then
 		add_dir="-L$dir"
+		# Try looking first in the location we're being installed to.
+		if test -n "$inst_prefix_dir"; then
+		  case $libdir in
+		    [\\/]*)
+		      add_dir="$add_dir -L$inst_prefix_dir$libdir"
+		      ;;
+		  esac
+		fi
 		add="-l$name"
 	      elif test "$hardcode_shlibpath_var" = yes; then
 		add_shlibpath="$dir"
@@ -2172,7 +2793,7 @@
 
 	    if test "$lib_linked" != yes; then
 	      $echo "$modename: configuration error: unsupported hardcode properties"
-	      exit 1
+	      exit $EXIT_FAILURE
 	    fi
 
 	    if test -n "$add_shlibpath"; then
@@ -2181,7 +2802,7 @@
 	      *) compile_shlibpath="$compile_shlibpath$add_shlibpath:" ;;
 	      esac
 	    fi
-	    if test $linkmode = prog; then
+	    if test "$linkmode" = prog; then
 	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
 	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
 	    else
@@ -2198,7 +2819,7 @@
 	    fi
 	  fi
 
-	  if test $linkmode = prog || test "$mode" = relink; then
+	  if test "$linkmode" = prog || test "$mode" = relink; then
 	    add_shlibpath=
 	    add_dir=
 	    add=
@@ -2214,13 +2835,28 @@
 	      *) finalize_shlibpath="$finalize_shlibpath$libdir:" ;;
 	      esac
 	      add="-l$name"
+	    elif test "$hardcode_automatic" = yes; then
+	      if test -n "$inst_prefix_dir" &&
+		 test -f "$inst_prefix_dir$libdir/$linklib" ; then
+	        add="$inst_prefix_dir$libdir/$linklib"
+	      else
+	        add="$libdir/$linklib"
+	      fi
 	    else
 	      # We cannot seem to hardcode it, guess we'll fake it.
 	      add_dir="-L$libdir"
+	      # Try looking first in the location we're being installed to.
+	      if test -n "$inst_prefix_dir"; then
+		case $libdir in
+		  [\\/]*)
+		    add_dir="$add_dir -L$inst_prefix_dir$libdir"
+		    ;;
+		esac
+	      fi
 	      add="-l$name"
 	    fi
 
-	    if test $linkmode = prog; then
+	    if test "$linkmode" = prog; then
 	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
 	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
 	    else
@@ -2228,16 +2864,7 @@
 	      test -n "$add" && deplibs="$add $deplibs"
 	    fi
 	  fi
-	elif test $linkmode = prog; then
-	  if test "$alldeplibs" = yes &&
-	     { test "$deplibs_check_method" = pass_all ||
-	       { test "$build_libtool_libs" = yes &&
-		 test -n "$library_names"; }; }; then
-	    # We only need to search for static libraries
-	    continue
-	  fi
-
-	  # Try to link the static library
+	elif test "$linkmode" = prog; then
 	  # Here we assume that one of hardcode_direct or hardcode_minus_L
 	  # is not unsupported.  This is valid on all known static and
 	  # shared platforms.
@@ -2257,40 +2884,40 @@
 
 	    # Just print a warning and add the library to dependency_libs so
 	    # that the program can be linked against the static library.
-	    echo
-	    echo "*** Warning: This library needs some functionality provided by $lib."
-	    echo "*** I have the capability to make that library automatically link in when"
-	    echo "*** you link to this library.  But I can only do this if you have a"
-	    echo "*** shared version of the library, which you do not appear to have."
+	    $echo
+	    $echo "*** Warning: This system can not link to static lib archive $lib."
+	    $echo "*** I have the capability to make that library automatically link in when"
+	    $echo "*** you link to this library.  But I can only do this if you have a"
+	    $echo "*** shared version of the library, which you do not appear to have."
 	    if test "$module" = yes; then
-	      echo "*** Therefore, libtool will create a static module, that should work "
-	      echo "*** as long as the dlopening application is linked with the -dlopen flag."
+	      $echo "*** But as you try to build a module library, libtool will still create "
+	      $echo "*** a static module, that should work as long as the dlopening application"
+	      $echo "*** is linked with the -dlopen flag to resolve symbols at runtime."
 	      if test -z "$global_symbol_pipe"; then
-	        echo
-	        echo "*** However, this would only work if libtool was able to extract symbol"
-	        echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
-	        echo "*** not find such a program.  So, this module is probably useless."
-	        echo "*** \`nm' from GNU binutils and a full rebuild may help."
+		$echo
+		$echo "*** However, this would only work if libtool was able to extract symbol"
+		$echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
+		$echo "*** not find such a program.  So, this module is probably useless."
+		$echo "*** \`nm' from GNU binutils and a full rebuild may help."
 	      fi
 	      if test "$build_old_libs" = no; then
-	        build_libtool_libs=module
-	        build_old_libs=yes
+		build_libtool_libs=module
+		build_old_libs=yes
 	      else
-	        build_libtool_libs=no
+		build_libtool_libs=no
 	      fi
 	    fi
 	  else
-	    convenience="$convenience $dir/$old_library"
-	    old_convenience="$old_convenience $dir/$old_library"
 	    deplibs="$dir/$old_library $deplibs"
 	    link_static=yes
 	  fi
 	fi # link shared/static library?
 
-	if test $linkmode = lib; then
+	if test "$linkmode" = lib; then
 	  if test -n "$dependency_libs" &&
-	     { test $hardcode_into_libs != yes || test $build_old_libs = yes ||
-	       test $link_static = yes; }; then
+	     { test "$hardcode_into_libs" != yes ||
+	       test "$build_old_libs" = yes ||
+	       test "$link_static" = yes; }; then
 	    # Extract -R from dependency_libs
 	    temp_deplibs=
 	    for libdir in $dependency_libs; do
@@ -2314,14 +2941,14 @@
 	  for deplib in $dependency_libs; do
 	    newdependency_libs="$deplib $newdependency_libs"
 	    if test "X$duplicate_deps" = "Xyes" ; then
-	    case "$tmp_libs " in
-	    *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
-	    esac
+	      case "$tmp_libs " in
+	      *" $deplib "*) specialdeplibs="$specialdeplibs $deplib" ;;
+	      esac
 	    fi
 	    tmp_libs="$tmp_libs $deplib"
 	  done
 
-	  if test $link_all_deplibs != no; then
+	  if test "$link_all_deplibs" != no; then
 	    # Add the search paths of all dependency libraries
 	    for deplib in $dependency_libs; do
 	      case $deplib in
@@ -2341,18 +2968,59 @@
 		  ;;
 		esac
 		if grep "^installed=no" $deplib > /dev/null; then
-		  path="-L$absdir/$objdir"
+		  path="$absdir/$objdir"
 		else
-		  eval libdir=`sed -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+		  eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
 		  if test -z "$libdir"; then
 		    $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2
-		    exit 1
+		    exit $EXIT_FAILURE
 		  fi
 		  if test "$absdir" != "$libdir"; then
 		    $echo "$modename: warning: \`$deplib' seems to be moved" 1>&2
 		  fi
-		  path="-L$absdir"
+		  path="$absdir"
 		fi
+		depdepl=
+		case $host in
+		*-*-darwin*)
+		  # we do not want to link against static libs,
+		  # but need to link against shared
+		  eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib`
+		  if test -n "$deplibrary_names" ; then
+		    for tmp in $deplibrary_names ; do
+		      depdepl=$tmp
+		    done
+		    if test -f "$path/$depdepl" ; then
+		      depdepl="$path/$depdepl"
+		    fi
+		    # do not add paths which are already there
+		    case " $newlib_search_path " in
+		    *" $path "*) ;;
+		    *) newlib_search_path="$newlib_search_path $path";;
+		    esac
+		  fi
+		  path=""
+		  ;;
+		*)
+		  path="-L$path"
+		  ;;
+		esac
+		;;
+	      -l*)
+		case $host in
+		*-*-darwin*)
+		  # Again, we only want to link against shared libraries
+		  eval tmp_libs=`$echo "X$deplib" | $Xsed -e "s,^\-l,,"`
+		  for tmp in $newlib_search_path ; do
+		    if test -f "$tmp/lib$tmp_libs.dylib" ; then
+		      eval depdepl="$tmp/lib$tmp_libs.dylib"
+		      break
+		    fi
+		  done
+		  path=""
+		  ;;
+		*) continue ;;
+		esac
 		;;
 	      *) continue ;;
 	      esac
@@ -2360,19 +3028,23 @@
 	      *" $path "*) ;;
 	      *) deplibs="$path $deplibs" ;;
 	      esac
+	      case " $deplibs " in
+	      *" $depdepl "*) ;;
+	      *) deplibs="$depdepl $deplibs" ;;
+	      esac
 	    done
 	  fi # link_all_deplibs != no
 	fi # linkmode = lib
       done # for deplib in $libs
-      if test $pass = dlpreopen; then
+      dependency_libs="$newdependency_libs"
+      if test "$pass" = dlpreopen; then
 	# Link the dlpreopened libraries before other libraries
 	for deplib in $save_deplibs; do
 	  deplibs="$deplib $deplibs"
 	done
       fi
-      if test $pass != dlopen; then
-	test $pass != scan && dependency_libs="$newdependency_libs"
-	if test $pass != conv; then
+      if test "$pass" != dlopen; then
+	if test "$pass" != conv; then
 	  # Make sure lib_search_path contains only unique directories.
 	  lib_search_path=
 	  for dir in $newlib_search_path; do
@@ -2394,9 +3066,30 @@
 	  eval tmp_libs=\"\$$var\"
 	  new_libs=
 	  for deplib in $tmp_libs; do
+	    # FIXME: Pedantically, this is the right thing to do, so
+	    #        that some nasty dependency loop isn't accidentally
+	    #        broken:
+	    #new_libs="$deplib $new_libs"
+	    # Pragmatically, this seems to cause very few problems in
+	    # practice:
 	    case $deplib in
 	    -L*) new_libs="$deplib $new_libs" ;;
+	    -R*) ;;
 	    *)
+	      # And here is the reason: when a library appears more
+	      # than once as an explicit dependence of a library, or
+	      # is implicitly linked in more than once by the
+	      # compiler, it is considered special, and multiple
+	      # occurrences thereof are not removed.  Compare this
+	      # with having the same library being listed as a
+	      # dependency of multiple other libraries: in this case,
+	      # we know (pedantically, we assume) the library does not
+	      # need to be listed more than once, so we keep only the
+	      # last copy.  This is not always right, but it is rare
+	      # enough that we require users that really mean to play
+	      # such unportable linking tricks to link the library
+	      # using -Wl,-lname, so that libtool does not consider it
+	      # for duplicate removal.
 	      case " $specialdeplibs " in
 	      *" $deplib "*) new_libs="$deplib $new_libs" ;;
 	      *)
@@ -2424,19 +3117,32 @@
 	  eval $var=\"$tmp_libs\"
 	done # for var
       fi
-      if test "$pass" = "conv" &&
-       { test "$linkmode" = "lib" || test "$linkmode" = "prog"; }; then
-	libs="$deplibs" # reset libs
-	deplibs=
-      fi
+      # Last step: remove runtime libs from dependency_libs
+      # (they stay in deplibs)
+      tmp_libs=
+      for i in $dependency_libs ; do
+	case " $predeps $postdeps $compiler_lib_search_path " in
+	*" $i "*)
+	  i=""
+	  ;;
+	esac
+	if test -n "$i" ; then
+	  tmp_libs="$tmp_libs $i"
+	fi
+      done
+      dependency_libs=$tmp_libs
     done # for pass
-    if test $linkmode = prog; then
+    if test "$linkmode" = prog; then
       dlfiles="$newdlfiles"
       dlprefiles="$newdlprefiles"
     fi
 
     case $linkmode in
     oldlib)
+      if test -n "$deplibs"; then
+	$echo "$modename: warning: \`-l' and \`-L' are ignored for archives" 1>&2
+      fi
+
       if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
 	$echo "$modename: warning: \`-dlopen' is ignored for archives" 1>&2
       fi
@@ -2450,7 +3156,7 @@
       fi
 
       if test -n "$vinfo"; then
-	$echo "$modename: warning: \`-version-info' is ignored for archives" 1>&2
+	$echo "$modename: warning: \`-version-info/-version-number' is ignored for archives" 1>&2
       fi
 
       if test -n "$release"; then
@@ -2472,17 +3178,19 @@
       case $outputname in
       lib*)
 	name=`$echo "X$outputname" | $Xsed -e 's/\.la$//' -e 's/^lib//'`
+	eval shared_ext=\"$shrext_cmds\"
 	eval libname=\"$libname_spec\"
 	;;
       *)
 	if test "$module" = no; then
 	  $echo "$modename: libtool library \`$output' must begin with \`lib'" 1>&2
 	  $echo "$help" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 	if test "$need_lib_prefix" != no; then
 	  # Add the "lib" prefix for modules if required
 	  name=`$echo "X$outputname" | $Xsed -e 's/\.la$//'`
+	  eval shared_ext=\"$shrext_cmds\"
 	  eval libname=\"$libname_spec\"
 	else
 	  libname=`$echo "X$outputname" | $Xsed -e 's/\.la$//'`
@@ -2493,11 +3201,11 @@
       if test -n "$objs"; then
 	if test "$deplibs_check_method" != pass_all; then
 	  $echo "$modename: cannot build libtool library \`$output' from non-libtool objects on this host:$objs" 2>&1
-	  exit 1
+	  exit $EXIT_FAILURE
 	else
-	  echo
-	  echo "*** Warning: Linking the shared library $output against the non-libtool"
-	  echo "*** objects $objs is not portable!"
+	  $echo
+	  $echo "*** Warning: Linking the shared library $output against the non-libtool"
+	  $echo "*** objects $objs is not portable!"
 	  libobjs="$libobjs $objs"
 	fi
       fi
@@ -2507,7 +3215,7 @@
       fi
 
       set dummy $rpath
-      if test $# -gt 2; then
+      if test "$#" -gt 2; then
 	$echo "$modename: warning: ignoring multiple \`-rpath's for a libtool library" 1>&2
       fi
       install_libdir="$2"
@@ -2517,15 +3225,15 @@
 	if test "$build_libtool_libs" = yes; then
 	  # Building a libtool convenience library.
 	  # Some compilers have problems with a `.al' extension so
-          # convenience libraries should have the same extension an
-          # archive normally would.
+	  # convenience libraries should have the same extension an
+	  # archive normally would.
 	  oldlibs="$output_objdir/$libname.$libext $oldlibs"
 	  build_libtool_libs=convenience
 	  build_old_libs=yes
 	fi
 
 	if test -n "$vinfo"; then
-	  $echo "$modename: warning: \`-version-info' is ignored for convenience libraries" 1>&2
+	  $echo "$modename: warning: \`-version-info/-version-number' is ignored for convenience libraries" 1>&2
 	fi
 
 	if test -n "$release"; then
@@ -2534,57 +3242,95 @@
       else
 
 	# Parse the version information argument.
-	IFS="${IFS= 	}"; save_ifs="$IFS"; IFS=':'
+	save_ifs="$IFS"; IFS=':'
 	set dummy $vinfo 0 0 0
 	IFS="$save_ifs"
 
 	if test -n "$8"; then
 	  $echo "$modename: too many parameters to \`-version-info'" 1>&2
 	  $echo "$help" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 
-	current="$2"
-	revision="$3"
-	age="$4"
+	# convert absolute version numbers to libtool ages
+	# this retains compatibility with .la files and attempts
+	# to make the code below a bit more comprehensible
+
+	case $vinfo_number in
+	yes)
+	  number_major="$2"
+	  number_minor="$3"
+	  number_revision="$4"
+	  #
+	  # There are really only two kinds -- those that
+	  # use the current revision as the major version
+	  # and those that subtract age and use age as
+	  # a minor version.  But, then there is irix
+	  # which has an extra 1 added just for fun
+	  #
+	  case $version_type in
+	  darwin|linux|osf|windows)
+	    current=`expr $number_major + $number_minor`
+	    age="$number_minor"
+	    revision="$number_revision"
+	    ;;
+	  freebsd-aout|freebsd-elf|sunos)
+	    current="$number_major"
+	    revision="$number_minor"
+	    age="0"
+	    ;;
+	  irix|nonstopux)
+	    current=`expr $number_major + $number_minor - 1`
+	    age="$number_minor"
+	    revision="$number_minor"
+	    ;;
+	  esac
+	  ;;
+	no)
+	  current="$2"
+	  revision="$3"
+	  age="$4"
+	  ;;
+	esac
 
 	# Check that each of the things are valid numbers.
 	case $current in
-	0 | [1-9] | [1-9][0-9] | [1-9][0-9][0-9]) ;;
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
 	*)
-	  $echo "$modename: CURRENT \`$current' is not a nonnegative integer" 1>&2
+	  $echo "$modename: CURRENT \`$current' must be a nonnegative integer" 1>&2
 	  $echo "$modename: \`$vinfo' is not valid version information" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	  ;;
 	esac
 
 	case $revision in
-	0 | [1-9] | [1-9][0-9] | [1-9][0-9][0-9]) ;;
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
 	*)
-	  $echo "$modename: REVISION \`$revision' is not a nonnegative integer" 1>&2
+	  $echo "$modename: REVISION \`$revision' must be a nonnegative integer" 1>&2
 	  $echo "$modename: \`$vinfo' is not valid version information" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	  ;;
 	esac
 
 	case $age in
-	0 | [1-9] | [1-9][0-9] | [1-9][0-9][0-9]) ;;
+	0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;
 	*)
-	  $echo "$modename: AGE \`$age' is not a nonnegative integer" 1>&2
+	  $echo "$modename: AGE \`$age' must be a nonnegative integer" 1>&2
 	  $echo "$modename: \`$vinfo' is not valid version information" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	  ;;
 	esac
 
-	if test $age -gt $current; then
+	if test "$age" -gt "$current"; then
 	  $echo "$modename: AGE \`$age' is greater than the current interface number \`$current'" 1>&2
 	  $echo "$modename: \`$vinfo' is not valid version information" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 
 	# Calculate the version variables.
 	major=
 	versuffix=
+	versuffix2=
 	verstring=
 	case $version_type in
 	none) ;;
@@ -2596,7 +3342,7 @@
 	  versuffix="$major.$age.$revision"
 	  # Darwin ld doesn't like 0 for these options...
 	  minor_current=`expr $current + 1`
-	  verstring="-compatibility_version $minor_current -current_version $minor_current.$revision"
+	  verstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision"
 	  ;;
 
 	freebsd-aout)
@@ -2609,16 +3355,21 @@
 	  versuffix=".$current";
 	  ;;
 
-	irix)
-	  major=`expr $current - $age`
-	  verstring="sgi$major.$revision"
+	irix | nonstopux)
+	  major=`expr $current - $age + 1`
+
+	  case $version_type in
+	    nonstopux) verstring_prefix=nonstopux ;;
+	    *)         verstring_prefix=sgi ;;
+	  esac
+	  verstring="$verstring_prefix$major.$revision"
 
 	  # Add in all the interfaces that we are compatible with.
 	  loop=$revision
-	  while test $loop != 0; do
+	  while test "$loop" -ne 0; do
 	    iface=`expr $revision - $loop`
 	    loop=`expr $loop - 1`
-	    verstring="sgi$major.$iface:$verstring"
+	    verstring="$verstring_prefix$major.$iface:$verstring"
 	  done
 
 	  # Before this point, $major must not contain `.'.
@@ -2629,16 +3380,17 @@
 	linux)
 	  major=.`expr $current - $age`
 	  versuffix="$major.$age.$revision"
+	  versuffix2="$major.$age"
 	  ;;
 
 	osf)
-	  major=`expr $current - $age`
+	  major=.`expr $current - $age`
 	  versuffix=".$current.$age.$revision"
 	  verstring="$current.$age.$revision"
 
 	  # Add in all the interfaces that we are compatible with.
 	  loop=$age
-	  while test $loop != 0; do
+	  while test "$loop" -ne 0; do
 	    iface=`expr $current - $loop`
 	    loop=`expr $loop - 1`
 	    verstring="$verstring:${iface}.0"
@@ -2662,15 +3414,24 @@
 
 	*)
 	  $echo "$modename: unknown library version type \`$version_type'" 1>&2
-	  echo "Fatal configuration error.  See the $PACKAGE docs for more information." 1>&2
-	  exit 1
+	  $echo "Fatal configuration error.  See the $PACKAGE docs for more information." 1>&2
+	  exit $EXIT_FAILURE
 	  ;;
 	esac
 
 	# Clear the version info if we defaulted, and they specified a release.
 	if test -z "$vinfo" && test -n "$release"; then
 	  major=
-	  verstring="0.0"
+	  case $version_type in
+	  darwin)
+	    # we can't check for "0.0" in archive_cmds due to quoting
+	    # problems, so we reset it completely
+	    verstring=
+	    ;;
+	  *)
+	    verstring="0.0"
+	    ;;
+	  esac
 	  if test "$need_version" = no; then
 	    versuffix=
 	  else
@@ -2682,6 +3443,7 @@
 	if test "$avoid_version" = yes && test "$need_version" = no; then
 	  major=
 	  versuffix=
+	  versuffix2=
 	  verstring=""
 	fi
 
@@ -2700,23 +3462,29 @@
 
       if test "$mode" != relink; then
 	# Remove our outputs, but don't remove object files since they
-        # may have been created when compiling PIC objects.
-        removelist=
-        tempremovelist=`echo "$output_objdir/*"`
+	# may have been created when compiling PIC objects.
+	removelist=
+	tempremovelist=`$echo "$output_objdir/*"`
 	for p in $tempremovelist; do
-          case $p in
-            *.$objext)
-               ;;
-            $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*)
-               removelist="$removelist $p"
-               ;;
-            *) ;;
-          esac
-        done
-        if test -n "$removelist"; then
+	  case $p in
+	    *.$objext)
+	       ;;
+	    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*)
+	       if test "X$precious_files_regex" != "X"; then
+	         if echo $p | $EGREP -e "$precious_files_regex" >/dev/null 2>&1
+	         then
+		   continue
+		 fi
+	       fi
+	       removelist="$removelist $p"
+	       ;;
+	    *) ;;
+	  esac
+	done
+	if test -n "$removelist"; then
 	  $show "${rm}r $removelist"
 	  $run ${rm}r $removelist
-        fi
+	fi
       fi
 
       # Now set the variables for building old libraries.
@@ -2727,12 +3495,13 @@
 	oldobjs="$objs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}'$/d' -e "$lo2o" | $NL2SP`
       fi
 
-      # Eliminate all temporary directories.
-      for path in $notinst_path; do
-	lib_search_path=`echo "$lib_search_path " | sed -e 's% $path % %g'`
-	deplibs=`echo "$deplibs " | sed -e 's% -L$path % %g'`
-	dependency_libs=`echo "$dependency_libs " | sed -e 's% -L$path % %g'`
-      done
+      ### Commented out in pkgsrc, since it is completely broken.
+      ## Eliminate all temporary directories.
+      #for path in $notinst_path; do
+      #	lib_search_path=`$echo "$lib_search_path " | ${SED} -e "s% $path % %g"`
+      #	deplibs=`$echo "$deplibs " | ${SED} -e "s% -L$path % %g"`
+      #	dependency_libs=`$echo "$dependency_libs " | ${SED} -e "s% -L$path % %g"`
+      #done
 
       if test -n "$xrpath"; then
 	# If the user specified any rpath flags, then add them.
@@ -2744,7 +3513,7 @@
 	  *) finalize_rpath="$finalize_rpath $libdir" ;;
 	  esac
 	done
-	if test $hardcode_into_libs != yes || test $build_old_libs = yes; then
+	if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then
 	  dependency_libs="$temp_xrpath $dependency_libs"
 	fi
       fi
@@ -2782,9 +3551,18 @@
 	  *-*-netbsd*)
 	    # Don't link with libc until the a.out ld.so is fixed.
 	    ;;
-	  *)
+	  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)
+	    # Do not include libc due to us having libc/libc_r.
+	    ;;
+	  *-*-sco3.2v5* | *-*-sco5v6*)
+	    # Causes problems with __ctype
+	    ;;
+	  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)
+	    # Compiler inserts libc in the correct place for threads to work
+	    ;;
+ 	  *)
 	    # Add libc to deplibs on all other systems if necessary.
-	    if test $build_libtool_need_lc = "yes"; then
+	    if test "$build_libtool_need_lc" = "yes"; then
 	      deplibs="$deplibs -lc"
 	    fi
 	    ;;
@@ -2811,7 +3589,7 @@
 	  # This might be a little naive.  We might want to check
 	  # whether the library exists or not.  But this is on
 	  # osf3 & osf4 and I'm not really sure... Just
-	  # implementing what was already the behaviour.
+	  # implementing what was already the behavior.
 	  newdeplibs=$deplibs
 	  ;;
 	test_compile)
@@ -2824,43 +3602,22 @@
 	  int main() { return 0; }
 EOF
 	  $rm conftest
-	  $LTCC -o conftest conftest.c $deplibs
-	  if test $? -eq 0 ; then
+	  $LTCC $LTCFLAGS -o conftest conftest.c $deplibs
+	  if test "$?" -eq 0 ; then
 	    ldd_output=`ldd conftest`
 	    for i in $deplibs; do
-	      name="`expr $i : '-l\(.*\)'`"
+	      name=`expr $i : '-l\(.*\)'`
 	      # If $name is empty we are operating on a -L argument.
-	      if test -n "$name" && test "$name" != "0"; then
-		libname=`eval \\$echo \"$libname_spec\"`
-		deplib_matches=`eval \\$echo \"$library_names_spec\"`
-		set dummy $deplib_matches
-		deplib_match=$2
-		if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
-		  newdeplibs="$newdeplibs $i"
-		else
-		  droppeddeps=yes
-		  echo
-		  echo "*** Warning: This library needs some functionality provided by $i."
-		  echo "*** I have the capability to make that library automatically link in when"
-		  echo "*** you link to this library.  But I can only do this if you have a"
-		  echo "*** shared version of the library, which you do not appear to have."
-		fi
-	      else
-		newdeplibs="$newdeplibs $i"
-	      fi
-	    done
-	  else
-	    # Error occured in the first compile.  Let's try to salvage the situation:
-	    # Compile a seperate program for each library.
-	    for i in $deplibs; do
-	      name="`expr $i : '-l\(.*\)'`"
-	     # If $name is empty we are operating on a -L argument.
-	      if test -n "$name" && test "$name" != "0"; then
-		$rm conftest
-		$LTCC -o conftest conftest.c $i
-		# Did it work?
-		if test $? -eq 0 ; then
-		  ldd_output=`ldd conftest`
+              if test "$name" != "" && test "$name" -ne "0"; then
+		if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		  case " $predeps $postdeps " in
+		  *" $i "*)
+		    newdeplibs="$newdeplibs $i"
+		    i=""
+		    ;;
+		  esac
+	        fi
+		if test -n "$i" ; then
 		  libname=`eval \\$echo \"$libname_spec\"`
 		  deplib_matches=`eval \\$echo \"$library_names_spec\"`
 		  set dummy $deplib_matches
@@ -2869,19 +3626,64 @@
 		    newdeplibs="$newdeplibs $i"
 		  else
 		    droppeddeps=yes
-		    echo
-		    echo "*** Warning: This library needs some functionality provided by $i."
-		    echo "*** I have the capability to make that library automatically link in when"
-		    echo "*** you link to this library.  But I can only do this if you have a"
-		    echo "*** shared version of the library, which you do not appear to have."
+		    $echo
+		    $echo "*** Warning: dynamic linker does not accept needed library $i."
+		    $echo "*** I have the capability to make that library automatically link in when"
+		    $echo "*** you link to this library.  But I can only do this if you have a"
+		    $echo "*** shared version of the library, which I believe you do not have"
+		    $echo "*** because a test_compile did reveal that the linker did not use it for"
+		    $echo "*** its dynamic dependency list that programs get resolved with at runtime."
+		  fi
+		fi
+	      else
+		newdeplibs="$newdeplibs $i"
+	      fi
+	    done
+	  else
+	    # Error occurred in the first compile.  Let's try to salvage
+	    # the situation: Compile a separate program for each library.
+	    for i in $deplibs; do
+	      name=`expr $i : '-l\(.*\)'`
+	      # If $name is empty we are operating on a -L argument.
+              if test "$name" != "" && test "$name" != "0"; then
+		$rm conftest
+		$LTCC $LTCFLAGS -o conftest conftest.c $i
+		# Did it work?
+		if test "$?" -eq 0 ; then
+		  ldd_output=`ldd conftest`
+		  if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		    case " $predeps $postdeps " in
+		    *" $i "*)
+		      newdeplibs="$newdeplibs $i"
+		      i=""
+		      ;;
+		    esac
+		  fi
+		  if test -n "$i" ; then
+		    libname=`eval \\$echo \"$libname_spec\"`
+		    deplib_matches=`eval \\$echo \"$library_names_spec\"`
+		    set dummy $deplib_matches
+		    deplib_match=$2
+		    if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0 ; then
+		      newdeplibs="$newdeplibs $i"
+		    else
+		      droppeddeps=yes
+		      $echo
+		      $echo "*** Warning: dynamic linker does not accept needed library $i."
+		      $echo "*** I have the capability to make that library automatically link in when"
+		      $echo "*** you link to this library.  But I can only do this if you have a"
+		      $echo "*** shared version of the library, which you do not appear to have"
+		      $echo "*** because a test_compile did reveal that the linker did not use this one"
+		      $echo "*** as a dynamic dependency that programs can get resolved with at runtime."
+		    fi
 		  fi
 		else
 		  droppeddeps=yes
-		  echo
-		  echo "*** Warning!  Library $i is needed by this library but I was not able to"
-		  echo "***  make it link in!  You will probably need to install it or some"
-		  echo "*** library that it depends on before this library will be fully"
-		  echo "*** functional.  Installing it before continuing would be even better."
+		  $echo
+		  $echo "*** Warning!  Library $i is needed by this library but I was not able to"
+		  $echo "***  make it link in!  You will probably need to install it or some"
+		  $echo "*** library that it depends on before this library will be fully"
+		  $echo "*** functional.  Installing it before continuing would be even better."
 		fi
 	      else
 		newdeplibs="$newdeplibs $i"
@@ -2893,13 +3695,22 @@
 	  set dummy $deplibs_check_method
 	  file_magic_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"`
 	  for a_deplib in $deplibs; do
-	    name="`expr $a_deplib : '-l\(.*\)'`"
+	    name=`expr $a_deplib : '-l\(.*\)'`
 	    # If $name is empty we are operating on a -L argument.
-	    if test -n "$name" && test "$name" != "0"; then
-	      libname=`eval \\$echo \"$libname_spec\"`
-	      for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
-		    potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
-		    for potent_lib in $potential_libs; do
+            if test "$name" != "" && test  "$name" != "0"; then
+	      if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  newdeplibs="$newdeplibs $a_deplib"
+		  a_deplib=""
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib" ; then
+		libname=`eval \\$echo \"$libname_spec\"`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+		  for potent_lib in $potential_libs; do
 		      # Follow soft links.
 		      if ls -lLd "$potent_lib" 2>/dev/null \
 			 | grep " -> " >/dev/null; then
@@ -2912,28 +3723,36 @@
 		      # but so what?
 		      potlib="$potent_lib"
 		      while test -h "$potlib" 2>/dev/null; do
-			potliblink=`ls -ld $potlib | sed 's/.* -> //'`
+			potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'`
 			case $potliblink in
 			[\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";;
 			*) potlib=`$echo "X$potlib" | $Xsed -e 's,[^/]*$,,'`"$potliblink";;
 			esac
 		      done
 		      if eval $file_magic_cmd \"\$potlib\" 2>/dev/null \
-			 | sed 10q \
-			 | egrep "$file_magic_regex" > /dev/null; then
+			 | ${SED} 10q \
+			 | $EGREP "$file_magic_regex" > /dev/null; then
 			newdeplibs="$newdeplibs $a_deplib"
 			a_deplib=""
 			break 2
 		      fi
-		    done
-	      done
+		  done
+		done
+	      fi
 	      if test -n "$a_deplib" ; then
 		droppeddeps=yes
-		echo
-		echo "*** Warning: This library needs some functionality provided by $a_deplib."
-		echo "*** I have the capability to make that library automatically link in when"
-		echo "*** you link to this library.  But I can only do this if you have a"
-		echo "*** shared version of the library, which you do not appear to have."
+		$echo
+		$echo "*** Warning: linker path does not have real file for library $a_deplib."
+		$echo "*** I have the capability to make that library automatically link in when"
+		$echo "*** you link to this library.  But I can only do this if you have a"
+		$echo "*** shared version of the library, which you do not appear to have"
+		$echo "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib" ; then
+		  $echo "*** with $libname but no candidates were found. (...for file magic test)"
+		else
+		  $echo "*** with $libname and none of the candidates passed a file format test"
+		  $echo "*** using a file magic. Last file checked: $potlib"
+		fi
 	      fi
 	    else
 	      # Add a -L argument.
@@ -2945,29 +3764,47 @@
 	  set dummy $deplibs_check_method
 	  match_pattern_regex=`expr "$deplibs_check_method" : "$2 \(.*\)"`
 	  for a_deplib in $deplibs; do
-	    name="`expr $a_deplib : '-l\(.*\)'`"
+	    name=`expr $a_deplib : '-l\(.*\)'`
 	    # If $name is empty we are operating on a -L argument.
 	    if test -n "$name" && test "$name" != "0"; then
-	      libname=`eval \\$echo \"$libname_spec\"`
-	      for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
-		potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
-		for potent_lib in $potential_libs; do
-		  if eval echo \"$potent_lib\" 2>/dev/null \
-		      | sed 10q \
-		      | egrep "$match_pattern_regex" > /dev/null; then
-		    newdeplibs="$newdeplibs $a_deplib"
-		    a_deplib=""
-		    break 2
-		  fi
+	      if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+		case " $predeps $postdeps " in
+		*" $a_deplib "*)
+		  newdeplibs="$newdeplibs $a_deplib"
+		  a_deplib=""
+		  ;;
+		esac
+	      fi
+	      if test -n "$a_deplib" ; then
+		libname=`eval \\$echo \"$libname_spec\"`
+		for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do
+		  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`
+		  for potent_lib in $potential_libs; do
+		    potlib="$potent_lib" # see symlink-check above in file_magic test
+		    if eval $echo \"$potent_lib\" 2>/dev/null \
+		        | ${SED} 10q \
+		        | $EGREP "$match_pattern_regex" > /dev/null; then
+		      newdeplibs="$newdeplibs $a_deplib"
+		      a_deplib=""
+		      break 2
+		    fi
+		  done
 		done
-	      done
+	      fi
 	      if test -n "$a_deplib" ; then
 		droppeddeps=yes
-		echo
-		echo "*** Warning: This library needs some functionality provided by $a_deplib."
-		echo "*** I have the capability to make that library automatically link in when"
-		echo "*** you link to this library.  But I can only do this if you have a"
-		echo "*** shared version of the library, which you do not appear to have."
+		$echo
+		$echo "*** Warning: linker path does not have real file for library $a_deplib."
+		$echo "*** I have the capability to make that library automatically link in when"
+		$echo "*** you link to this library.  But I can only do this if you have a"
+		$echo "*** shared version of the library, which you do not appear to have"
+		$echo "*** because I did check the linker path looking for a file starting"
+		if test -z "$potlib" ; then
+		  $echo "*** with $libname but no candidates were found. (...for regex pattern test)"
+		else
+		  $echo "*** with $libname and none of the candidates passed a file format test"
+		  $echo "*** using a regex pattern. Last file checked: $potlib"
+		fi
 	      fi
 	    else
 	      # Add a -L argument.
@@ -2977,16 +3814,23 @@
 	  ;;
 	none | unknown | *)
 	  newdeplibs=""
-	  if $echo "X $deplibs" | $Xsed -e 's/ -lc$//' \
-	       -e 's/ -[LR][^ ]*//g' -e 's/[ 	]//g' |
-	     grep . >/dev/null; then
-	    echo
+	  tmp_deplibs=`$echo "X $deplibs" | $Xsed -e 's/ -lc$//' \
+	    -e 's/ -[LR][^ ]*//g'`
+	  if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then
+	    for i in $predeps $postdeps ; do
+	      # can't use Xsed below, because $i might contain '/'
+	      tmp_deplibs=`$echo "X $tmp_deplibs" | ${SED} -e "1s,^X,," -e "s,$i,,"`
+	    done
+	  fi
+	  if $echo "X $tmp_deplibs" | $Xsed -e 's/[ 	]//g' \
+	    | grep . >/dev/null; then
+	    $echo
 	    if test "X$deplibs_check_method" = "Xnone"; then
-	      echo "*** Warning: inter-library dependencies are not supported in this platform."
+	      $echo "*** Warning: inter-library dependencies are not supported in this platform."
 	    else
-	      echo "*** Warning: inter-library dependencies are not known to be supported."
+	      $echo "*** Warning: inter-library dependencies are not known to be supported."
 	    fi
-	    echo "*** All declared inter-library dependencies are being dropped."
+	    $echo "*** All declared inter-library dependencies are being dropped."
 	    droppeddeps=yes
 	  fi
 	  ;;
@@ -3006,17 +3850,17 @@
 
 	if test "$droppeddeps" = yes; then
 	  if test "$module" = yes; then
-	    echo
-	    echo "*** Warning: libtool could not satisfy all declared inter-library"
-	    echo "*** dependencies of module $libname.  Therefore, libtool will create"
-	    echo "*** a static module, that should work as long as the dlopening"
-	    echo "*** application is linked with the -dlopen flag."
+	    $echo
+	    $echo "*** Warning: libtool could not satisfy all declared inter-library"
+	    $echo "*** dependencies of module $libname.  Therefore, libtool will create"
+	    $echo "*** a static module, that should work as long as the dlopening"
+	    $echo "*** application is linked with the -dlopen flag."
 	    if test -z "$global_symbol_pipe"; then
-	      echo
-	      echo "*** However, this would only work if libtool was able to extract symbol"
-	      echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
-	      echo "*** not find such a program.  So, this module is probably useless."
-	      echo "*** \`nm' from GNU binutils and a full rebuild may help."
+	      $echo
+	      $echo "*** However, this would only work if libtool was able to extract symbol"
+	      $echo "*** lists from a program, using \`nm' or equivalent, but libtool could"
+	      $echo "*** not find such a program.  So, this module is probably useless."
+	      $echo "*** \`nm' from GNU binutils and a full rebuild may help."
 	    fi
 	    if test "$build_old_libs" = no; then
 	      oldlibs="$output_objdir/$libname.$libext"
@@ -3026,16 +3870,16 @@
 	      build_libtool_libs=no
 	    fi
 	  else
-	    echo "*** The inter-library dependencies that have been dropped here will be"
-	    echo "*** automatically added whenever a program is linked with this library"
-	    echo "*** or is declared to -dlopen it."
+	    $echo "*** The inter-library dependencies that have been dropped here will be"
+	    $echo "*** automatically added whenever a program is linked with this library"
+	    $echo "*** or is declared to -dlopen it."
 
-	    if test $allow_undefined = no; then
-	      echo
-	      echo "*** Since this library must not contain undefined symbols,"
-	      echo "*** because either the platform does not support them or"
-	      echo "*** it was explicitly requested with -no-undefined,"
-	      echo "*** libtool will only create a static version of it."
+	    if test "$allow_undefined" = no; then
+	      $echo
+	      $echo "*** Since this library must not contain undefined symbols,"
+	      $echo "*** because either the platform does not support them or"
+	      $echo "*** it was explicitly requested with -no-undefined,"
+	      $echo "*** libtool will only create a static version of it."
 	      if test "$build_old_libs" = no; then
 		oldlibs="$output_objdir/$libname.$libext"
 		build_libtool_libs=module
@@ -3050,6 +3894,35 @@
 	deplibs=$newdeplibs
       fi
 
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $deplibs " in
+	  *" -L$path/$objdir "*)
+	    new_libs="$new_libs -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) new_libs="$new_libs $deplib" ;;
+	  esac
+	  ;;
+	*) new_libs="$new_libs $deplib" ;;
+	esac
+      done
+      deplibs="$new_libs"
+
+
       # All the library-specific variables (install_libdir is set above).
       library_names=
       old_library=
@@ -3057,7 +3930,7 @@
 
       # Test again, we may have decided not to build it any more
       if test "$build_libtool_libs" = yes; then
-	if test $hardcode_into_libs = yes; then
+	if test "$hardcode_into_libs" = yes; then
 	  # Hardcode the library paths
 	  hardcode_libdirs=
 	  dep_rpath=
@@ -3093,7 +3966,11 @@
 	  if test -n "$hardcode_libdir_separator" &&
 	     test -n "$hardcode_libdirs"; then
 	    libdir="$hardcode_libdirs"
-	    eval dep_rpath=\"$hardcode_libdir_flag_spec\"
+	    if test -n "$hardcode_libdir_flag_spec_ld"; then
+	      eval dep_rpath=\"$hardcode_libdir_flag_spec_ld\"
+	    else
+	      eval dep_rpath=\"$hardcode_libdir_flag_spec\"
+	    fi
 	  fi
 	  if test -n "$runpath_var" && test -n "$perm_rpath"; then
 	    # We should set the runpath_var.
@@ -3113,6 +3990,7 @@
 	fi
 
 	# Get the real and link names of the library.
+	eval shared_ext=\"$shrext_cmds\"
 	eval library_names=\"$library_names_spec\"
 	set dummy $library_names
 	realname="$2"
@@ -3123,31 +4001,17 @@
 	else
 	  soname="$realname"
 	fi
-	test -z "$dlname" && dlname=$soname
+	if test -z "$dlname"; then
+	  dlname=$soname
+	fi
 
 	lib="$output_objdir/$realname"
+	linknames=
 	for link
 	do
 	  linknames="$linknames $link"
 	done
 
-#	# Ensure that we have .o objects for linkers which dislike .lo
-#	# (e.g. aix) in case we are running --disable-static
-#	for obj in $libobjs; do
-#	  xdir=`$echo "X$obj" | $Xsed -e 's%/[^/]*$%%'`
-#	  if test "X$xdir" = "X$obj"; then
-#	    xdir="."
-#	  else
-#	    xdir="$xdir"
-#	  fi
-#	  baseobj=`$echo "X$obj" | $Xsed -e 's%^.*/%%'`
-#	  oldobj=`$echo "X$baseobj" | $Xsed -e "$lo2o"`
-#	  if test ! -f $xdir/$oldobj && test "$baseobj" != "$oldobj"; then
-#	    $show "(cd $xdir && ${LN_S} $baseobj $oldobj)"
-#	    $run eval '(cd $xdir && ${LN_S} $baseobj $oldobj)' || exit $?
-#	  fi
-#	done
-
 	# Use standard objects if they are pic
 	test -z "$pic_flag" && libobjs=`$echo "X$libobjs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
 
@@ -3157,17 +4021,29 @@
 	    $show "generating symbol list for \`$libname.la'"
 	    export_symbols="$output_objdir/$libname.exp"
 	    $run $rm $export_symbols
-	    eval cmds=\"$export_symbols_cmds\"
-	    IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
+	    cmds=$export_symbols_cmds
+	    save_ifs="$IFS"; IFS='~'
 	    for cmd in $cmds; do
 	      IFS="$save_ifs"
-	      $show "$cmd"
-	      $run eval "$cmd" || exit $?
+	      eval cmd=\"$cmd\"
+	      if len=`expr "X$cmd" : ".*"` &&
+	       test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	        $show "$cmd"
+	        $run eval "$cmd" || exit $?
+	        skipped_export=false
+	      else
+	        # The command line is too long to execute in one step.
+	        $show "using reloadable object file for export list..."
+	        skipped_export=:
+		# Break out early, otherwise skipped_export may be
+		# set to false by a later but shorter cmd.
+		break
+	      fi
 	    done
 	    IFS="$save_ifs"
 	    if test -n "$export_symbols_regex"; then
-	      $show "egrep -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\""
-	      $run eval 'egrep -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
+	      $show "$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\""
+	      $run eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"'
 	      $show "$mv \"${export_symbols}T\" \"$export_symbols\""
 	      $run eval '$mv "${export_symbols}T" "$export_symbols"'
 	    fi
@@ -3178,47 +4054,30 @@
 	  $run eval '$echo "X$include_expsyms" | $SP2NL >> "$export_symbols"'
 	fi
 
+	tmp_deplibs=
+	for test_deplib in $deplibs; do
+		case " $convenience " in
+		*" $test_deplib "*) ;;
+		*)
+			tmp_deplibs="$tmp_deplibs $test_deplib"
+			;;
+		esac
+	done
+	deplibs="$tmp_deplibs"
+
 	if test -n "$convenience"; then
 	  if test -n "$whole_archive_flag_spec"; then
 	    save_libobjs=$libobjs
 	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
 	  else
 	    gentop="$output_objdir/${outputname}x"
-	    $show "${rm}r $gentop"
-	    $run ${rm}r "$gentop"
-	    $show "$mkdir $gentop"
-	    $run $mkdir "$gentop"
-	    status=$?
-	    if test $status -ne 0 && test ! -d "$gentop"; then
-	      exit $status
-	    fi
 	    generated="$generated $gentop"
 
-	    for xlib in $convenience; do
-	      # Extract the objects.
-	      case $xlib in
-	      [\\/]* | [A-Za-z]:[\\/]*) xabs="$xlib" ;;
-	      *) xabs=`pwd`"/$xlib" ;;
-	      esac
-	      xlib=`$echo "X$xlib" | $Xsed -e 's%^.*/%%'`
-	      xdir="$gentop/$xlib"
-
-	      $show "${rm}r $xdir"
-	      $run ${rm}r "$xdir"
-	      $show "$mkdir $xdir"
-	      $run $mkdir "$xdir"
-	      status=$?
-	      if test $status -ne 0 && test ! -d "$xdir"; then
-		exit $status
-	      fi
-	      $show "(cd $xdir && $AR x $xabs)"
-	      $run eval "(cd \$xdir && $AR x \$xabs)" || exit $?
-
-	      libobjs="$libobjs "`find $xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
-	    done
+	    func_extract_archives $gentop $convenience
+	    libobjs="$libobjs $func_extract_archives_result"
 	  fi
 	fi
-
+	
 	if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then
 	  eval flag=\"$thread_safe_flag_spec\"
 	  linker_flags="$linker_flags $flag"
@@ -3230,17 +4089,31 @@
 	fi
 
 	# Do each of the archive commands.
-	if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
-	  eval cmds=\"$archive_expsym_cmds\"
+	if test "$module" = yes && test -n "$module_cmds" ; then
+	  if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	    eval test_cmds=\"$module_expsym_cmds\"
+	    cmds=$module_expsym_cmds
+	  else
+	    eval test_cmds=\"$module_cmds\"
+	    cmds=$module_cmds
+	  fi
 	else
-	  eval cmds=\"$archive_cmds\"
+	if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	  eval test_cmds=\"$archive_expsym_cmds\"
+	  cmds=$archive_expsym_cmds
+	else
+	  eval test_cmds=\"$archive_cmds\"
+	  cmds=$archive_cmds
+	  fi
 	fi
-        if len=`expr "X$cmds" : ".*"` &&
-           test $len -le $max_cmd_len; then
-          :
-        else
+
+	if test "X$skipped_export" != "X:" &&
+	   len=`expr "X$test_cmds" : ".*" 2>/dev/null` &&
+	   test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  :
+	else
 	  # The command line is too long to link in one step, link piecewise.
-          $echo "creating reloadable object files..."
+	  $echo "creating reloadable object files..."
 
 	  # Save the value of $output and $libobjs because we want to
 	  # use them later.  If we have whole_archive_flag_spec, we
@@ -3253,72 +4126,82 @@
 	  if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then
 	    save_libobjs=$libobjs
 	  fi
-          save_output=$output
+	  save_output=$output
+	  output_la=`$echo "X$output" | $Xsed -e "$basename"`
 
 	  # Clear the reloadable object creation command queue and
 	  # initialize k to one.
-          test_cmds=
-          concat_cmds=
-          objlist=
-          delfiles=
-          last_robj=
-          k=1
-          output=$output_objdir/$save_output-${k}.$objext
+	  test_cmds=
+	  concat_cmds=
+	  objlist=
+	  delfiles=
+	  last_robj=
+	  k=1
+	  output=$output_objdir/$output_la-${k}.$objext
 	  # Loop over the list of objects to be linked.
-          for obj in $save_libobjs
-          do
-            eval test_cmds=\"$reload_cmds $objlist $last_robj\"
-            if test "X$objlist" = X ||
-	       { len=`expr "X$test_cmds" : ".*"` &&
-                 test $len -le $max_cmd_len; }; then
-              objlist="$objlist $obj"
-            else
+	  for obj in $save_libobjs
+	  do
+	    eval test_cmds=\"$reload_cmds $objlist $last_robj\"
+	    if test "X$objlist" = X ||
+	       { len=`expr "X$test_cmds" : ".*" 2>/dev/null` &&
+		 test "$len" -le "$max_cmd_len"; }; then
+	      objlist="$objlist $obj"
+	    else
 	      # The command $test_cmds is almost too long, add a
 	      # command to the queue.
-              if test $k -eq 1 ; then
-	        # The first file doesn't have a previous command to add.
-                eval concat_cmds=\"$reload_cmds $objlist $last_robj\"
-              else
-	        # All subsequent reloadable object files will link in
-	        # the last one created.
-                eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj\"
-              fi
-              last_robj=$output_objdir/$save_output-${k}.$objext
-              k=`expr $k + 1`
-              output=$output_objdir/$save_output-${k}.$objext
-              objlist=$obj
-              len=1
-            fi
-          done
+	      if test "$k" -eq 1 ; then
+		# The first file doesn't have a previous command to add.
+		eval concat_cmds=\"$reload_cmds $objlist $last_robj\"
+	      else
+		# All subsequent reloadable object files will link in
+		# the last one created.
+		eval concat_cmds=\"\$concat_cmds~$reload_cmds $objlist $last_robj\"
+	      fi
+	      last_robj=$output_objdir/$output_la-${k}.$objext
+	      k=`expr $k + 1`
+	      output=$output_objdir/$output_la-${k}.$objext
+	      objlist=$obj
+	      len=1
+	    fi
+	  done
 	  # Handle the remaining objects by creating one last
 	  # reloadable object file.  All subsequent reloadable object
 	  # files will link in the last one created.
 	  test -z "$concat_cmds" || concat_cmds=$concat_cmds~
-          eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\"
+	  eval concat_cmds=\"\${concat_cmds}$reload_cmds $objlist $last_robj\"
 
-	  # Set up a command to remove the reloadale object files
+	  if ${skipped_export-false}; then
+	    $show "generating symbol list for \`$libname.la'"
+	    export_symbols="$output_objdir/$libname.exp"
+	    $run $rm $export_symbols
+	    libobjs=$output
+	    # Append the command to create the export file.
+	    eval concat_cmds=\"\$concat_cmds~$export_symbols_cmds\"
+          fi
+
+	  # Set up a command to remove the reloadable object files
 	  # after they are used.
-          i=0
-          while test $i -lt $k
-          do
-            i=`expr $i + 1`
-            delfiles="$delfiles $output_objdir/$save_output-${i}.$objext"
-          done
+	  i=0
+	  while test "$i" -lt "$k"
+	  do
+	    i=`expr $i + 1`
+	    delfiles="$delfiles $output_objdir/$output_la-${i}.$objext"
+	  done
 
-          $echo "creating a temporary reloadable object file: $output"
+	  $echo "creating a temporary reloadable object file: $output"
 
 	  # Loop through the commands generated above and execute them.
-          IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
-          for cmd in $concat_cmds; do
-            IFS="$save_ifs"
-            $show "$cmd"
-            $run eval "$cmd" || exit $?
-          done
-          IFS="$save_ifs"
+	  save_ifs="$IFS"; IFS='~'
+	  for cmd in $concat_cmds; do
+	    IFS="$save_ifs"
+	    $show "$cmd"
+	    $run eval "$cmd" || exit $?
+	  done
+	  IFS="$save_ifs"
 
-          libobjs=$output
+	  libobjs=$output
 	  # Restore the value of output.
-          output=$save_output
+	  output=$save_output
 
 	  if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then
 	    eval libobjs=\"\$libobjs $whole_archive_flag_spec\"
@@ -3327,28 +4210,54 @@
 	  # value of $libobjs for piecewise linking.
 
 	  # Do each of the archive commands.
-          if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
-            eval cmds=\"$archive_expsym_cmds\"
-          else
-            eval cmds=\"$archive_cmds\"
-          fi
+	  if test "$module" = yes && test -n "$module_cmds" ; then
+	    if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then
+	      cmds=$module_expsym_cmds
+	    else
+	      cmds=$module_cmds
+	    fi
+	  else
+	  if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then
+	    cmds=$archive_expsym_cmds
+	  else
+	    cmds=$archive_cmds
+	    fi
+	  fi
 
 	  # Append the command to remove the reloadable object files
 	  # to the just-reset $cmds.
-          eval cmds=\"\$cmds~$rm $delfiles\"
-        fi
-        IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
-        for cmd in $cmds; do
-          IFS="$save_ifs"
-          $show "$cmd"
-          $run eval "$cmd" || exit $?
-        done
-        IFS="$save_ifs"
+	  eval cmds=\"\$cmds~\$rm $delfiles\"
+	fi
+	save_ifs="$IFS"; IFS='~'
+	for cmd in $cmds; do
+	  IFS="$save_ifs"
+	  eval cmd=\"$cmd\"
+	  $show "$cmd"
+	  $run eval "$cmd" || {
+	    lt_exit=$?
+
+	    # Restore the uninstalled library and exit
+	    if test "$mode" = relink; then
+	      $run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)'
+	    fi
+
+	    exit $lt_exit
+	  }
+	done
+	IFS="$save_ifs"
 
 	# Restore the uninstalled library and exit
 	if test "$mode" = relink; then
 	  $run eval '(cd $output_objdir && $rm ${realname}T && $mv $realname ${realname}T && $mv "$realname"U $realname)' || exit $?
-	  exit 0
+
+	  if test -n "$convenience"; then
+	    if test -z "$whole_archive_flag_spec"; then
+	      $show "${rm}r $gentop"
+	      $run ${rm}r "$gentop"
+	    fi
+	  fi
+
+	  exit $EXIT_SUCCESS
 	fi
 
 	# Create links to the real library.
@@ -3396,7 +4305,7 @@
       *.lo)
 	if test -n "$objs$old_deplibs"; then
 	  $echo "$modename: cannot build library object \`$output' from non-libtool objects" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 	libobj="$output"
 	obj=`$echo "X$output" | $Xsed -e "$lo2o"`
@@ -3425,38 +4334,10 @@
 	  eval reload_conv_objs=\"\$reload_objs $whole_archive_flag_spec\"
 	else
 	  gentop="$output_objdir/${obj}x"
-	  $show "${rm}r $gentop"
-	  $run ${rm}r "$gentop"
-	  $show "$mkdir $gentop"
-	  $run $mkdir "$gentop"
-	  status=$?
-	  if test $status -ne 0 && test ! -d "$gentop"; then
-	    exit $status
-	  fi
 	  generated="$generated $gentop"
 
-	  for xlib in $convenience; do
-	    # Extract the objects.
-	    case $xlib in
-	    [\\/]* | [A-Za-z]:[\\/]*) xabs="$xlib" ;;
-	    *) xabs=`pwd`"/$xlib" ;;
-	    esac
-	    xlib=`$echo "X$xlib" | $Xsed -e 's%^.*/%%'`
-	    xdir="$gentop/$xlib"
-
-	    $show "${rm}r $xdir"
-	    $run ${rm}r "$xdir"
-	    $show "$mkdir $xdir"
-	    $run $mkdir "$xdir"
-	    status=$?
-	    if test $status -ne 0 && test ! -d "$xdir"; then
-	      exit $status
-	    fi
-	    $show "(cd $xdir && $AR x $xabs)"
-	    $run eval "(cd \$xdir && $AR x \$xabs)" || exit $?
-
-	    reload_conv_objs="$reload_objs "`find $xdir -name \*.$objext -print -o -name \*.lo -print | $NL2SP`
-	  done
+	  func_extract_archives $gentop $convenience
+	  reload_conv_objs="$reload_objs $func_extract_archives_result"
 	fi
       fi
 
@@ -3464,10 +4345,11 @@
       reload_objs="$objs$old_deplibs "`$echo "X$libobjs" | $SP2NL | $Xsed -e '/\.'${libext}$'/d' -e '/\.lib$/d' -e "$lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test
 
       output="$obj"
-      eval cmds=\"$reload_cmds\"
-      IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
+      cmds=$reload_cmds
+      save_ifs="$IFS"; IFS='~'
       for cmd in $cmds; do
 	IFS="$save_ifs"
+	eval cmd=\"$cmd\"
 	$show "$cmd"
 	$run eval "$cmd" || exit $?
       done
@@ -3480,7 +4362,7 @@
 	  $run ${rm}r $gentop
 	fi
 
-	exit 0
+	exit $EXIT_SUCCESS
       fi
 
       if test "$build_libtool_libs" != yes; then
@@ -3493,35 +4375,22 @@
 	# accidentally link it into a program.
 	# $show "echo timestamp > $libobj"
 	# $run eval "echo timestamp > $libobj" || exit $?
-	exit 0
+	exit $EXIT_SUCCESS
       fi
 
       if test -n "$pic_flag" || test "$pic_mode" != default; then
 	# Only do commands if we really have different PIC objects.
 	reload_objs="$libobjs $reload_conv_objs"
 	output="$libobj"
-	eval cmds=\"$reload_cmds\"
-	IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
+	cmds=$reload_cmds
+	save_ifs="$IFS"; IFS='~'
 	for cmd in $cmds; do
 	  IFS="$save_ifs"
+	  eval cmd=\"$cmd\"
 	  $show "$cmd"
 	  $run eval "$cmd" || exit $?
 	done
 	IFS="$save_ifs"
-#     else
-#	# Just create a symlink.
-#	$show $rm $libobj
-#	$run $rm $libobj
-#	xdir=`$echo "X$libobj" | $Xsed -e 's%/[^/]*$%%'`
-#	if test "X$xdir" = "X$libobj"; then
-#	  xdir="."
-#	else
-#	  xdir="$xdir"
-#	fi
-#	baseobj=`$echo "X$libobj" | $Xsed -e 's%^.*/%%'`
-#	oldobj=`$echo "X$baseobj" | $Xsed -e "$lo2o"`
-#	$show "(cd $xdir && $LN_S $oldobj $baseobj)"
-#	$run eval '(cd $xdir && $LN_S $oldobj $baseobj)' || exit $?
       fi
 
       if test -n "$gentop"; then
@@ -3529,12 +4398,12 @@
 	$run ${rm}r $gentop
       fi
 
-      exit 0
+      exit $EXIT_SUCCESS
       ;;
 
     prog)
       case $host in
-	*cygwin*) output=`echo $output | sed -e 's,.exe$,,;s,$,.exe,'` ;;
+	*cygwin*) output=`$echo $output | ${SED} -e 's,.exe$,,;s,$,.exe,'` ;;
       esac
       if test -n "$vinfo"; then
 	$echo "$modename: warning: \`-version-info' is ignored for programs" 1>&2
@@ -3559,6 +4428,45 @@
 	;;
       esac
 
+      case $host in
+      *darwin*)
+        # Don't allow lazy linking, it breaks C++ global constructors
+        if test "$tagname" = CXX ; then
+        compile_command="$compile_command ${wl}-bind_at_load"
+        finalize_command="$finalize_command ${wl}-bind_at_load"
+        fi
+        ;;
+      esac
+
+
+      # move library search paths that coincide with paths to not yet
+      # installed libraries to the beginning of the library search list
+      new_libs=
+      for path in $notinst_path; do
+	case " $new_libs " in
+	*" -L$path/$objdir "*) ;;
+	*)
+	  case " $compile_deplibs " in
+	  *" -L$path/$objdir "*)
+	    new_libs="$new_libs -L$path/$objdir" ;;
+	  esac
+	  ;;
+	esac
+      done
+      for deplib in $compile_deplibs; do
+	case $deplib in
+	-L*)
+	  case " $new_libs " in
+	  *" $deplib "*) ;;
+	  *) new_libs="$new_libs $deplib" ;;
+	  esac
+	  ;;
+	*) new_libs="$new_libs $deplib" ;;
+	esac
+      done
+      compile_deplibs="$new_libs"
+
+
       compile_command="$compile_command $compile_deplibs"
       finalize_command="$finalize_command $finalize_deplibs"
 
@@ -3603,10 +4511,15 @@
 	fi
 	case $host in
 	*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
+	  testbindir=`$echo "X$libdir" | $Xsed -e 's*/lib$*/bin*'`
 	  case :$dllsearchpath: in
 	  *":$libdir:"*) ;;
 	  *) dllsearchpath="$dllsearchpath:$libdir";;
 	  esac
+	  case :$dllsearchpath: in
+	  *":$testbindir:"*) ;;
+	  *) dllsearchpath="$dllsearchpath:$testbindir";;
+	  esac
 	  ;;
 	esac
       done
@@ -3654,6 +4567,12 @@
       fi
       finalize_rpath="$rpath"
 
+      if test -n "$libobjs" && test "$build_old_libs" = yes; then
+	# Transform all the library objects into standard objects.
+	compile_command=`$echo "X$compile_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+	finalize_command=`$echo "X$finalize_command" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
+      fi
+
       dlsyms=
       if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then
 	if test -n "$NM" && test -n "$global_symbol_pipe"; then
@@ -3696,38 +4615,50 @@
 	    test -z "$run" && $echo ': @PROGRAM@ ' > "$nlist"
 
 	    # Add our own program objects to the symbol list.
-	    progfiles="$objs$old_deplibs"
+	    progfiles=`$echo "X$objs$old_deplibs" | $SP2NL | $Xsed -e "$lo2o" | $NL2SP`
 	    for arg in $progfiles; do
 	      $show "extracting global C symbols from \`$arg'"
 	      $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'"
 	    done
 
 	    if test -n "$exclude_expsyms"; then
-	      $run eval 'egrep -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
+	      $run eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T'
 	      $run eval '$mv "$nlist"T "$nlist"'
 	    fi
 
 	    if test -n "$export_symbols_regex"; then
-	      $run eval 'egrep -e "$export_symbols_regex" "$nlist" > "$nlist"T'
+	      $run eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T'
 	      $run eval '$mv "$nlist"T "$nlist"'
 	    fi
 
 	    # Prepare the list of exported symbols
 	    if test -z "$export_symbols"; then
-	      export_symbols="$output_objdir/$output.exp"
+	      export_symbols="$output_objdir/$outputname.exp"
 	      $run $rm $export_symbols
-	      $run eval "sed -n -e '/^: @PROGRAM@$/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
+	      $run eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"'
+              case $host in
+              *cygwin* | *mingw* )
+	        $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+		$run eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"'
+                ;;
+              esac
 	    else
-	      $run eval "sed -e 's/\([][.*^$]\)/\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$output.exp"'
-	      $run eval 'grep -f "$output_objdir/$output.exp" < "$nlist" > "$nlist"T'
+	      $run eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"'
+	      $run eval 'grep -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T'
 	      $run eval 'mv "$nlist"T "$nlist"'
+              case $host in
+              *cygwin* | *mingw* )
+	        $run eval "echo EXPORTS "'> "$output_objdir/$outputname.def"'
+		$run eval 'cat "$nlist" >> "$output_objdir/$outputname.def"'
+                ;;
+              esac
 	    fi
 	  fi
 
 	  for arg in $dlprefiles; do
 	    $show "extracting global C symbols from \`$arg'"
-	    name=`echo "$arg" | sed -e 's%^.*/%%'`
-	    $run eval 'echo ": $name " >> "$nlist"'
+	    name=`$echo "$arg" | ${SED} -e 's%^.*/%%'`
+	    $run eval '$echo ": $name " >> "$nlist"'
 	    $run eval "$NM $arg | $global_symbol_pipe >> '$nlist'"
 	  done
 
@@ -3736,12 +4667,18 @@
 	    test -f "$nlist" || : > "$nlist"
 
 	    if test -n "$exclude_expsyms"; then
-	      egrep -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
+	      $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T
 	      $mv "$nlist"T "$nlist"
 	    fi
 
 	    # Try sorting and uniquifying the output.
-	    if grep -v "^: " < "$nlist" | sort +2 | uniq > "$nlist"S; then
+	    if grep -v "^: " < "$nlist" |
+		if sort -k 3 </dev/null >/dev/null 2>&1; then
+		  sort -k 3
+		else
+		  sort +2
+		fi |
+		uniq > "$nlist"S; then
 	      :
 	    else
 	      grep -v "^: " < "$nlist" > "$nlist"S
@@ -3750,7 +4687,7 @@
 	    if test -f "$nlist"S; then
 	      eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$dlsyms"'
 	    else
-	      echo '/* NONE */' >> "$output_objdir/$dlsyms"
+	      $echo '/* NONE */' >> "$output_objdir/$dlsyms"
 	    fi
 
 	    $echo >> "$output_objdir/$dlsyms" "\
@@ -3758,27 +4695,44 @@
 #undef lt_preloaded_symbols
 
 #if defined (__STDC__) && __STDC__
-# define lt_ptr_t void *
+# define lt_ptr void *
 #else
-# define lt_ptr_t char *
+# define lt_ptr char *
 # define const
 #endif
 
 /* The mapping between symbol names and symbols. */
+"
+
+	    case $host in
+	    *cygwin* | *mingw* )
+	  $echo >> "$output_objdir/$dlsyms" "\
+/* DATA imports from DLLs on WIN32 can't be const, because
+   runtime relocations are performed -- see ld's documentation
+   on pseudo-relocs */
+struct {
+"
+	      ;;
+	    * )
+	  $echo >> "$output_objdir/$dlsyms" "\
 const struct {
+"
+	      ;;
+	    esac
+
+
+	  $echo >> "$output_objdir/$dlsyms" "\
   const char *name;
-  lt_ptr_t address;
+  lt_ptr address;
 }
 lt_preloaded_symbols[] =
 {\
 "
 
-	    sed -n -e 's/^: \([^ ]*\) $/  {\"\1\", (lt_ptr_t) 0},/p' \
-		-e 's/^. \([^ ]*\) \([^ ]*\)$/  {"\2", (lt_ptr_t) \&\2},/p' \
-		  < "$nlist" >> "$output_objdir/$dlsyms"
+	    eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$dlsyms"
 
 	    $echo >> "$output_objdir/$dlsyms" "\
-  {0, (lt_ptr_t) 0}
+  {0, (lt_ptr) 0}
 };
 
 /* This works around a problem in FreeBSD linker */
@@ -3814,20 +4768,33 @@
 	  esac
 
 	  # Now compile the dynamic symbol file.
-	  $show "(cd $output_objdir && $LTCC -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")"
-	  $run eval '(cd $output_objdir && $LTCC -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $?
+	  $show "(cd $output_objdir && $LTCC  $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable \"$dlsyms\")"
+	  $run eval '(cd $output_objdir && $LTCC  $LTCFLAGS -c$no_builtin_flag$pic_flag_for_symtable "$dlsyms")' || exit $?
 
 	  # Clean up the generated files.
 	  $show "$rm $output_objdir/$dlsyms $nlist ${nlist}S ${nlist}T"
 	  $run $rm "$output_objdir/$dlsyms" "$nlist" "${nlist}S" "${nlist}T"
 
 	  # Transform the symbol file into the correct name.
-	  compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
-	  finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
+          case $host in
+          *cygwin* | *mingw* )
+            if test -f "$output_objdir/${outputname}.def" ; then
+              compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%"`
+              finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}.def $output_objdir/${outputname}S.${objext}%"`
+            else
+              compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
+              finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
+             fi
+            ;;
+          * )
+            compile_command=`$echo "X$compile_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
+            finalize_command=`$echo "X$finalize_command" | $Xsed -e "s%@SYMFILE@%$output_objdir/${outputname}S.${objext}%"`
+            ;;
+          esac
 	  ;;
 	*)
 	  $echo "$modename: unknown suffix for \`$dlsyms'" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	  ;;
 	esac
       else
@@ -3840,7 +4807,7 @@
 	finalize_command=`$echo "X$finalize_command" | $Xsed -e "s% @SYMFILE@%%"`
       fi
 
-      if test $need_relink = no || test "$build_libtool_libs" != yes; then
+      if test "$need_relink" = no || test "$build_libtool_libs" != yes; then
 	# Replace the output file specification.
 	compile_command=`$echo "X$compile_command" | $Xsed -e 's%@OUTPUT@%'"$output"'%g'`
 	link_command="$compile_command$compile_rpath"
@@ -3848,7 +4815,7 @@
 	# We have no uninstalled library dependencies, so finalize right now.
 	$show "$link_command"
 	$run eval "$link_command"
-	status=$?
+	exit_status=$?
 
 	# Delete the generated files.
 	if test -n "$dlsyms"; then
@@ -3856,7 +4823,7 @@
 	  $run $rm "$output_objdir/${outputname}S.${objext}"
 	fi
 
-	exit $status
+	exit $exit_status
       fi
 
       if test -n "$shlibpath_var"; then
@@ -3915,7 +4882,7 @@
 	# Link the executable and exit
 	$show "$link_command"
 	$run eval "$link_command" || exit $?
-	exit 0
+	exit $EXIT_SUCCESS
       fi
 
       if test "$hardcode_action" = relink; then
@@ -3965,15 +4932,15 @@
 	    relink_command="$var=\"$var_value\"; export $var; $relink_command"
 	  fi
 	done
-	relink_command="cd `pwd`; $relink_command"
+	relink_command="(cd `pwd`; $relink_command)"
 	relink_command=`$echo "X$relink_command" | $Xsed -e "$sed_quote_subst"`
       fi
 
       # Quote $echo for shipping.
-      if test "X$echo" = "X$SHELL $0 --fallback-echo"; then
-	case $0 in
-	[\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $0 --fallback-echo";;
-	*) qecho="$SHELL `pwd`/$0 --fallback-echo";;
+      if test "X$echo" = "X$SHELL $progpath --fallback-echo"; then
+	case $progpath in
+	[\\/]* | [A-Za-z]:[\\/]*) qecho="$SHELL $progpath --fallback-echo";;
+	*) qecho="$SHELL `pwd`/$progpath --fallback-echo";;
 	esac
 	qecho=`$echo "X$qecho" | $Xsed -e "$sed_quote_subst"`
       else
@@ -3985,15 +4952,376 @@
 	# win32 will think the script is a binary if it has
 	# a .exe suffix, so we strip it off here.
 	case $output in
-	  *.exe) output=`echo $output|sed 's,.exe$,,'` ;;
+	  *.exe) output=`$echo $output|${SED} 's,.exe$,,'` ;;
 	esac
 	# test for cygwin because mv fails w/o .exe extensions
 	case $host in
-	  *cygwin*) exeext=.exe ;;
+	  *cygwin*)
+	    exeext=.exe
+	    outputname=`$echo $outputname|${SED} 's,.exe$,,'` ;;
 	  *) exeext= ;;
 	esac
-	$rm $output
-	trap "$rm $output; exit 1" 1 2 15
+	case $host in
+	  *cygwin* | *mingw* )
+            output_name=`basename $output`
+            output_path=`dirname $output`
+            cwrappersource="$output_path/$objdir/lt-$output_name.c"
+            cwrapper="$output_path/$output_name.exe"
+            $rm $cwrappersource $cwrapper
+            trap "$rm $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15
+
+	    cat > $cwrappersource <<EOF
+
+/* $cwrappersource - temporary wrapper executable for $objdir/$outputname
+   Generated by $PROGRAM - GNU $PACKAGE $VERSION$TIMESTAMP
+
+   The $output program cannot be directly executed until all the libtool
+   libraries that it depends on are installed.
+
+   This wrapper executable should never be moved out of the build directory.
+   If it is, it will not operate correctly.
+
+   Currently, it simply execs the wrapper *script* "/bin/sh $output",
+   but could eventually absorb all of the scripts functionality and
+   exec $objdir/$outputname directly.
+*/
+EOF
+	    cat >> $cwrappersource<<"EOF"
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <malloc.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/stat.h>
+
+#if defined(PATH_MAX)
+# define LT_PATHMAX PATH_MAX
+#elif defined(MAXPATHLEN)
+# define LT_PATHMAX MAXPATHLEN
+#else
+# define LT_PATHMAX 1024
+#endif
+
+#ifndef DIR_SEPARATOR
+# define DIR_SEPARATOR '/'
+# define PATH_SEPARATOR ':'
+#endif
+
+#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
+  defined (__OS2__)
+# define HAVE_DOS_BASED_FILE_SYSTEM
+# ifndef DIR_SEPARATOR_2
+#  define DIR_SEPARATOR_2 '\\'
+# endif
+# ifndef PATH_SEPARATOR_2
+#  define PATH_SEPARATOR_2 ';'
+# endif
+#endif
+
+#ifndef DIR_SEPARATOR_2
+# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
+#else /* DIR_SEPARATOR_2 */
+# define IS_DIR_SEPARATOR(ch) \
+        (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+#endif /* DIR_SEPARATOR_2 */
+
+#ifndef PATH_SEPARATOR_2
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)
+#else /* PATH_SEPARATOR_2 */
+# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)
+#endif /* PATH_SEPARATOR_2 */
+
+#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))
+#define XFREE(stale) do { \
+  if (stale) { free ((void *) stale); stale = 0; } \
+} while (0)
+
+/* -DDEBUG is fairly common in CFLAGS.  */
+#undef DEBUG
+#if defined DEBUGWRAPPER
+# define DEBUG(format, ...) fprintf(stderr, format, __VA_ARGS__)
+#else
+# define DEBUG(format, ...)
+#endif
+
+const char *program_name = NULL;
+
+void * xmalloc (size_t num);
+char * xstrdup (const char *string);
+const char * base_name (const char *name);
+char * find_executable(const char *wrapper);
+int    check_executable(const char *path);
+char * strendzap(char *str, const char *pat);
+void lt_fatal (const char *message, ...);
+
+int
+main (int argc, char *argv[])
+{
+  char **newargz;
+  int i;
+
+  program_name = (char *) xstrdup (base_name (argv[0]));
+  DEBUG("(main) argv[0]      : %s\n",argv[0]);
+  DEBUG("(main) program_name : %s\n",program_name);
+  newargz = XMALLOC(char *, argc+2);
+EOF
+
+            cat >> $cwrappersource <<EOF
+  newargz[0] = (char *) xstrdup("$SHELL");
+EOF
+
+            cat >> $cwrappersource <<"EOF"
+  newargz[1] = find_executable(argv[0]);
+  if (newargz[1] == NULL)
+    lt_fatal("Couldn't find %s", argv[0]);
+  DEBUG("(main) found exe at : %s\n",newargz[1]);
+  /* we know the script has the same name, without the .exe */
+  /* so make sure newargz[1] doesn't end in .exe */
+  strendzap(newargz[1],".exe");
+  for (i = 1; i < argc; i++)
+    newargz[i+1] = xstrdup(argv[i]);
+  newargz[argc+1] = NULL;
+
+  for (i=0; i<argc+1; i++)
+  {
+    DEBUG("(main) newargz[%d]   : %s\n",i,newargz[i]);
+    ;
+  }
+
+EOF
+
+            case $host_os in
+              mingw*)
+                cat >> $cwrappersource <<EOF
+  execv("$SHELL",(char const **)newargz);
+EOF
+              ;;
+              *)
+                cat >> $cwrappersource <<EOF
+  execv("$SHELL",newargz);
+EOF
+              ;;
+            esac
+
+            cat >> $cwrappersource <<"EOF"
+  return 127;
+}
+
+void *
+xmalloc (size_t num)
+{
+  void * p = (void *) malloc (num);
+  if (!p)
+    lt_fatal ("Memory exhausted");
+
+  return p;
+}
+
+char *
+xstrdup (const char *string)
+{
+  return string ? strcpy ((char *) xmalloc (strlen (string) + 1), string) : NULL
+;
+}
+
+const char *
+base_name (const char *name)
+{
+  const char *base;
+
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  /* Skip over the disk name in MSDOS pathnames. */
+  if (isalpha ((unsigned char)name[0]) && name[1] == ':')
+    name += 2;
+#endif
+
+  for (base = name; *name; name++)
+    if (IS_DIR_SEPARATOR (*name))
+      base = name + 1;
+  return base;
+}
+
+int
+check_executable(const char * path)
+{
+  struct stat st;
+
+  DEBUG("(check_executable)  : %s\n", path ? (*path ? path : "EMPTY!") : "NULL!");
+  if ((!path) || (!*path))
+    return 0;
+
+  if ((stat (path, &st) >= 0) &&
+      (
+        /* MinGW & native WIN32 do not support S_IXOTH or S_IXGRP */
+#if defined (S_IXOTH)
+       ((st.st_mode & S_IXOTH) == S_IXOTH) ||
+#endif
+#if defined (S_IXGRP)
+       ((st.st_mode & S_IXGRP) == S_IXGRP) ||
+#endif
+       ((st.st_mode & S_IXUSR) == S_IXUSR))
+      )
+    return 1;
+  else
+    return 0;
+}
+
+/* Searches for the full path of the wrapper.  Returns
+   newly allocated full path name if found, NULL otherwise */
+char *
+find_executable (const char* wrapper)
+{
+  int has_slash = 0;
+  const char* p;
+  const char* p_next;
+  /* static buffer for getcwd */
+  char tmp[LT_PATHMAX + 1];
+  int tmp_len;
+  char* concat_name;
+
+  DEBUG("(find_executable)  : %s\n", wrapper ? (*wrapper ? wrapper : "EMPTY!") : "NULL!");
+
+  if ((wrapper == NULL) || (*wrapper == '\0'))
+    return NULL;
+
+  /* Absolute path? */
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  if (isalpha ((unsigned char)wrapper[0]) && wrapper[1] == ':')
+  {
+    concat_name = xstrdup (wrapper);
+    if (check_executable(concat_name))
+      return concat_name;
+    XFREE(concat_name);
+  }
+  else
+  {
+#endif
+    if (IS_DIR_SEPARATOR (wrapper[0]))
+    {
+      concat_name = xstrdup (wrapper);
+      if (check_executable(concat_name))
+        return concat_name;
+      XFREE(concat_name);
+    }
+#if defined (HAVE_DOS_BASED_FILE_SYSTEM)
+  }
+#endif
+
+  for (p = wrapper; *p; p++)
+    if (*p == '/')
+    {
+      has_slash = 1;
+      break;
+    }
+  if (!has_slash)
+  {
+    /* no slashes; search PATH */
+    const char* path = getenv ("PATH");
+    if (path != NULL)
+    {
+      for (p = path; *p; p = p_next)
+      {
+        const char* q;
+        size_t p_len;
+        for (q = p; *q; q++)
+          if (IS_PATH_SEPARATOR(*q))
+            break;
+        p_len = q - p;
+        p_next = (*q == '\0' ? q : q + 1);
+        if (p_len == 0)
+        {
+          /* empty path: current directory */
+          if (getcwd (tmp, LT_PATHMAX) == NULL)
+            lt_fatal ("getcwd failed");
+          tmp_len = strlen(tmp);
+          concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1);
+          memcpy (concat_name, tmp, tmp_len);
+          concat_name[tmp_len] = '/';
+          strcpy (concat_name + tmp_len + 1, wrapper);
+        }
+        else
+        {
+          concat_name = XMALLOC(char, p_len + 1 + strlen(wrapper) + 1);
+          memcpy (concat_name, p, p_len);
+          concat_name[p_len] = '/';
+          strcpy (concat_name + p_len + 1, wrapper);
+        }
+        if (check_executable(concat_name))
+          return concat_name;
+        XFREE(concat_name);
+      }
+    }
+    /* not found in PATH; assume curdir */
+  }
+  /* Relative path | not found in path: prepend cwd */
+  if (getcwd (tmp, LT_PATHMAX) == NULL)
+    lt_fatal ("getcwd failed");
+  tmp_len = strlen(tmp);
+  concat_name = XMALLOC(char, tmp_len + 1 + strlen(wrapper) + 1);
+  memcpy (concat_name, tmp, tmp_len);
+  concat_name[tmp_len] = '/';
+  strcpy (concat_name + tmp_len + 1, wrapper);
+
+  if (check_executable(concat_name))
+    return concat_name;
+  XFREE(concat_name);
+  return NULL;
+}
+
+char *
+strendzap(char *str, const char *pat)
+{
+  size_t len, patlen;
+
+  assert(str != NULL);
+  assert(pat != NULL);
+
+  len = strlen(str);
+  patlen = strlen(pat);
+
+  if (patlen <= len)
+  {
+    str += len - patlen;
+    if (strcmp(str, pat) == 0)
+      *str = '\0';
+  }
+  return str;
+}
+
+static void
+lt_error_core (int exit_status, const char * mode,
+          const char * message, va_list ap)
+{
+  fprintf (stderr, "%s: %s: ", program_name, mode);
+  vfprintf (stderr, message, ap);
+  fprintf (stderr, ".\n");
+
+  if (exit_status >= 0)
+    exit (exit_status);
+}
+
+void
+lt_fatal (const char *message, ...)
+{
+  va_list ap;
+  va_start (ap, message);
+  lt_error_core (EXIT_FAILURE, "FATAL", message, ap);
+  va_end (ap);
+}
+EOF
+          # we should really use a build-platform specific compiler
+          # here, but OTOH, the wrappers (shell script and this C one)
+          # are only useful if you want to execute the "real" binary.
+          # Since the "real" binary is built for $host, then this
+          # wrapper might as well be built for $host, too.
+          $run $LTCC $LTCFLAGS -s -o $cwrapper $cwrappersource
+          ;;
+        esac
+        $rm $output
+        trap "$rm $output; exit $EXIT_FAILURE" 1 2 15
 
 	$echo > $output "\
 #! $SHELL
@@ -4009,12 +5337,12 @@
 
 # Sed substitution that helps us do robust quoting.  It backslashifies
 # metacharacters that are still active within double-quoted strings.
-Xsed='sed -e 1s/^X//'
+Xsed='${SED} -e 1s/^X//'
 sed_quote_subst='$sed_quote_subst'
 
 # The HP-UX ksh and POSIX shell print the target directory to stdout
 # if CDPATH is set.
-if test \"\${CDPATH+set}\" = set; then CDPATH=:; export CDPATH; fi
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
 
 relink_command=\"$relink_command\"
 
@@ -4047,7 +5375,7 @@
   test \"x\$thisdir\" = \"x\$file\" && thisdir=.
 
   # Follow symbolic links until we get to the real thisdir.
-  file=\`ls -ld \"\$file\" | sed -n 's/.*-> //p'\`
+  file=\`ls -ld \"\$file\" | ${SED} -n 's/.*-> //p'\`
   while test -n \"\$file\"; do
     destdir=\`\$echo \"X\$file\" | \$Xsed -e 's%/[^/]*\$%%'\`
 
@@ -4060,7 +5388,7 @@
     fi
 
     file=\`\$echo \"X\$file\" | \$Xsed -e 's%^.*/%%'\`
-    file=\`ls -ld \"\$thisdir/\$file\" | sed -n 's/.*-> //p'\`
+    file=\`ls -ld \"\$thisdir/\$file\" | ${SED} -n 's/.*-> //p'\`
   done
 
   # Try to get the absolute directory name.
@@ -4069,12 +5397,12 @@
 "
 
 	if test "$fast_install" = yes; then
-	  echo >> $output "\
+	  $echo >> $output "\
   program=lt-'$outputname'$exeext
   progdir=\"\$thisdir/$objdir\"
 
   if test ! -f \"\$progdir/\$program\" || \\
-     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | sed 1q\`; \\
+     { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\
        test \"X\$file\" != \"X\$progdir/\$program\"; }; then
 
     file=\"\$\$-\$program\"
@@ -4085,15 +5413,15 @@
       $rm \"\$progdir/\$file\"
     fi"
 
-	  echo >> $output "\
+	  $echo >> $output "\
 
     # relink executable if necessary
     if test -n \"\$relink_command\"; then
       if relink_command_output=\`eval \$relink_command 2>&1\`; then :
       else
-        $echo \"\$relink_command_output\" >&2
+	$echo \"\$relink_command_output\" >&2
 	$rm \"\$progdir/\$file\"
-	exit 1
+	exit $EXIT_FAILURE
       fi
     fi
 
@@ -4103,13 +5431,13 @@
     $rm \"\$progdir/\$file\"
   fi"
 	else
-	  echo >> $output "\
+	  $echo >> $output "\
   program='$outputname'
   progdir=\"\$thisdir/$objdir\"
 "
 	fi
 
-	echo >> $output "\
+	$echo >> $output "\
 
   if test -f \"\$progdir/\$program\"; then"
 
@@ -4140,47 +5468,35 @@
       # Run the actual program with our arguments.
 "
 	case $host in
-	# win32 systems need to use the prog path for dll
-	# lookup to work
-	*-*-cygwin* | *-*-pw32*)
-	  $echo >> $output "\
-      exec \$progdir/\$program \${1+\"\$@\"}
-"
-	  ;;
-
 	# Backslashes separate directories on plain windows
 	*-*-mingw | *-*-os2*)
 	  $echo >> $output "\
-      exec \$progdir\\\\\$program \${1+\"\$@\"}
+      exec \"\$progdir\\\\\$program\" \${1+\"\$@\"}
 "
 	  ;;
 
 	*)
 	  $echo >> $output "\
-      # Export the path to the program.
-      PATH=\"\$progdir:\$PATH\"
-      export PATH
-
-      exec \$program \${1+\"\$@\"}
+      exec \"\$progdir/\$program\" \${1+\"\$@\"}
 "
 	  ;;
 	esac
 	$echo >> $output "\
       \$echo \"\$0: cannot exec \$program \${1+\"\$@\"}\"
-      exit 1
+      exit $EXIT_FAILURE
     fi
   else
     # The program doesn't exist.
-    \$echo \"\$0: error: \$progdir/\$program does not exist\" 1>&2
+    \$echo \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2
     \$echo \"This script is just a wrapper for \$program.\" 1>&2
-    echo \"See the $PACKAGE documentation for more information.\" 1>&2
-    exit 1
+    $echo \"See the $PACKAGE documentation for more information.\" 1>&2
+    exit $EXIT_FAILURE
   fi
 fi\
 "
 	chmod +x $output
       fi
-      exit 0
+      exit $EXIT_SUCCESS
       ;;
     esac
 
@@ -4196,106 +5512,130 @@
 	  oldobjs="$libobjs_save"
 	  build_libtool_libs=no
 	else
-	  oldobjs="$objs$old_deplibs $non_pic_objects"
+	  oldobjs="$old_deplibs $non_pic_objects"
 	fi
 	addlibs="$old_convenience"
       fi
 
       if test -n "$addlibs"; then
 	gentop="$output_objdir/${outputname}x"
-	$show "${rm}r $gentop"
-	$run ${rm}r "$gentop"
-	$show "$mkdir $gentop"
-	$run $mkdir "$gentop"
-	status=$?
-	if test $status -ne 0 && test ! -d "$gentop"; then
-	  exit $status
-	fi
 	generated="$generated $gentop"
 
-	# Add in members from convenience archives.
-	for xlib in $addlibs; do
-	  # Extract the objects.
-	  case $xlib in
-	  [\\/]* | [A-Za-z]:[\\/]*) xabs="$xlib" ;;
-	  *) xabs=`pwd`"/$xlib" ;;
-	  esac
-	  xlib=`$echo "X$xlib" | $Xsed -e 's%^.*/%%'`
-	  xdir="$gentop/$xlib"
-
-	  $show "${rm}r $xdir"
-	  $run ${rm}r "$xdir"
-	  $show "$mkdir $xdir"
-	  $run $mkdir "$xdir"
-	  status=$?
-	  if test $status -ne 0 && test ! -d "$xdir"; then
-	    exit $status
-	  fi
-	  $show "(cd $xdir && $AR x $xabs)"
-	  $run eval "(cd \$xdir && $AR x \$xabs)" || exit $?
-
-	  oldobjs="$oldobjs "`find $xdir -name \*.${objext} -print | $NL2SP`
-	done
+	func_extract_archives $gentop $addlibs
+	oldobjs="$oldobjs $func_extract_archives_result"
       fi
 
       # Do each command in the archive commands.
       if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then
-	eval cmds=\"$old_archive_from_new_cmds\"
+       cmds=$old_archive_from_new_cmds
       else
-#	# Ensure that we have .o objects in place in case we decided
-#	# not to build a shared library, and have fallen back to building
-#	# static libs even though --disable-static was passed!
-#	for oldobj in $oldobjs; do
-#	  if test ! -f $oldobj; then
-#	    xdir=`$echo "X$oldobj" | $Xsed -e 's%/[^/]*$%%'`
-#	    if test "X$xdir" = "X$oldobj"; then
-#	      xdir="."
-#	    else
-#	      xdir="$xdir"
-#	    fi
-#	    baseobj=`$echo "X$oldobj" | $Xsed -e 's%^.*/%%'`
-#	    obj=`$echo "X$baseobj" | $Xsed -e "$o2lo"`
-#	    $show "(cd $xdir && ${LN_S} $obj $baseobj)"
-#	    $run eval '(cd $xdir && ${LN_S} $obj $baseobj)' || exit $?
-#	  fi
-#	done
+	# POSIX demands no paths to be encoded in archives.  We have
+	# to avoid creating archives with duplicate basenames if we
+	# might have to extract them afterwards, e.g., when creating a
+	# static archive out of a convenience library, or when linking
+	# the entirety of a libtool archive into another (currently
+	# not supported by libtool).
+	if (for obj in $oldobjs
+	    do
+	      $echo "X$obj" | $Xsed -e 's%^.*/%%'
+	    done | sort | sort -uc >/dev/null 2>&1); then
+	  :
+	else
+	  $echo "copying selected object files to avoid basename conflicts..."
 
-        eval cmds=\"$old_archive_cmds\"
+	  if test -z "$gentop"; then
+	    gentop="$output_objdir/${outputname}x"
+	    generated="$generated $gentop"
 
-        if len=`expr "X$cmds" : ".*"` &&
-             test $len -le $max_cmd_len; then
-          :
-        else
-          # the command line is too long to link in one step, link in parts
-          $echo "using piecewise archive linking..."
+	    $show "${rm}r $gentop"
+	    $run ${rm}r "$gentop"
+	    $show "$mkdir $gentop"
+	    $run $mkdir "$gentop"
+	    exit_status=$?
+	    if test "$exit_status" -ne 0 && test ! -d "$gentop"; then
+	      exit $exit_status
+	    fi
+	  fi
+
+	  save_oldobjs=$oldobjs
+	  oldobjs=
+	  counter=1
+	  for obj in $save_oldobjs
+	  do
+	    objbase=`$echo "X$obj" | $Xsed -e 's%^.*/%%'`
+	    case " $oldobjs " in
+	    " ") oldobjs=$obj ;;
+	    *[\ /]"$objbase "*)
+	      while :; do
+		# Make sure we don't pick an alternate name that also
+		# overlaps.
+		newobj=lt$counter-$objbase
+		counter=`expr $counter + 1`
+		case " $oldobjs " in
+		*[\ /]"$newobj "*) ;;
+		*) if test ! -f "$gentop/$newobj"; then break; fi ;;
+		esac
+	      done
+	      $show "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj"
+	      $run ln "$obj" "$gentop/$newobj" ||
+	      $run cp "$obj" "$gentop/$newobj"
+	      oldobjs="$oldobjs $gentop/$newobj"
+	      ;;
+	    *) oldobjs="$oldobjs $obj" ;;
+	    esac
+	  done
+	fi
+
+	eval cmds=\"$old_archive_cmds\"
+
+	if len=`expr "X$cmds" : ".*"` &&
+	     test "$len" -le "$max_cmd_len" || test "$max_cmd_len" -le -1; then
+	  cmds=$old_archive_cmds
+	else
+	  # the command line is too long to link in one step, link in parts
+	  $echo "using piecewise archive linking..."
 	  save_RANLIB=$RANLIB
 	  RANLIB=:
-          objlist=
-          concat_cmds=
-          save_oldobjs=$oldobjs
-          for obj in $save_oldobjs
-          do
-            oldobjs="$objlist $obj"
-            objlist="$objlist $obj"
-            eval test_cmds=\"$old_archive_cmds\"
-            if len=`expr "X$test_cmds" : ".*"` &&
-               test $len -le $max_cmd_len; then
-              :
-            else
-              # the above command should be used before it gets too long
-              oldobjs=$objlist
+	  objlist=
+	  concat_cmds=
+	  save_oldobjs=$oldobjs
+
+	  # Is there a better way of finding the last object in the list?
+	  for obj in $save_oldobjs
+	  do
+	    last_oldobj=$obj
+	  done
+	  for obj in $save_oldobjs
+	  do
+	    oldobjs="$objlist $obj"
+	    objlist="$objlist $obj"
+	    eval test_cmds=\"$old_archive_cmds\"
+	    if len=`expr "X$test_cmds" : ".*" 2>/dev/null` &&
+	       test "$len" -le "$max_cmd_len"; then
+	      :
+	    else
+	      # the above command should be used before it gets too long
+	      oldobjs=$objlist
+	      if test "$obj" = "$last_oldobj" ; then
+	        RANLIB=$save_RANLIB
+	      fi
 	      test -z "$concat_cmds" || concat_cmds=$concat_cmds~
-              eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\"
-              objlist=
-            fi
-          done
+	      eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\"
+	      objlist=
+	    fi
+	  done
 	  RANLIB=$save_RANLIB
-          oldobjs=$objlist
-          eval cmds=\"\$concat_cmds~$old_archive_cmds\"
-        fi
+	  oldobjs=$objlist
+	  if test "X$oldobjs" = "X" ; then
+	    eval cmds=\"\$concat_cmds\"
+	  else
+	    eval cmds=\"\$concat_cmds~\$old_archive_cmds\"
+	  fi
+	fi
       fi
-      IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
+      save_ifs="$IFS"; IFS='~'
       for cmd in $cmds; do
+        eval cmd=\"$cmd\"
 	IFS="$save_ifs"
 	$show "$cmd"
 	$run eval "$cmd" || exit $?
@@ -4327,8 +5667,12 @@
 	fi
       done
       # Quote the link command for shipping.
-      relink_command="cd `pwd`; $SHELL $0 --mode=relink $libtool_args"
+      relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)"
       relink_command=`$echo "X$relink_command" | $Xsed -e "$sed_quote_subst"`
+      if test "$hardcode_automatic" = yes ; then
+	relink_command=
+      fi
+
 
       # Only create the output if not a dry run.
       if test -z "$run"; then
@@ -4344,10 +5688,10 @@
 	      case $deplib in
 	      *.la)
 		name=`$echo "X$deplib" | $Xsed -e 's%^.*/%%'`
-		eval libdir=`sed -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
+		eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib`
 		if test -z "$libdir"; then
 		  $echo "$modename: \`$deplib' is not a valid libtool archive" 1>&2
-		  exit 1
+		  exit $EXIT_FAILURE
 		fi
 		newdependency_libs="$newdependency_libs $libdir/$name"
 		;;
@@ -4358,10 +5702,10 @@
 	    newdlfiles=
 	    for lib in $dlfiles; do
 	      name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'`
-	      eval libdir=`sed -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+	      eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
 	      if test -z "$libdir"; then
 		$echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
-		exit 1
+		exit $EXIT_FAILURE
 	      fi
 	      newdlfiles="$newdlfiles $libdir/$name"
 	    done
@@ -4369,20 +5713,39 @@
 	    newdlprefiles=
 	    for lib in $dlprefiles; do
 	      name=`$echo "X$lib" | $Xsed -e 's%^.*/%%'`
-	      eval libdir=`sed -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
+	      eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib`
 	      if test -z "$libdir"; then
 		$echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
-		exit 1
+		exit $EXIT_FAILURE
 	      fi
 	      newdlprefiles="$newdlprefiles $libdir/$name"
 	    done
 	    dlprefiles="$newdlprefiles"
+	  else
+	    newdlfiles=
+	    for lib in $dlfiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      newdlfiles="$newdlfiles $abs"
+	    done
+	    dlfiles="$newdlfiles"
+	    newdlprefiles=
+	    for lib in $dlprefiles; do
+	      case $lib in
+		[\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;;
+		*) abs=`pwd`"/$lib" ;;
+	      esac
+	      newdlprefiles="$newdlprefiles $abs"
+	    done
+	    dlprefiles="$newdlprefiles"
 	  fi
 	  $rm $output
 	  # place dlname in correct position for cygwin
 	  tdlname=$dlname
 	  case $host,$output,$installed,$module,$dlname in
-	    *cygwin*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
+	    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll) tdlname=../bin/$dlname ;;
 	  esac
 	  $echo > $output "\
 # $outputname - a libtool library file
@@ -4411,13 +5774,16 @@
 # Is this an already installed library?
 installed=$installed
 
+# Should we warn about portability when linking against -modules?
+shouldnotlink=$module
+
 # Files to dlopen/dlpreopen
 dlopen='$dlfiles'
 dlpreopen='$dlprefiles'
 
 # Directory that this library needs to be installed in:
 libdir='$install_libdir'"
-	  if test "$installed" = no && test $need_relink = yes; then
+	  if test "$installed" = no && test "$need_relink" = yes; then
 	    $echo >> $output "\
 relink_command=\"$relink_command\""
 	  fi
@@ -4430,7 +5796,7 @@
       $run eval '(cd $output_objdir && $rm $outputname && $LN_S ../$outputname $outputname)' || exit $?
       ;;
     esac
-    exit 0
+    exit $EXIT_SUCCESS
     ;;
 
   # libtool install mode
@@ -4441,11 +5807,11 @@
     # install_prog (especially on Windows NT).
     if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh ||
        # Allow the use of GNU shtool's install command.
-       $echo "X$nonopt" | $Xsed | grep shtool > /dev/null; then
+       $echo "X$nonopt" | grep shtool > /dev/null; then
       # Aesthetically quote it.
       arg=`$echo "X$nonopt" | $Xsed -e "$sed_quote_subst"`
       case $arg in
-      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
 	arg="\"$arg\""
 	;;
       esac
@@ -4454,14 +5820,14 @@
       shift
     else
       install_prog=
-      arg="$nonopt"
+      arg=$nonopt
     fi
 
     # The real first argument should be the name of the installation program.
     # Aesthetically quote it.
     arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
     case $arg in
-    *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
+    *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
       arg="\"$arg\""
       ;;
     esac
@@ -4479,28 +5845,31 @@
     do
       if test -n "$dest"; then
 	files="$files $dest"
-	dest="$arg"
+	dest=$arg
 	continue
       fi
 
       case $arg in
       -d) isdir=yes ;;
-      -f) prev="-f" ;;
-      -g) prev="-g" ;;
-      -m) prev="-m" ;;
-      -o) prev="-o" ;;
+      -f) 
+      	case " $install_prog " in
+	*[\\\ /]cp\ *) ;;
+	*) prev=$arg ;;
+	esac
+	;;
+      -g | -m | -o) prev=$arg ;;
       -s)
 	stripme=" -s"
 	continue
 	;;
-      -*) ;;
-
+      -*)
+	;;
       *)
 	# If the previous option needed an argument, then skip it.
 	if test -n "$prev"; then
 	  prev=
 	else
-	  dest="$arg"
+	  dest=$arg
 	  continue
 	fi
 	;;
@@ -4509,7 +5878,7 @@
       # Aesthetically quote the argument.
       arg=`$echo "X$arg" | $Xsed -e "$sed_quote_subst"`
       case $arg in
-      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*)
+      *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \	]*|*]*|"")
 	arg="\"$arg\""
 	;;
       esac
@@ -4519,13 +5888,13 @@
     if test -z "$install_prog"; then
       $echo "$modename: you must specify an install program" 1>&2
       $echo "$help" 1>&2
-      exit 1
+      exit $EXIT_FAILURE
     fi
 
     if test -n "$prev"; then
       $echo "$modename: the \`$prev' option requires an argument" 1>&2
       $echo "$help" 1>&2
-      exit 1
+      exit $EXIT_FAILURE
     fi
 
     if test -z "$files"; then
@@ -4535,11 +5904,19 @@
 	$echo "$modename: you must specify a destination" 1>&2
       fi
       $echo "$help" 1>&2
-      exit 1
+      exit $EXIT_FAILURE
     fi
 
-    # Strip any trailing slash from the destination.
-    dest=`$echo "X$dest" | $Xsed -e 's%/$%%'`
+    # Canonicalise the pathname:
+    #   - remove foo/../
+    #   - replace //
+    #   - remove /./
+    #   - strip any trailing /
+    tmp=""
+    while test "$dest" != "$tmp";  do
+      tmp=$dest
+      dest=`$echo "X$dest" | $Xsed -e 's%[^/.][^/.]*/\.\.%%g' -e 's%/\./%/%g' -e 's%//*%/%g' -e 's%/$%%g'`
+    done
 
     # Check to see that the destination is a directory.
     test -d "$dest" && isdir=yes
@@ -4553,10 +5930,10 @@
 
       # Not a directory, so check to see that there is only one file specified.
       set dummy $files
-      if test $# -gt 2; then
+      if test "$#" -gt 2; then
 	$echo "$modename: \`$dest' is not a directory" 1>&2
 	$echo "$help" 1>&2
-	exit 1
+	exit $EXIT_FAILURE
       fi
     fi
     case $destdir in
@@ -4568,7 +5945,7 @@
 	*)
 	  $echo "$modename: \`$destdir' must be an absolute directory name" 1>&2
 	  $echo "$help" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	  ;;
 	esac
       done
@@ -4593,11 +5970,11 @@
 
       *.la)
 	# Check to see that this really is a libtool archive.
-	if (sed -e '2q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
+	if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
 	else
 	  $echo "$modename: \`$file' is not a valid libtool archive" 1>&2
 	  $echo "$help" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 
 	library_names=
@@ -4628,12 +6005,33 @@
 	dir="$dir$objdir"
 
 	if test -n "$relink_command"; then
+	  # Determine the prefix the user has applied to our future dir.
+	  inst_prefix_dir=`$echo "$destdir" | $SED "s%$libdir\$%%"`
+
+	  # Don't allow the user to place us outside of our expected
+	  # location b/c this prevents finding dependent libraries that
+	  # are installed to the same prefix.
+	  # At present, this check doesn't affect windows .dll's that
+	  # are installed into $libdir/../bin (currently, that works fine)
+	  # but it's something to keep an eye on.
+	  if test "$inst_prefix_dir" = "$destdir"; then
+	    $echo "$modename: error: cannot install \`$file' to a directory not ending in $libdir" 1>&2
+	    exit $EXIT_FAILURE
+	  fi
+
+	  if test -n "$inst_prefix_dir"; then
+	    # Stick the inst_prefix_dir data into the link command.
+	    relink_command=`$echo "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"`
+	  else
+	    relink_command=`$echo "$relink_command" | $SED "s%@inst_prefix_dir@%%"`
+	  fi
+
 	  $echo "$modename: warning: relinking \`$file'" 1>&2
 	  $show "$relink_command"
 	  if $run eval "$relink_command"; then :
 	  else
 	    $echo "$modename: error: relink \`$file' with the above command before installing it" 1>&2
-	    continue
+	    exit $EXIT_FAILURE
 	  fi
 	fi
 
@@ -4655,25 +6053,38 @@
 	    $run eval "$striplib $destdir/$realname" || exit $?
 	  fi
 
-	  if test $# -gt 0; then
+	  if test "$#" -gt 0; then
 	    # Delete the old symlinks, and create new ones.
+	    # Try `ln -sf' first, because the `ln' binary might depend on
+	    # the symlink we replace!  Solaris /bin/ln does not understand -f,
+	    # so we also need to try rm && ln -s.
 	    for linkname
 	    do
 	      if test "$linkname" != "$realname"; then
-		$show "(cd $destdir && $rm $linkname && $LN_S $realname $linkname)"
-		$run eval "(cd $destdir && $rm $linkname && $LN_S $realname $linkname)"
+                $show "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })"
+                $run eval "(cd $destdir && { $LN_S -f $realname $linkname || { $rm $linkname && $LN_S $realname $linkname; }; })"
 	      fi
 	    done
 	  fi
 
 	  # Do each command in the postinstall commands.
 	  lib="$destdir/$realname"
-	  eval cmds=\"$postinstall_cmds\"
-	  IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
+	  cmds=$postinstall_cmds
+	  save_ifs="$IFS"; IFS='~'
 	  for cmd in $cmds; do
 	    IFS="$save_ifs"
+	    eval cmd=\"$cmd\"
 	    $show "$cmd"
-	    $run eval "$cmd" || exit $?
+	    $run eval "$cmd" || {
+	      lt_exit=$?
+
+	      # Restore the uninstalled library and exit
+	      if test "$mode" = relink; then
+		$run eval '(cd $output_objdir && $rm ${realname}T && $mv ${realname}U $realname)'
+	      fi
+
+	      exit $lt_exit
+	    }
 	  done
 	  IFS="$save_ifs"
 	fi
@@ -4711,7 +6122,7 @@
 	*)
 	  $echo "$modename: cannot copy a libtool object to \`$destfile'" 1>&2
 	  $echo "$help" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	  ;;
 	esac
 
@@ -4729,7 +6140,7 @@
 	  $show "$install_prog $staticobj $staticdest"
 	  $run eval "$install_prog \$staticobj \$staticdest" || exit $?
 	fi
-	exit 0
+	exit $EXIT_SUCCESS
 	;;
 
       *)
@@ -4741,21 +6152,47 @@
 	  destfile="$destdir/$destfile"
 	fi
 
+	# If the file is missing, and there is a .exe on the end, strip it
+	# because it is most likely a libtool script we actually want to
+	# install
+	stripped_ext=""
+	case $file in
+	  *.exe)
+	    if test ! -f "$file"; then
+	      file=`$echo $file|${SED} 's,.exe$,,'`
+	      stripped_ext=".exe"
+	    fi
+	    ;;
+	esac
+
 	# Do a test to see if this is really a libtool program.
-	if (sed -e '4q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
+	case $host in
+	*cygwin*|*mingw*)
+	    wrapper=`$echo $file | ${SED} -e 's,.exe$,,'`
+	    ;;
+	*)
+	    wrapper=$file
+	    ;;
+	esac
+	if (${SED} -e '4q' $wrapper | grep "^# Generated by .*$PACKAGE")>/dev/null 2>&1; then
 	  notinst_deplibs=
 	  relink_command=
 
+	  # Note that it is not necessary on cygwin/mingw to append a dot to
+	  # foo even if both foo and FILE.exe exist: automatic-append-.exe
+	  # behavior happens only for exec(3), not for open(2)!  Also, sourcing
+	  # `FILE.' does not work on cygwin managed mounts.
+	  #
 	  # If there is no directory component, then add one.
-	  case $file in
-	  */* | *\\*) . $file ;;
-	  *) . ./$file ;;
+	  case $wrapper in
+	  */* | *\\*) . ${wrapper} ;;
+	  *) . ./${wrapper} ;;
 	  esac
 
 	  # Check the variables that should have been set.
 	  if test -z "$notinst_deplibs"; then
-	    $echo "$modename: invalid libtool wrapper script \`$file'" 1>&2
-	    exit 1
+	    $echo "$modename: invalid libtool wrapper script \`$wrapper'" 1>&2
+	    exit $EXIT_FAILURE
 	  fi
 
 	  finalize=yes
@@ -4777,24 +6214,22 @@
 	  done
 
 	  relink_command=
+	  # Note that it is not necessary on cygwin/mingw to append a dot to
+	  # foo even if both foo and FILE.exe exist: automatic-append-.exe
+	  # behavior happens only for exec(3), not for open(2)!  Also, sourcing
+	  # `FILE.' does not work on cygwin managed mounts.
+	  #
 	  # If there is no directory component, then add one.
-	  case $file in
-	  */* | *\\*) . $file ;;
-	  *) . ./$file ;;
+	  case $wrapper in
+	  */* | *\\*) . ${wrapper} ;;
+	  *) . ./${wrapper} ;;
 	  esac
 
 	  outputname=
 	  if test "$fast_install" = no && test -n "$relink_command"; then
 	    if test "$finalize" = yes && test -z "$run"; then
-	      tmpdir="/tmp"
-	      test -n "$TMPDIR" && tmpdir="$TMPDIR"
-	      tmpdir="$tmpdir/libtool-$$"
-	      if $mkdir -p "$tmpdir" && chmod 700 "$tmpdir"; then :
-	      else
-		$echo "$modename: error: cannot create temporary directory \`$tmpdir'" 1>&2
-		continue
-	      fi
-	      file=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
+	      tmpdir=`func_mktempdir`
+	      file=`$echo "X$file$stripped_ext" | $Xsed -e 's%^.*/%%'`
 	      outputname="$tmpdir/$file"
 	      # Replace the output file specification.
 	      relink_command=`$echo "X$relink_command" | $Xsed -e 's%@OUTPUT@%'"$outputname"'%g'`
@@ -4812,13 +6247,12 @@
 	    fi
 	  else
 	    # Install the binary that we compiled earlier.
-	    file=`$echo "X$file" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"`
+	    file=`$echo "X$file$stripped_ext" | $Xsed -e "s%\([^/]*\)$%$objdir/\1%"`
 	  fi
 	fi
 
-
 	# remove .exe since cygwin /usr/bin/install will append another
-	# one anyways
+	# one anyway 
 	case $install_prog,$host in
 	*/usr/bin/install*,*cygwin*)
 	  case $file:$destfile in
@@ -4829,12 +6263,11 @@
 	    destfile=$destfile.exe
 	    ;;
 	  *:*.exe)
-	    destfile=`echo $destfile | sed -e 's,.exe$,,'`
+	    destfile=`$echo $destfile | ${SED} -e 's,.exe$,,'`
 	    ;;
 	  esac
 	  ;;
 	esac
-
 	$show "$install_prog$stripme $file $destfile"
 	$run eval "$install_prog\$stripme \$file \$destfile" || exit $?
 	test -n "$outputname" && ${rm}r "$tmpdir"
@@ -4851,16 +6284,17 @@
       $show "$install_prog $file $oldlib"
       $run eval "$install_prog \$file \$oldlib" || exit $?
 
-      if test -n "$stripme" && test -n "$striplib"; then
+      if test -n "$stripme" && test -n "$old_striplib"; then
 	$show "$old_striplib $oldlib"
 	$run eval "$old_striplib $oldlib" || exit $?
       fi
 
       # Do each command in the postinstall commands.
-      eval cmds=\"$old_postinstall_cmds\"
-      IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
+      cmds=$old_postinstall_cmds
+      save_ifs="$IFS"; IFS='~'
       for cmd in $cmds; do
 	IFS="$save_ifs"
+	eval cmd=\"$cmd\"
 	$show "$cmd"
 	$run eval "$cmd" || exit $?
       done
@@ -4874,9 +6308,9 @@
     if test -n "$current_libdirs"; then
       # Maybe just do a dry run.
       test -n "$run" && current_libdirs=" -n$current_libdirs"
-      exec_cmd='$SHELL $0 --finish$current_libdirs'
+      exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs'
     else
-      exit 0
+      exit $EXIT_SUCCESS
     fi
     ;;
 
@@ -4895,10 +6329,11 @@
       for libdir in $libdirs; do
 	if test -n "$finish_cmds"; then
 	  # Do each command in the finish commands.
-	  eval cmds=\"$finish_cmds\"
-	  IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
+	  cmds=$finish_cmds
+	  save_ifs="$IFS"; IFS='~'
 	  for cmd in $cmds; do
 	    IFS="$save_ifs"
+	    eval cmd=\"$cmd\"
 	    $show "$cmd"
 	    $run eval "$cmd" || admincmds="$admincmds
        $cmd"
@@ -4915,43 +6350,43 @@
     fi
 
     # Exit here if they wanted silent mode.
-    test "$show" = ":" && exit 0
+    test "$show" = : && exit $EXIT_SUCCESS
 
-    echo "----------------------------------------------------------------------"
-    echo "Libraries have been installed in:"
+    $echo "X----------------------------------------------------------------------" | $Xsed
+    $echo "Libraries have been installed in:"
     for libdir in $libdirs; do
-      echo "   $libdir"
+      $echo "   $libdir"
     done
-    echo
-    echo "If you ever happen to want to link against installed libraries"
-    echo "in a given directory, LIBDIR, you must either use libtool, and"
-    echo "specify the full pathname of the library, or use the \`-LLIBDIR'"
-    echo "flag during linking and do at least one of the following:"
+    $echo
+    $echo "If you ever happen to want to link against installed libraries"
+    $echo "in a given directory, LIBDIR, you must either use libtool, and"
+    $echo "specify the full pathname of the library, or use the \`-LLIBDIR'"
+    $echo "flag during linking and do at least one of the following:"
     if test -n "$shlibpath_var"; then
-      echo "   - add LIBDIR to the \`$shlibpath_var' environment variable"
-      echo "     during execution"
+      $echo "   - add LIBDIR to the \`$shlibpath_var' environment variable"
+      $echo "     during execution"
     fi
     if test -n "$runpath_var"; then
-      echo "   - add LIBDIR to the \`$runpath_var' environment variable"
-      echo "     during linking"
+      $echo "   - add LIBDIR to the \`$runpath_var' environment variable"
+      $echo "     during linking"
     fi
     if test -n "$hardcode_libdir_flag_spec"; then
       libdir=LIBDIR
       eval flag=\"$hardcode_libdir_flag_spec\"
 
-      echo "   - use the \`$flag' linker flag"
+      $echo "   - use the \`$flag' linker flag"
     fi
     if test -n "$admincmds"; then
-      echo "   - have your system administrator run these commands:$admincmds"
+      $echo "   - have your system administrator run these commands:$admincmds"
     fi
     if test -f /etc/ld.so.conf; then
-      echo "   - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
+      $echo "   - have your system administrator add LIBDIR to \`/etc/ld.so.conf'"
     fi
-    echo
-    echo "See any operating system documentation about shared libraries for"
-    echo "more information, such as the ld(1) and ld.so(8) manual pages."
-    echo "----------------------------------------------------------------------"
-    exit 0
+    $echo
+    $echo "See any operating system documentation about shared libraries for"
+    $echo "more information, such as the ld(1) and ld.so(8) manual pages."
+    $echo "X----------------------------------------------------------------------" | $Xsed
+    exit $EXIT_SUCCESS
     ;;
 
   # libtool execute mode
@@ -4963,7 +6398,7 @@
     if test -z "$cmd"; then
       $echo "$modename: you must specify a COMMAND" 1>&2
       $echo "$help"
-      exit 1
+      exit $EXIT_FAILURE
     fi
 
     # Handle -dlopen flags immediately.
@@ -4971,18 +6406,18 @@
       if test ! -f "$file"; then
 	$echo "$modename: \`$file' is not a file" 1>&2
 	$echo "$help" 1>&2
-	exit 1
+	exit $EXIT_FAILURE
       fi
 
       dir=
       case $file in
       *.la)
 	# Check to see that this really is a libtool archive.
-	if (sed -e '2q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
+	if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then :
 	else
 	  $echo "$modename: \`$lib' is not a valid libtool archive" 1>&2
 	  $echo "$help" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 
 	# Read the libtool library.
@@ -5009,7 +6444,7 @@
 	  dir="$dir/$objdir"
 	else
 	  $echo "$modename: cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" 1>&2
-	  exit 1
+	  exit $EXIT_FAILURE
 	fi
 	;;
 
@@ -5049,7 +6484,7 @@
       -*) ;;
       *)
 	# Do a test to see if this is really a libtool program.
-	if (sed -e '4q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
+	if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
 	  # If there is no directory component, then add one.
 	  case $file in
 	  */* | *\\*) . $file ;;
@@ -5072,7 +6507,7 @@
 	eval "export $shlibpath_var"
       fi
 
-      # Restore saved enviroment variables
+      # Restore saved environment variables
       if test "${save_LC_ALL+set}" = set; then
 	LC_ALL="$save_LC_ALL"; export LC_ALL
       fi
@@ -5089,7 +6524,7 @@
 	$echo "export $shlibpath_var"
       fi
       $echo "$cmd$args"
-      exit 0
+      exit $EXIT_SUCCESS
     fi
     ;;
 
@@ -5117,24 +6552,25 @@
     if test -z "$rm"; then
       $echo "$modename: you must specify an RM program" 1>&2
       $echo "$help" 1>&2
-      exit 1
+      exit $EXIT_FAILURE
     fi
 
     rmdirs=
 
+    origobjdir="$objdir"
     for file in $files; do
       dir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
       if test "X$dir" = "X$file"; then
 	dir=.
-	objdir="$objdir"
+	objdir="$origobjdir"
       else
-	objdir="$dir/$objdir"
+	objdir="$dir/$origobjdir"
       fi
       name=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
-      test $mode = uninstall && objdir="$dir"
+      test "$mode" = uninstall && objdir="$dir"
 
       # Remember objdir for removal later, being careful to avoid duplicates
-      if test $mode = clean; then
+      if test "$mode" = clean; then
 	case " $rmdirs " in
 	  *" $objdir "*) ;;
 	  *) rmdirs="$rmdirs $objdir" ;;
@@ -5143,14 +6579,14 @@
 
       # Don't error if the file doesn't exist and rm -f was used.
       if (test -L "$file") >/dev/null 2>&1 \
-        || (test -h "$file") >/dev/null 2>&1 \
+	|| (test -h "$file") >/dev/null 2>&1 \
 	|| test -f "$file"; then
-        :
+	:
       elif test -d "$file"; then
-        exit_status=1
+	exit_status=1
 	continue
       elif test "$rmforce" = yes; then
-        continue
+	continue
       fi
 
       rmfiles="$file"
@@ -5158,7 +6594,7 @@
       case $name in
       *.la)
 	# Possibly a libtool archive, so verify it.
-	if (sed -e '2q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
+	if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
 	  . $dir/$name
 
 	  # Delete the libtool libraries and symlinks.
@@ -5166,18 +6602,27 @@
 	    rmfiles="$rmfiles $objdir/$n"
 	  done
 	  test -n "$old_library" && rmfiles="$rmfiles $objdir/$old_library"
-	  test $mode = clean && rmfiles="$rmfiles $objdir/$name $objdir/${name}i"
 
-	  if test $mode = uninstall; then
+	  case "$mode" in
+	  clean)
+	    case "  $library_names " in
+	    # "  " in the beginning catches empty $dlname
+	    *" $dlname "*) ;;
+	    *) rmfiles="$rmfiles $objdir/$dlname" ;;
+	    esac
+	     test -n "$libdir" && rmfiles="$rmfiles $objdir/$name $objdir/${name}i"
+	    ;;
+	  uninstall)
 	    if test -n "$library_names"; then
 	      # Do each command in the postuninstall commands.
-	      eval cmds=\"$postuninstall_cmds\"
-	      IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
+	      cmds=$postuninstall_cmds
+	      save_ifs="$IFS"; IFS='~'
 	      for cmd in $cmds; do
 		IFS="$save_ifs"
+		eval cmd=\"$cmd\"
 		$show "$cmd"
 		$run eval "$cmd"
-		if test $? != 0 && test "$rmforce" != yes; then
+		if test "$?" -ne 0 && test "$rmforce" != yes; then
 		  exit_status=1
 		fi
 	      done
@@ -5186,54 +6631,72 @@
 
 	    if test -n "$old_library"; then
 	      # Do each command in the old_postuninstall commands.
-	      eval cmds=\"$old_postuninstall_cmds\"
-	      IFS="${IFS= 	}"; save_ifs="$IFS"; IFS='~'
+	      cmds=$old_postuninstall_cmds
+	      save_ifs="$IFS"; IFS='~'
 	      for cmd in $cmds; do
 		IFS="$save_ifs"
+		eval cmd=\"$cmd\"
 		$show "$cmd"
 		$run eval "$cmd"
-		if test $? != 0 && test "$rmforce" != yes; then
+		if test "$?" -ne 0 && test "$rmforce" != yes; then
 		  exit_status=1
 		fi
 	      done
 	      IFS="$save_ifs"
 	    fi
 	    # FIXME: should reinstall the best remaining shared library.
-	  fi
+	    ;;
+	  esac
 	fi
 	;;
 
       *.lo)
 	# Possibly a libtool object, so verify it.
-	if (sed -e '2q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
+	if (${SED} -e '2q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
 
-          # Read the .lo file
-          . $dir/$name
+	  # Read the .lo file
+	  . $dir/$name
 
 	  # Add PIC object to the list of files to remove.
-          if test -n "$pic_object" \
-             && test "$pic_object" != none; then
+	  if test -n "$pic_object" \
+	     && test "$pic_object" != none; then
 	    rmfiles="$rmfiles $dir/$pic_object"
-          fi
+	  fi
 
 	  # Add non-PIC object to the list of files to remove.
-          if test -n "$non_pic_object" \
-             && test "$non_pic_object" != none; then
+	  if test -n "$non_pic_object" \
+	     && test "$non_pic_object" != none; then
 	    rmfiles="$rmfiles $dir/$non_pic_object"
-          fi
+	  fi
 	fi
 	;;
 
       *)
-	# Do a test to see if this is a libtool program.
-	if test $mode = clean &&
-	   (sed -e '4q' $file | egrep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
-	  relink_command=
-	  . $dir/$file
+	if test "$mode" = clean ; then
+	  noexename=$name
+	  case $file in
+	  *.exe)
+	    file=`$echo $file|${SED} 's,.exe$,,'`
+	    noexename=`$echo $name|${SED} 's,.exe$,,'`
+	    # $file with .exe has already been added to rmfiles,
+	    # add $file without .exe
+	    rmfiles="$rmfiles $file"
+	    ;;
+	  esac
+	  # Do a test to see if this is a libtool program.
+	  if (${SED} -e '4q' $file | grep "^# Generated by .*$PACKAGE") >/dev/null 2>&1; then
+	    relink_command=
+	    . $dir/$noexename
 
-	  rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
-	  if test "$fast_install" = yes && test -n "$relink_command"; then
-	    rmfiles="$rmfiles $objdir/lt-$name"
+	    # note $name still contains .exe if it was in $file originally
+	    # as does the version of $file that was added into $rmfiles
+	    rmfiles="$rmfiles $objdir/$name $objdir/${name}S.${objext}"
+	    if test "$fast_install" = yes && test -n "$relink_command"; then
+	      rmfiles="$rmfiles $objdir/lt-$name"
+	    fi
+	    if test "X$noexename" != "X$name" ; then
+	      rmfiles="$rmfiles $objdir/lt-${noexename}.c"
+	    fi
 	  fi
 	fi
 	;;
@@ -5241,6 +6704,7 @@
       $show "$rm $rmfiles"
       $run $rm $rmfiles || exit_status=1
     done
+    objdir="$origobjdir"
 
     # Try to remove the ${objdir}s in the directories where we deleted files
     for dir in $rmdirs; do
@@ -5256,20 +6720,20 @@
   "")
     $echo "$modename: you must specify a MODE" 1>&2
     $echo "$generic_help" 1>&2
-    exit 1
+    exit $EXIT_FAILURE
     ;;
   esac
 
   if test -z "$exec_cmd"; then
     $echo "$modename: invalid operation mode \`$mode'" 1>&2
     $echo "$generic_help" 1>&2
-    exit 1
+    exit $EXIT_FAILURE
   fi
 fi # test -z "$show_help"
 
 if test -n "$exec_cmd"; then
   eval exec $exec_cmd
-  exit 1
+  exit $EXIT_FAILURE
 fi
 
 # We need to display help for each of the modes.
@@ -5302,8 +6766,10 @@
       uninstall       remove libraries from an installed directory
 
 MODE-ARGS vary depending on the MODE.  Try \`$modename --help --mode=MODE' for
-a more detailed description of MODE."
-  exit 0
+a more detailed description of MODE.
+
+Report bugs to <bug-libtool@gnu.org>."
+  exit $EXIT_SUCCESS
   ;;
 
 clean)
@@ -5415,6 +6881,8 @@
   -no-undefined     declare that a library does not refer to external symbols
   -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects
   -objectlist FILE  Use a list of object files found in FILE to specify objects
+  -precious-files-regex REGEX
+                    don't remove output files matching REGEX
   -release RELEASE  specify package release information
   -rpath LIBDIR     the created library will eventually be installed in LIBDIR
   -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
@@ -5456,14 +6924,14 @@
 *)
   $echo "$modename: invalid operation mode \`$mode'" 1>&2
   $echo "$help" 1>&2
-  exit 1
+  exit $EXIT_FAILURE
   ;;
 esac
 
-echo
+$echo
 $echo "Try \`$modename --help' for more information about other modes."
 
-exit 0
+exit $?
 
 # The TAGs below are defined such that we never get into a situation
 # in which we disable both kinds of libraries.  Given conflicting
@@ -5476,14 +6944,13 @@
 # If a disable-shared tag is given, we'll fallback to a static-only
 # configuration.  But we'll never go from static-only to shared-only.
 
-### BEGIN LIBTOOL TAG CONFIG: disable-shared
-build_libtool_libs=no
-build_old_libs=yes
-### END LIBTOOL TAG CONFIG: disable-shared
+# ### BEGIN LIBTOOL TAG CONFIG: disable-shared
+disable_libs=shared
+# ### END LIBTOOL TAG CONFIG: disable-shared
 
-### BEGIN LIBTOOL TAG CONFIG: disable-static
-build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`
-### END LIBTOOL TAG CONFIG: disable-static
+# ### BEGIN LIBTOOL TAG CONFIG: disable-static
+disable_libs=static
+# ### END LIBTOOL TAG CONFIG: disable-static
 
 # Local Variables:
 # mode:shell-script
diff --git a/man/CMakeLists.txt b/man/CMakeLists.txt
new file mode 100644
index 0000000..8de246d
--- /dev/null
+++ b/man/CMakeLists.txt
@@ -0,0 +1,97 @@
+SET(MDOC3_PAGES
+  libzip.mdoc
+  zip_add.mdoc
+  zip_add_dir.mdoc
+  zip_close.mdoc
+  zip_delete.mdoc
+  zip_error_clear.mdoc
+  zip_error_get.mdoc
+  zip_error_get_sys_type.mdoc
+  zip_error_to_str.mdoc
+  zip_errors.mdoc
+  zip_fclose.mdoc
+  zip_file_strerror.mdoc
+  zip_fopen.mdoc
+  zip_fread.mdoc
+  zip_get_archive_comment.mdoc
+  zip_get_file_comment.mdoc
+  zip_get_name.mdoc
+  zip_get_num_files.mdoc
+  zip_name_locate.mdoc
+  zip_open.mdoc
+  zip_rename.mdoc
+  zip_set_archive_comment.mdoc
+  zip_set_file_comment.mdoc
+  zip_source_buffer.mdoc
+  zip_source_file.mdoc
+  zip_source_filep.mdoc
+  zip_source_free.mdoc
+  zip_source_function.mdoc
+  zip_source_zip.mdoc
+  zip_stat.mdoc
+  zip_stat_init.mdoc
+  zip_unchange.mdoc
+  zip_unchange_all.mdoc
+  zip_unchange_archive.mdoc
+)
+SET(MDOC1_PAGES
+  zipcmp.mdoc
+  zipmerge.mdoc
+)
+SET(MDOC_PAGES ${MDOC1_PAGES} ${MDOC3_PAGES})
+STRING(REGEX REPLACE .mdoc "" MAN1_PAGES "${MDOC1_PAGES}")
+STRING(REGEX REPLACE .mdoc "" MAN3_PAGES "${MDOC3_PAGES}")
+SET(MAN_PAGES ${MAN1_PAGES} ${MAN3_PAGES})
+
+IF(CMAKE_SYSTEM_NAME MATCHES BSD)
+  SET(MANFMT mdoc)
+ELSE(CMAKE_SYSTEM_NAME MATCHES BSD)
+  SET(MANFMT man)
+ENDif(CMAKE_SYSTEM_NAME MATCHES BSD)
+
+# installation
+
+SET(MAN_PATH man)
+
+FOREACH(MAN_PAGE ${MAN1_PAGES})
+  INSTALL(FILES ${MAN_PAGE}.${MANFMT} DESTINATION ${MAN_PATH}/man1
+    RENAME ${MAN_PAGE}.1)
+ENDFOREACH(MAN_PAGE ${PROGRAMS})
+FOREACH(MAN_PAGE ${MAN3_PAGES})
+  INSTALL(FILES ${MAN_PAGE}.${MANFMT} DESTINATION ${MAN_PATH}/man3
+    RENAME ${MAN_PAGE}.3)
+ENDFOREACH(MAN_PAGE ${PROGRAMS})
+
+# custom targets
+
+FOREACH(MAN ${MAN_PAGES})
+  ADD_CUSTOM_TARGET(${MAN}.man
+    DEPENDS ${MAN}.mdoc
+    COMMAND mdoc2man ${CMAKE_CURRENT_SOURCE_DIR}/${MAN}.mdoc > ${MAN}.new
+    COMMAND diff -I NiH ${MAN}.new ${CMAKE_CURRENT_SOURCE_DIR}/${MAN}.man || mv ${MAN}.new ${CMAKE_CURRENT_SOURCE_DIR}/${MAN}.man
+    COMMAND rm -f ${MAN}.new
+    COMMENT Updating man page ${MAN}.man
+    )
+  ADD_CUSTOM_TARGET(${MAN}.html
+    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${MAN}.mdoc
+    COMMAND nroff -mdoc2html ${CMAKE_CURRENT_SOURCE_DIR}/${MAN}.mdoc | sed -e "s,../html[0-9]/,," > ${MAN}.html
+    COMMENT Updating HTML page ${MAN}.html
+    )
+ENDFOREACH(MAN)
+
+STRING(REGEX REPLACE .mdoc .man MANDEPEND "${MDOC_PAGES}")
+ADD_CUSTOM_TARGET(update-man
+  DEPENDS ${MANDEPEND})
+
+STRING(REGEX REPLACE .mdoc .html HTMLDEPEND "${MDOC_PAGES}")
+ADD_CUSTOM_TARGET(update-html
+  DEPENDS ${HTMLDEPEND})
+
+# XXX: strange error:
+#[ 94%] zipcmp.html
+#[ 97%] Built target zipcmp.html
+#[ 97%] zipmerge.html
+#[100%] Built target zipmerge.html
+#make: don't know how to make zipcmp.html. Stop
+
+# XXX: why are all the man pages rebuilt on a second 'make update-html'?
diff --git a/man/Makefile.am b/man/Makefile.am
index 82a5f25..f7cbb08 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -1,45 +1,99 @@
-man_MANS=${MAN1} ${MAN3}
+MANFMT=@MANFMT@
+man1_MANS=${MAN1:.mdoc=.${MANFMT}}
+man3_MANS=${MAN3:.mdoc=.${MANFMT}}
 
-DISTCLEANFILES=${man_MANS}
-EXTRA_DIST=${MANDOC} ${MAN}
+DISTCLEANFILES=${HTML}
+EXTRA_DIST=${MANDOC} ${MAN} CMakeLists.txt
 
-MAN1=	zipcmp.1
-MAN3=	zip_close.3 \
-	zip_delete.3 \
-	zip_error_str.3 \
-	zip_fclose.3 \
-	zip_file_strerror.3 \
-	zip_fopen.3 \
-	zip_fread.3 \
-	zip_get_name.3 \
-	zip_get_num_files.3 \
-	zip_name_locate.3 \
-	zip_open.3 \
-	zip_rename.3 \
-	zip_stat.3 \
-	zip_strerror.3 \
-	zip_unchange.3 \
-	zip_unchange_all.3
+MAN1=	zipcmp.mdoc zipmerge.mdoc
+MAN3=	libzip.mdoc \
+	zip_add.mdoc \
+	zip_add_dir.mdoc \
+	zip_close.mdoc \
+	zip_delete.mdoc \
+	zip_error_clear.mdoc \
+	zip_error_get.mdoc \
+	zip_error_get_sys_type.mdoc \
+	zip_error_to_str.mdoc \
+	zip_errors.mdoc \
+	zip_fclose.mdoc \
+	zip_file_strerror.mdoc \
+	zip_fopen.mdoc \
+	zip_fread.mdoc \
+	zip_get_archive_comment.mdoc \
+	zip_get_file_comment.mdoc \
+	zip_get_name.mdoc \
+	zip_get_num_files.mdoc \
+	zip_name_locate.mdoc \
+	zip_open.mdoc \
+	zip_rename.mdoc \
+	zip_set_archive_comment.mdoc \
+	zip_set_file_comment.mdoc \
+	zip_source_buffer.mdoc \
+	zip_source_file.mdoc \
+	zip_source_filep.mdoc \
+	zip_source_free.mdoc \
+	zip_source_function.mdoc \
+	zip_source_zip.mdoc \
+	zip_stat.mdoc \
+	zip_stat_init.mdoc \
+	zip_unchange.mdoc \
+	zip_unchange_all.mdoc \
+	zip_unchange_archive.mdoc
 
-install-man: link-man3
+install-data-hook: link-man3
 
 LN=ln
 
-link-man3: install-man3
-	-rm -f ${man3dir}/zip_fopen_index.3
-	${LN} ${man3dir}/zip_fopen.3 ${man3dir}/zip_fopen_index.3
-	-rm -f ${man3dir}/zip_stat_index.3
-	${LN} ${man3dir}/zip_stat.3 ${man3dir}/zip_stat_index.3
+link-man3: install-man3 uninstall-hook
+	${LN} ${DESTDIR}${man3dir}/zip_error_clear.3 \
+		${DESTDIR}${man3dir}/zip_file_error_clear.3
+	${LN} ${DESTDIR}${man3dir}/zip_error_get.3 \
+		${DESTDIR}${man3dir}/zip_file_error_get.3
+	${LN} ${DESTDIR}${man3dir}/zip_fopen.3 \
+		${DESTDIR}${man3dir}/zip_fopen_index.3
+	${LN} ${DESTDIR}${man3dir}/zip_add.3 \
+		${DESTDIR}${man3dir}/zip_replace.3
+	${LN} ${DESTDIR}${man3dir}/zip_stat.3 \
+		${DESTDIR}${man3dir}/zip_stat_index.3
+	${LN} ${DESTDIR}${man3dir}/zip_file_strerror.3 \
+		${DESTDIR}${man3dir}/zip_strerror.3
 
-MANDOC=${MAN1:.1=.mdoc} ${MAN3:.3=.mdoc}
+uninstall-hook:
+	-rm -f ${DESTDIR}${man3dir}/zip_file_error_clear.3
+	-rm -f ${DESTDIR}${man3dir}/zip_file_error_get.3
+	-rm -f ${DESTDIR}${man3dir}/zip_fopen_index.3
+	-rm -f ${DESTDIR}${man3dir}/zip_replace.3
+	-rm -f ${DESTDIR}${man3dir}/zip_stat_index.3
+	-rm -f ${DESTDIR}${man3dir}/zip_strerror.3
+
+link-html: ${HTML}
+	-rm -f zip_file_error_get.html zip_fopen_index.html \
+		zip_replace.html zip_stat_index.html \
+		zip_strerror.html
+	${LN} zip_error_get.html zip_file_error_get.html
+	${LN} zip_fopen.html zip_fopen_index.html
+	${LN} zip_add.html zip_replace.html
+	${LN} zip_stat.html zip_stat_index.html
+	${LN} zip_file_strerror.html zip_strerror.html
+
+MANDOC=${MAN1} ${MAN3}
+HTML=${MANDOC:.mdoc=.html}
 MAN=${MANDOC:.mdoc=.man}
 
 MDOC2MAN=mdoc2man
-SUFFIXES=.man .mdoc
+SUFFIXES=.man .mdoc .html
 
-.PHONY: mkman
+.PHONY: mkman update-errors
 
 mkman: ${MAN}
+mkhtml: ${HTML} link-html
+
+update-errors:
+	sh $(srcdir)/make_zip_errors.sh $(srcdir)/../lib/zip.h zip_errors.mdoc
 
 .mdoc.man:
 	${MDOC2MAN} $< > $@.$$$$ && mv $@.$$$$ $@
+
+.mdoc.html:
+	nroff -mdoc2html $< | sed -e "s,../html[0-9]/,," > $@.$$$$ && mv $@.$$$$ $@
diff --git a/man/libzip.man b/man/libzip.man
new file mode 100644
index 0000000..9862f87
--- /dev/null
+++ b/man/libzip.man
@@ -0,0 +1,103 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: libzip.mdoc,v 1.8 2006/04/23 16:37:38 wiz Exp 
+.\" $NiH: libzip.mdoc,v 1.8 2006/04/23 16:37:38 wiz Exp $
+.\"
+.\" libzip.mdoc \-- general overview of available functions
+.\" Copyright (C) 2005, 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH LIBZIP 3 "April 23, 2006" NiH
+.SH "NAME"
+libzip \- library for manipulating zip archives
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.SH "DESCRIPTION"
+.B libzip
+is a library for reading, creating, and modifying zip archives.
+.PP
+Below there are two sections listing functions: one for how to read
+from zip archives and one for how to create/modify them.
+.SH "READING ZIP ARCHIVES"
+.SS "open archive"
+zip_open(3)
+.SS "find files"
+zip_name_locate(3)
+.SS "read files"
+zip_fopen(3)
+zip_fopen_index(3)
+zip_fread(3)
+zip_fclose(3)
+.SS "close archive"
+zip_close(3)
+.SS "miscellaneous"
+zip_stat(3)
+zip_get_archive_comment(3)
+zip_get_file_comment(3)
+zip_get_name(3)
+zip_get_num_files(3)
+.SH "CREATING/MODIFYING ZIP ARCHIVES"
+.SS "create/open archive"
+zip_open(3)
+.SS "add/change files"
+zip_add(3)
+zip_replace(3)
+zip_set_file_comment(3)
+zip_source_buffer(3)
+zip_source_file(3)
+zip_source_filep(3)
+zip_source_function(3)
+zip_source_zip(3)
+zip_source_free(3)
+.SS "rename files"
+zip_rename(3)
+.SS "delete files"
+zip_delete(3)
+.SS "revert changes"
+zip_unchange(3)
+zip_unchange_all(3)
+zip_unchange_archive(3)
+.SS "close archive"
+zip_close(3)
+.SS "miscellaneous"
+zip_set_archive_comment(3)
+.SH "ERROR HANDLING"
+zip_error_to_str(3)
+zip_strerror(3)
+zip_file_strerror(3)
+zip_error_get(3)
+zip_error_get_sys_type(3)
+zip_errors(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/libzip.mdoc b/man/libzip.mdoc
new file mode 100644
index 0000000..707bf95
--- /dev/null
+++ b/man/libzip.mdoc
@@ -0,0 +1,104 @@
+.\" $NiH: libzip.mdoc,v 1.7 2006/04/23 12:50:32 wiz Exp $
+.\"
+.\" libzip.mdoc -- general overview of available functions
+.\" Copyright (C) 2005, 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 23, 2006
+.Dt LIBZIP 3
+.Os
+.Sh NAME
+.Nm libzip
+.Nd library for manipulating zip archives
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.In zip.h
+.Sh DESCRIPTION
+.Nm
+is a library for reading, creating, and modifying zip archives.
+.Pp
+Below there are two sections listing functions: one for how to read
+from zip archives and one for how to create/modify them.
+.Sh READING ZIP ARCHIVES
+.Ss open archive
+.Xr zip_open 3
+.Ss find files
+.Xr zip_name_locate 3
+.Ss read files
+.Xr zip_fopen 3
+.Xr zip_fopen_index 3
+.Xr zip_fread 3
+.Xr zip_fclose 3
+.Ss close archive
+.Xr zip_close 3
+.Ss miscellaneous
+.Xr zip_stat 3
+.Xr zip_get_archive_comment 3
+.Xr zip_get_file_comment 3
+.Xr zip_get_name 3
+.Xr zip_get_num_files 3
+.Sh CREATING/MODIFYING ZIP ARCHIVES
+.Ss create/open archive
+.Xr zip_open 3
+.Ss add/change files
+.Xr zip_add 3
+.Xr zip_replace 3
+.Xr zip_set_file_comment 3
+.Xr zip_source_buffer 3
+.Xr zip_source_file 3
+.Xr zip_source_filep 3
+.Xr zip_source_function 3
+.Xr zip_source_zip 3
+.Xr zip_source_free 3
+.Ss rename files
+.Xr zip_rename 3
+.Ss delete files
+.Xr zip_delete 3
+.Ss revert changes
+.Xr zip_unchange 3
+.Xr zip_unchange_all 3
+.Xr zip_unchange_archive 3
+.Ss close archive
+.Xr zip_close 3
+.Ss miscellaneous
+.Xr zip_set_archive_comment 3
+.Sh ERROR HANDLING
+.Xr zip_error_to_str 3
+.Xr zip_strerror 3
+.Xr zip_file_strerror 3
+.Xr zip_error_get 3
+.Xr zip_error_get_sys_type 3
+.Xr zip_errors 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/make_zip_errors.sh b/man/make_zip_errors.sh
new file mode 100644
index 0000000..46349ae
--- /dev/null
+++ b/man/make_zip_errors.sh
@@ -0,0 +1,121 @@
+#!/bin/sh
+
+#  $NiH: make_zip_errors.sh,v 1.3 2005/01/20 21:03:36 dillo Exp $
+#
+#  make_zip_errrors.sh: create zip_errors.mdoc from zip.h
+#  Copyright (C) 1999, 2003, 2004, 2005 Dieter Baron and Thomas Klausner
+#
+#  This file is part of libzip, a library to manipulate ZIP archives.
+#  The authors can be contacted at <nih@giga.or.at>
+#
+#  Redistribution and use in source and binary forms, with or without
+#  modification, are permitted provided that the following conditions
+#  are met:
+#  1. Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#  3. The names of the authors may not be used to endorse or promote
+#     products derived from this software without specific prior
+#     written permission.
+# 
+#  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+#  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+#  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+#  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+#  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+#  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+#  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+if [ "$#" -ne 2 ]
+then
+    echo "Usage: $0 in_file out_file" >&2
+    echo "       e.g. $0 zip.h zip_err_str.c" >&2
+    exit 1
+fi
+
+if [ "$1" = "$2" ]
+then
+    echo "$0: error: output file = input file" >&2
+    exit 1
+fi
+
+rcsid=`echo '$NiH: make_zip_errors.sh,v 1.3 2005/01/20 21:03:36 dillo Exp $' | tr -d '$'`
+inrcsid=`sed -n 's/^  \$\([^$]*[^ ]\) *\$$/\1/p' "$1"`
+date=`date '+%B %e, %Y' | sed 's/  / /'`
+
+cat <<EOF >> "$2.$$" || exit 1
+.\" \$NiH\$
+.\"
+.\" zip_errors.mdoc -- list of all libzip error codes
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS \`\`AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\"   This file was generated automatically by $0
+.\"   from $1; make changes there.
+.\"	$rcsid
+.\"	$inrcsid
+.\"
+.Dd $date
+.Dt ZIP_ERRORS 3
+.Os
+.Sh NAME
+.Nm zip_errors
+.Nd list of all libzip error codes
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.In zip.h
+.Sh DESCRIPTION
+The following error codes are used by libzip:
+.Bl -tag -width XZIPXERXCOMPNOTSUPPXX
+EOF
+
+sed -n  's/^#define \(ZIP_ER_[A-Z_0-9]*\).*\/\* \(.\) \([^*]*\) \*\//.It Bq Er \1@\3./p' "$1" \
+    | tr @ '\012' \
+    >> "$2.$$" || exit 1
+
+cat <<EOF >> "$2.$$" || exit 1
+.El
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
+EOF
+
+mv "$2.$$" "$2" || exit 1
diff --git a/man/zip_add.man b/man/zip_add.man
new file mode 100644
index 0000000..d98ebb5
--- /dev/null
+++ b/man/zip_add.man
@@ -0,0 +1,128 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_add.mdoc,v 1.10 2006/04/09 14:52:03 wiz Exp 
+.\" $NiH: zip_add.mdoc,v 1.10 2006/04/09 14:52:03 wiz Exp $
+.\"
+.\" zip_add.mdoc \-- add files to zip archive
+.\" Copyright (C) 2004, 2005, 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_ADD 3 "April 9, 2006" NiH
+.SH "NAME"
+zip_add , \- .Nm zip_replace
+add file to zip archive or replace file in zip archive
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.PP
+int
+zip_add(struct zip *archive, const char *name); \
+"struct zip_source *source"
+.PP
+int
+zip_replace(struct zip *archive, int index); \
+"struct zip_source *source"
+.SH "DESCRIPTION"
+The function
+zip_add
+adds a file to a zip archive, while
+zip_replace
+replaces an existing file in a zip archive.
+The argument
+\fBarchive\fR
+specifies the zip archive to which the file should be added.
+\fBname\fR
+is the file's name in the zip archive (for
+zip_add ),
+while
+\fBindex\fR
+specifies which file should be replaced (for
+zip_replace ).
+The data is obtained from the
+\fBsource\fR
+argument.
+See the
+zip_source_*
+functions cited in
+SEE ALSO.
+.SH "RETURN VALUES"
+Upon successful completion, the index of the new file in the archive
+is returned.
+Otherwise, \-1 is returned and the error code in
+\fBarchive\fR
+is set to indicate the error.
+.SH "EXAMPLES"
+.Bd \-literal \-offset indent
+struct zip_source *s;
+
+if ((s=zip_source_buffer(archive, buffer, len)) == NULL ||
+    zip_add(archive, name, s) \*[Lt] 0) {
+    zip_source_free(s);
+    printf("error adding file: %s\n", zip_strerror(archive));
+}
+.Ed
+.SH "ERRORS"
+zip_add
+and
+zip_replace
+fail if:
+.RS
+.TP 4
+[ZIP_ER_EXISTS]
+There is already a file called
+\fBname\fR
+in the archive.
+(Only applies to
+zip_add ).
+.TP 4
+[ZIP_ER_INVAL]
+\fBsource\fR
+or
+\fBname\fR
+are
+\fBNULL,\fR
+or
+\fBindex\fR
+is invalid.
+.TP 4
+[ZIP_ER_MEMORY]
+Required memory could not be allocated.
+.RE
+.SH "SEE ALSO"
+libzip(3),
+zip_source_file(3),
+zip_source_filep(3),
+zip_source_function(3),
+zip_source_zip(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_add.mdoc b/man/zip_add.mdoc
new file mode 100644
index 0000000..5acbfe3
--- /dev/null
+++ b/man/zip_add.mdoc
@@ -0,0 +1,124 @@
+.\" $NiH: zip_add.mdoc,v 1.9 2005/06/09 21:14:54 wiz Exp $
+.\"
+.\" zip_add.mdoc -- add files to zip archive
+.\" Copyright (C) 2004, 2005, 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 9, 2006
+.Dt ZIP_ADD 3
+.Os
+.Sh NAME
+.Nm zip_add ,
+.Nm zip_replace
+.Nd add file to zip archive or replace file in zip archive
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.In zip.h
+.Ft int
+.Fn zip_add "struct zip *archive" "const char *name" \
+"struct zip_source *source"
+.Ft int
+.Fn zip_replace "struct zip *archive" "int index" \
+"struct zip_source *source"
+.Sh DESCRIPTION
+The function
+.Fn zip_add
+adds a file to a zip archive, while
+.Fn zip_replace
+replaces an existing file in a zip archive.
+The argument
+.Ar archive
+specifies the zip archive to which the file should be added.
+.Ar name
+is the file's name in the zip archive (for
+.Fn zip_add ) ,
+while
+.Ar index
+specifies which file should be replaced (for
+.Fn zip_replace ) .
+The data is obtained from the
+.Ar source
+argument.
+See the
+.Fn zip_source_*
+functions cited in
+.Sx SEE ALSO .
+.Sh RETURN VALUES
+Upon successful completion, the index of the new file in the archive
+is returned.
+Otherwise, \-1 is returned and the error code in
+.Ar archive
+is set to indicate the error.
+.Sh EXAMPLES
+.Bd -literal -offset indent
+struct zip_source *s;
+
+if ((s=zip_source_buffer(archive, buffer, len)) == NULL ||
+    zip_add(archive, name, s) \*[Lt] 0) {
+    zip_source_free(s);
+    printf("error adding file: %s\n", zip_strerror(archive));
+}
+.Ed
+.Sh ERRORS
+.Fn zip_add
+and
+.Fn zip_replace
+fail if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_EXISTS
+There is already a file called
+.Ar name
+in the archive.
+(Only applies to
+.Fn zip_add ) .
+.It Bq Er ZIP_ER_INVAL
+.Ar source
+or
+.Ar name
+are
+.Dv NULL ,
+or
+.Ar index
+is invalid.
+.It Bq Er ZIP_ER_MEMORY
+Required memory could not be allocated.
+.El
+.Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_source_file 3 ,
+.Xr zip_source_filep 3 ,
+.Xr zip_source_function 3 ,
+.Xr zip_source_zip 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_error_str.man b/man/zip_add_dir.man
similarity index 60%
copy from man/zip_error_str.man
copy to man/zip_add_dir.man
index 630a864..6db7e86 100644
--- a/man/zip_error_str.man
+++ b/man/zip_add_dir.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_error_str.mdoc,v 1.1 2003/12/27 22:25:58 wiz Exp 
-.\" $NiH: zip_error_str.mdoc,v 1.1 2003/12/27 22:25:58 wiz Exp $
+.\" from NiH: zip_add_dir.mdoc,v 1.2 2006/10/03 19:35:52 dillo Exp 
+.\" $NiH: zip_add_dir.mdoc,v 1.2 2006/10/03 19:35:52 dillo Exp $
 .\"
-.\" zip_error_str.mdoc \-- get string representation of zip error code
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_add_dir.mdoc \-- add directory to zip archive
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,42 +33,56 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_STRERROR 3 "October 3, 2003" NiH
+.TH ZIP_ADD_DIR 3 "October 3, 2006" NiH
 .SH "NAME"
-zip_error_str \- get string representation of zip error
+zip_add_dir \- add directory to zip archive
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_error_str "char *buf" "int len" "int ze" "int se"
+#include <zip.h>
+.PP
+int
+zip_add_dir(struct zip *archive, const char *name);
 .SH "DESCRIPTION"
-The
-.Fn zip_error_str
-function returns a string describing the zip error code
-\fBze\fR
-in
-\fBbuf\fR
-which has size
-\fBlen.\fR
-\fBse\fR
-should be the value of the global variable
-\fBerrno\fR
-at the time of the error.
-.Fn zip_error_str
-is especially useful if
-.Fn zip_open
-failed and no
-.Vt struct zip
-is available; otherwise
-.Fn zip_strerror
-should be used.
+The function
+zip_add_dir
+adds a directory to a zip archive.
+The argument
+\fBarchive\fR
+specifies the zip archive to which the directory should be added.
+\fBname\fR
+is the directory's name in the zip archive.
 .SH "RETURN VALUES"
-.Fn zip_error_str
-returns the number of characters that would have been written to a
-sufficiently sized
-\fBbuf,\fR
-excluding the terminating NUL character.
+Upon successful completion, the index of the new entry in the archive
+is returned.
+Otherwise, \-1 is returned and the error code in
+\fBarchive\fR
+is set to indicate the error.
+.SH "ERRORS"
+zip_add_dir
+fails if:
+.RS
+.TP 4
+[ZIP_ER_EXISTS]
+There is already an entry called
+\fBname\fR
+in the archive.
+.TP 4
+[ZIP_ER_INVAL]
+\fBarchive\fR
+or
+\fBname\fR
+are
+\fBNULL.\fR
+.TP 4
+[ZIP_ER_MEMORY]
+Required memory could not be allocated.
+.RE
 .SH "SEE ALSO"
-zip_open(3),
-zip_strerror(3)
+libzip(3),
+zip_add(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_strerror.mdoc b/man/zip_add_dir.mdoc
similarity index 60%
copy from man/zip_strerror.mdoc
copy to man/zip_add_dir.mdoc
index 529c361..d211d18 100644
--- a/man/zip_strerror.mdoc
+++ b/man/zip_add_dir.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH: zip_add_dir.mdoc,v 1.1 2006/10/03 18:55:51 wiz Exp $
 .\"
-.\" zip_strerror.mdoc -- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_add_dir.mdoc -- add directory to zip archive
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,30 +31,55 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd October 3, 2006
+.Dt ZIP_ADD_DIR 3
 .Os
 .Sh NAME
-.Nm zip_strerror
-.Nd get string representation of zip error
+.Nm zip_add_dir
+.Nd add directory to zip archive
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+.Ft int
+.Fn zip_add_dir "struct zip *archive" "const char *name"
 .Sh DESCRIPTION
-The
-.Fn zip_strerror
-function returns a string describing the last error for
-.Ar archive .
-The returned string must not be modified or freed, and becomes invalid when
+The function
+.Fn zip_add_dir
+adds a directory to a zip archive.
+The argument
 .Ar archive
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
+specifies the zip archive to which the directory should be added.
+.Ar name
+is the directory's name in the zip archive.
 .Sh RETURN VALUES
-.Fn zip_strerror
-returns a pointer to the error string.
+Upon successful completion, the index of the new entry in the archive
+is returned.
+Otherwise, \-1 is returned and the error code in
+.Ar archive
+is set to indicate the error.
+.Sh ERRORS
+.Fn zip_add_dir
+fails if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_EXISTS
+There is already an entry called
+.Ar name
+in the archive.
+.It Bq Er ZIP_ER_INVAL
+.Ar archive
+or
+.Ar name
+are
+.Dv NULL .
+.It Bq Er ZIP_ER_MEMORY
+Required memory could not be allocated.
+.El
 .Sh SEE ALSO
-.Xr zip_error_str 3
+.Xr libzip 3 ,
+.Xr zip_add 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_close.man b/man/zip_close.man
index 3fd3b48..1873ec7 100644
--- a/man/zip_close.man
+++ b/man/zip_close.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_close.mdoc,v 1.4 2003/10/03 12:04:08 dillo Exp 
-.\" $NiH: zip_close.mdoc,v 1.4 2003/10/03 12:04:08 dillo Exp $
+.\" from NiH: zip_close.mdoc,v 1.14 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_close.mdoc,v 1.14 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_close.mdoc \-- close zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,65 +33,86 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_CLOSE 3 "October 3, 2003" NiH
+.TH ZIP_CLOSE 3 "June 9, 2005" NiH
 .SH "NAME"
 zip_close \- close zip archive
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_close "struct zip *archive"
+#include <zip.h>
+.PP
+int
+zip_close(struct zip *archive);
 .SH "DESCRIPTION"
 The
-.Fn zip_close
+zip_close
 function closes
 \fBarchive\fR
 and frees the memory allocated for it.
 If any files within were changed, those changes are written to disk
 first.
 If writing changes fails,
-.Fn zip_close
+zip_close
 fails and
 \fBarchive\fR
 is left unchanged.
 .SH "RETURN VALUES"
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+\fBarchive\fR
 is set to indicate the error.
 .SH "ERRORS"
-.Fn zip_close
+zip_close
 will fail if:
 .RS
 .TP 4
-Bq Er ZERR_INVAL
+[ZIP_ER_EOF]
+Unexpected end-of-file found while reading from a file.
+.TP 4
+[ZIP_ER_INTERNAL]
+The callback function of an added or replaced file returned an
+error but failed to report which.
+.TP 4
+[ZIP_ER_INVAL]
 The
 \fBpath\fR
 argument is
-.Dv NULL.
+\fBNULL.\fR
 .TP 4
-Bq Er ZERR_MEMORY
+[ZIP_ER_MEMORY]
 Required memory could not be allocated.
 .TP 4
-Bq Er ZERR_RENAME
+[ZIP_ER_NOZIP]
+File is not a zip archive.
+.TP 4
+[ZIP_ER_READ]
+A file read failed.
+.TP 4
+[ZIP_ER_RENAME]
 A temporary file could not be renamed to its final name.
-See
-.Va errno
-for details.
 .TP 4
-Bq Er ZERR_SEEK
-A file seek  failed.
-See
-.Va errno
-for details.
+[ZIP_ER_SEEK]
+A file seek failed.
 .TP 4
-Bq Er ZERR_TMPOPEN
+[ZIP_ER_TMPOPEN]
 A temporary file could not be created.
-See
-.Va errno
-for details.
-.\" XXX: list incomplete
+.TP 4
+[ZIP_ER_WRITE]
+A file write failed.
+.TP 4
+[ZIP_ER_ZLIB]
+An error occurred while (de)compressing a stream with
+zlib(3).
 .RE
+Additionally, any errors returned by the callback function
+for added or replaced files will be passed back.
 .SH "SEE ALSO"
-zip_open(3)
+libzip(3),
+zip_error_get(3),
+zip_open(3),
+zip_strerror(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_close.mdoc b/man/zip_close.mdoc
index aad2506..b518092 100644
--- a/man/zip_close.mdoc
+++ b/man/zip_close.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_close.mdoc,v 1.3 2003/10/03 09:44:43 wiz Exp $
+.\" $NiH: zip_close.mdoc,v 1.13 2005/06/09 21:13:12 wiz Exp $
 .\"
 .\" zip_close.mdoc -- close zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,7 +31,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
+.Dd June 9, 2005
 .Dt ZIP_CLOSE 3
 .Os
 .Sh NAME
@@ -58,36 +58,50 @@
 is left unchanged.
 .Sh RETURN VALUES
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+.Ar archive
 is set to indicate the error.
 .Sh ERRORS
 .Fn zip_close
 will fail if:
 .Bl -tag -width Er
-.It Bq Er ZERR_INVAL
+.It Bq Er ZIP_ER_EOF
+Unexpected end-of-file found while reading from a file.
+.It Bq Er ZIP_ER_INTERNAL
+The callback function of an added or replaced file returned an
+error but failed to report which.
+.It Bq Er ZIP_ER_INVAL
 The
 .Ar path
 argument is
 .Dv NULL .
-.It Bq Er ZERR_MEMORY
+.It Bq Er ZIP_ER_MEMORY
 Required memory could not be allocated.
-.It Bq Er ZERR_RENAME
+.It Bq Er ZIP_ER_NOZIP
+File is not a zip archive.
+.It Bq Er ZIP_ER_READ
+A file read failed.
+.It Bq Er ZIP_ER_RENAME
 A temporary file could not be renamed to its final name.
-See
-.Va errno
-for details.
-.It Bq Er ZERR_SEEK
-A file seek  failed.
-See
-.Va errno
-for details.
-.It Bq Er ZERR_TMPOPEN
+.It Bq Er ZIP_ER_SEEK
+A file seek failed.
+.It Bq Er ZIP_ER_TMPOPEN
 A temporary file could not be created.
-See
-.Va errno
-for details.
-.\" XXX: list incomplete
+.It Bq Er ZIP_ER_WRITE
+A file write failed.
+.It Bq Er ZIP_ER_ZLIB
+An error occurred while (de)compressing a stream with
+.Xr zlib 3 .
 .El
+Additionally, any errors returned by the callback function
+for added or replaced files will be passed back.
 .Sh SEE ALSO
-.Xr zip_open 3
+.Xr libzip 3 ,
+.Xr zip_error_get 3 ,
+.Xr zip_open 3 ,
+.Xr zip_strerror 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_delete.man b/man/zip_delete.man
index 6a1e181..7497256 100644
--- a/man/zip_delete.man
+++ b/man/zip_delete.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_delete.mdoc,v 1.4 2003/10/03 23:26:00 dillo Exp 
-.\" $NiH: zip_delete.mdoc,v 1.4 2003/10/03 23:26:00 dillo Exp $
+.\" from NiH: zip_delete.mdoc,v 1.11 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_delete.mdoc,v 1.11 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_delete.mdoc \-- delete files from zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -39,9 +39,10 @@
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_delete "struct zip *archive" "int index"
+#include <zip.h>
+.PP
+int
+zip_delete(struct zip *archive, int index);
 .SH "DESCRIPTION"
 The file at position
 \fBindex\fR
@@ -50,19 +51,24 @@
 is marked as deleted.
 .SH "RETURN VALUES"
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+\fBarchive\fR
 is set to indicate the error.
 .SH "ERRORS"
-.Fn zip_delete
+zip_delete
 fails if:
 .RS
 .TP 4
-Bq Er ZERR_INVAL
+[ZIP_ER_INVAL]
 \fBindex\fR
 is not a valid file index in
 \fBarchive.\fR
-.\: XXX: also ch_func ZIP_CMD_CLOSE errors
 .RE
 .SH "SEE ALSO"
+libzip(3),
 zip_unchange(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_delete.mdoc b/man/zip_delete.mdoc
index 0db4168..190547b 100644
--- a/man/zip_delete.mdoc
+++ b/man/zip_delete.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_delete.mdoc,v 1.3 2003/10/03 12:04:08 dillo Exp $
+.\" $NiH: zip_delete.mdoc,v 1.10 2005/06/09 21:13:12 wiz Exp $
 .\"
 .\" zip_delete.mdoc -- delete files from zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -51,18 +51,23 @@
 is marked as deleted.
 .Sh RETURN VALUES
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+.Ar archive
 is set to indicate the error.
 .Sh ERRORS
 .Fn zip_delete
 fails if:
 .Bl -tag -width Er
-.It Bq Er ZERR_INVAL
+.It Bq Er ZIP_ER_INVAL
 .Ar index
 is not a valid file index in
 .Ar archive .
-.\: XXX: also ch_func ZIP_CMD_CLOSE errors
 .El
 .Sh SEE ALSO
+.Xr libzip 3 ,
 .Xr zip_unchange 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_strerror.man b/man/zip_error_clear.man
similarity index 69%
rename from man/zip_strerror.man
rename to man/zip_error_clear.man
index 3b82061..952d2c6 100644
--- a/man/zip_strerror.man
+++ b/man/zip_error_clear.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp 
-.\" $NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp $
+.\" from NiH: zip_error_clear.mdoc,v 1.1 2006/10/04 18:31:09 wiz Exp 
+.\" $NiH: zip_error_clear.mdoc,v 1.1 2006/10/04 18:31:09 wiz Exp $
 .\"
-.\" zip_strerror.mdoc \-- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_clear_error.mdoc \-- clear error state for archive or file
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,27 +33,35 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_STRERROR 3 "October 3, 2003" NiH
+.TH ZIP_CLEAR_ERROR 3 "October 4, 2006" NiH
 .SH "NAME"
-zip_strerror \- get string representation of zip error
+zip_error_clear , \- .Nm zip_file_error_clear
+clear error state for archive or file
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+#include <zip.h>
+.PP
+void
+zip_error_clear(struct zip *archive);
+.PP
+void
+zip_file_error_clear(struct zip_file *file);
 .SH "DESCRIPTION"
 The
-.Fn zip_strerror
-function returns a string describing the last error for
+zip_error_clear
+function clears the error state for the zip archive
 \fBarchive.\fR
-The returned string must not be modified or freed, and becomes invalid when
-\fBarchive\fR
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
-.SH "RETURN VALUES"
-.Fn zip_strerror
-returns a pointer to the error string.
+.PP
+The
+zip_file_error_clear
+function does the same for the zip file
+\fBfile.\fR
 .SH "SEE ALSO"
-zip_error_str(3)
+libzip(3),
+zip_error_get(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_strerror.mdoc b/man/zip_error_clear.mdoc
similarity index 71%
rename from man/zip_strerror.mdoc
rename to man/zip_error_clear.mdoc
index 529c361..2c543bb 100644
--- a/man/zip_strerror.mdoc
+++ b/man/zip_error_clear.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH$
 .\"
-.\" zip_strerror.mdoc -- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_clear_error.mdoc -- clear error state for archive or file
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,30 +31,36 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd October 4, 2006
+.Dt ZIP_CLEAR_ERROR 3
 .Os
 .Sh NAME
-.Nm zip_strerror
-.Nd get string representation of zip error
+.Nm zip_error_clear ,
+.Nm zip_file_error_clear
+.Nd clear error state for archive or file
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+.Ft void
+.Fn zip_error_clear "struct zip *archive"
+.Ft void
+.Fn zip_file_error_clear "struct zip_file *file"
 .Sh DESCRIPTION
 The
-.Fn zip_strerror
-function returns a string describing the last error for
+.Fn zip_error_clear
+function clears the error state for the zip archive
 .Ar archive .
-The returned string must not be modified or freed, and becomes invalid when
-.Ar archive
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
-.Sh RETURN VALUES
-.Fn zip_strerror
-returns a pointer to the error string.
+.Pp
+The
+.Fn zip_file_error_clear
+function does the same for the zip file
+.Ar file .
 .Sh SEE ALSO
-.Xr zip_error_str 3
+.Xr libzip 3 ,
+.Xr zip_error_get 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_error_str.man b/man/zip_error_get.man
similarity index 60%
copy from man/zip_error_str.man
copy to man/zip_error_get.man
index 630a864..2d9efef 100644
--- a/man/zip_error_str.man
+++ b/man/zip_error_get.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_error_str.mdoc,v 1.1 2003/12/27 22:25:58 wiz Exp 
-.\" $NiH: zip_error_str.mdoc,v 1.1 2003/12/27 22:25:58 wiz Exp $
+.\" from NiH: zip_error_get.mdoc,v 1.10 2006/10/04 18:34:03 wiz Exp 
+.\" $NiH: zip_error_get.mdoc,v 1.10 2006/10/04 18:34:03 wiz Exp $
 .\"
-.\" zip_error_str.mdoc \-- get string representation of zip error code
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_error_get.mdoc \-- get error codes for archive or file
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,42 +33,52 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_STRERROR 3 "October 3, 2003" NiH
+.TH ZIP_ERROR_GET 3 "October 4, 2006" NiH
 .SH "NAME"
-zip_error_str \- get string representation of zip error
+zip_error_get , \- .Nm zip_file_error_get
+get error codes for archive or file
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_error_str "char *buf" "int len" "int ze" "int se"
+#include <zip.h>
+.PP
+void
+zip_error_get(struct zip *archive, int *zep, int *sep);
+.PP
+void
+zip_file_error_get(struct zip_file *file, int *zep, int *sep);
 .SH "DESCRIPTION"
 The
-.Fn zip_error_str
-function returns a string describing the zip error code
-\fBze\fR
-in
-\fBbuf\fR
-which has size
-\fBlen.\fR
-\fBse\fR
-should be the value of the global variable
-\fBerrno\fR
-at the time of the error.
-.Fn zip_error_str
-is especially useful if
-.Fn zip_open
-failed and no
-.Vt struct zip
-is available; otherwise
-.Fn zip_strerror
-should be used.
-.SH "RETURN VALUES"
-.Fn zip_error_str
-returns the number of characters that would have been written to a
-sufficiently sized
-\fBbuf,\fR
-excluding the terminating NUL character.
+zip_error_get
+function returns the error codes for the zip archive
+\fBarchive.\fR
+If
+\fBzep\fR
+is not
+\fBNULL,\fR
+\fB*zep\fR
+will be filled in with the error code from libzip.
+Similarly,
+\fB*sep\fR
+will contain the corresponding system error code, if
+\fBsep\fR
+is not
+\fBNULL;\fR
+use
+zip_error_get_sys_type
+to determine the type of system error code.
+.PP
+The
+zip_file_error_get
+function does the same for the zip file
+\fBfile.\fR
 .SH "SEE ALSO"
-zip_open(3),
-zip_strerror(3)
+libzip(3),
+zip_error_clear(3),
+zip_error_get_sys_type(3),
+zip_error_to_str(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_strerror.mdoc b/man/zip_error_get.mdoc
similarity index 61%
copy from man/zip_strerror.mdoc
copy to man/zip_error_get.mdoc
index 529c361..911aebc 100644
--- a/man/zip_strerror.mdoc
+++ b/man/zip_error_get.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH: zip_error_get.mdoc,v 1.9 2006/04/23 12:45:10 wiz Exp $
 .\"
-.\" zip_strerror.mdoc -- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_error_get.mdoc -- get error codes for archive or file
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,30 +31,53 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd October 4, 2006
+.Dt ZIP_ERROR_GET 3
 .Os
 .Sh NAME
-.Nm zip_strerror
-.Nd get string representation of zip error
+.Nm zip_error_get ,
+.Nm zip_file_error_get
+.Nd get error codes for archive or file
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+.Ft void
+.Fn zip_error_get "struct zip *archive" "int *zep" "int *sep"
+.Ft void
+.Fn zip_file_error_get "struct zip_file *file" "int *zep" "int *sep"
 .Sh DESCRIPTION
 The
-.Fn zip_strerror
-function returns a string describing the last error for
+.Fn zip_error_get
+function returns the error codes for the zip archive
 .Ar archive .
-The returned string must not be modified or freed, and becomes invalid when
-.Ar archive
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
-.Sh RETURN VALUES
-.Fn zip_strerror
-returns a pointer to the error string.
+If
+.Ar zep
+is not
+.Dv NULL ,
+.Ar *zep
+will be filled in with the error code from libzip.
+Similarly,
+.Ar *sep
+will contain the corresponding system error code, if
+.Ar sep
+is not
+.Dv NULL ;
+use
+.Fn zip_error_get_sys_type
+to determine the type of system error code.
+.Pp
+The
+.Fn zip_file_error_get
+function does the same for the zip file
+.Ar file .
 .Sh SEE ALSO
-.Xr zip_error_str 3
+.Xr libzip 3 ,
+.Xr zip_error_clear 3 ,
+.Xr zip_error_get_sys_type 3 ,
+.Xr zip_error_to_str 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_strerror.man b/man/zip_error_get_sys_type.man
similarity index 65%
copy from man/zip_strerror.man
copy to man/zip_error_get_sys_type.man
index 3b82061..f0b1abb 100644
--- a/man/zip_strerror.man
+++ b/man/zip_error_get_sys_type.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp 
-.\" $NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp $
+.\" from NiH: zip_error_get_sys_type.mdoc,v 1.5 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_error_get_sys_type.mdoc,v 1.5 2005/06/09 21:14:54 wiz Exp $
 .\"
-.\" zip_strerror.mdoc \-- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_error_get_sys_type.mdoc \-- get type of error
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,27 +33,41 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_STRERROR 3 "October 3, 2003" NiH
+.TH ZIP_ERROR_SYS_TYPE 3 "November 30, 2004" NiH
 .SH "NAME"
-zip_strerror \- get string representation of zip error
+zip_error_get_sys_type \- get type of system error code
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+#include <zip.h>
+.PP
+int
+zip_error_get_sys_type(int ze);
 .SH "DESCRIPTION"
 The
-.Fn zip_strerror
-function returns a string describing the last error for
-\fBarchive.\fR
-The returned string must not be modified or freed, and becomes invalid when
-\fBarchive\fR
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
-.SH "RETURN VALUES"
-.Fn zip_strerror
-returns a pointer to the error string.
+zip_error_get_sys_type
+function returns the type of the system error code for the libzip error
+\fBze.\fR
+Possible types are:
+.RS
+.TP 16
+\fBZIP_ET_NONE\fR
+System error code is unused.
+.TP 16
+\fBZIP_ET_SYS\fR
+System error code is an errno value.
+.TP 16
+\fBZIP_ET_ZLIB\fR
+System error code is from
+zlib(3).
+.RE
 .SH "SEE ALSO"
-zip_error_str(3)
+libzip(3),
+zip_error_get(3),
+zip_error_to_str(3),
+zip_file_error_get(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_strerror.mdoc b/man/zip_error_get_sys_type.mdoc
similarity index 65%
copy from man/zip_strerror.mdoc
copy to man/zip_error_get_sys_type.mdoc
index 529c361..d2a9ef4 100644
--- a/man/zip_strerror.mdoc
+++ b/man/zip_error_get_sys_type.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH: zip_error_get_sys_type.mdoc,v 1.4 2005/06/09 21:13:12 wiz Exp $
 .\"
-.\" zip_strerror.mdoc -- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_error_get_sys_type.mdoc -- get type of error
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,30 +31,40 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd November 30, 2004
+.Dt ZIP_ERROR_SYS_TYPE 3
 .Os
 .Sh NAME
-.Nm zip_strerror
-.Nd get string representation of zip error
+.Nm zip_error_get_sys_type
+.Nd get type of system error code
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+.Ft int
+.Fn zip_error_get_sys_type "int ze"
 .Sh DESCRIPTION
 The
-.Fn zip_strerror
-function returns a string describing the last error for
-.Ar archive .
-The returned string must not be modified or freed, and becomes invalid when
-.Ar archive
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
-.Sh RETURN VALUES
-.Fn zip_strerror
-returns a pointer to the error string.
+.Fn zip_error_get_sys_type
+function returns the type of the system error code for the libzip error
+.Ar ze .
+Possible types are:
+.Bl -tag -width XZIP_ET_NONEXX -offset indent -compact
+.It Dv ZIP_ET_NONE
+System error code is unused.
+.It Dv ZIP_ET_SYS
+System error code is an errno value.
+.It Dv ZIP_ET_ZLIB
+System error code is from
+.Xr zlib 3 .
+.El
 .Sh SEE ALSO
-.Xr zip_error_str 3
+.Xr libzip 3 ,
+.Xr zip_error_get  3 ,
+.Xr zip_error_to_str  3 ,
+.Xr zip_file_error_get  3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_error_str.man b/man/zip_error_to_str.man
similarity index 66%
rename from man/zip_error_str.man
rename to man/zip_error_to_str.man
index 630a864..b9d1460 100644
--- a/man/zip_error_str.man
+++ b/man/zip_error_to_str.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_error_str.mdoc,v 1.1 2003/12/27 22:25:58 wiz Exp 
-.\" $NiH: zip_error_str.mdoc,v 1.1 2003/12/27 22:25:58 wiz Exp $
+.\" from NiH: zip_error_to_str.mdoc,v 1.8 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_error_to_str.mdoc,v 1.8 2005/06/09 21:14:54 wiz Exp $
 .\"
-.\" zip_error_str.mdoc \-- get string representation of zip error code
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_error_to_str.mdoc \-- get string representation of zip error code
+.\" Copyright (C) 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,42 +33,58 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_STRERROR 3 "October 3, 2003" NiH
+.TH ZIP_ERROR_TO_STR 3 "November 24, 2004" NiH
 .SH "NAME"
-zip_error_str \- get string representation of zip error
+zip_error_to_str \- get string representation of zip error
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_error_str "char *buf" "int len" "int ze" "int se"
+#include <zip.h>
+.PP
+int
+zip_error_to_str(char *buf, int len, int ze, int se);
 .SH "DESCRIPTION"
 The
-.Fn zip_error_str
-function returns a string describing the zip error code
+zip_error_to_str
+function stores a string describing the libzip error code
 \fBze\fR
-in
+in the user-provided buffer
 \fBbuf\fR
 which has size
 \fBlen.\fR
+The buffer is always NUL-terminated.
 \fBse\fR
 should be the value of the global variable
 \fBerrno\fR
-at the time of the error.
-.Fn zip_error_str
+at the time of the error or the zlib error code, depending on
+\fBze.\fR
+.PP
+zip_error_to_str
 is especially useful if
-.Fn zip_open
-failed and no
+zip_open
+failed, since then there is no
 .Vt struct zip
-is available; otherwise
-.Fn zip_strerror
-should be used.
+is available to store the error code; otherwise
+zip_strerror
+or
+zip_file_strerror
+are more convenient.
 .SH "RETURN VALUES"
-.Fn zip_error_str
+zip_error_to_str
 returns the number of characters that would have been written to a
 sufficiently sized
 \fBbuf,\fR
 excluding the terminating NUL character.
 .SH "SEE ALSO"
+libzip(3),
+zip_error_get(3),
+zip_error_get_sys_type(3),
+zip_file_error_get(3),
+zip_file_strerror(3),
 zip_open(3),
 zip_strerror(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_error_str.mdoc b/man/zip_error_to_str.mdoc
similarity index 68%
rename from man/zip_error_str.mdoc
rename to man/zip_error_to_str.mdoc
index 31cb1df..4754f4b 100644
--- a/man/zip_error_str.mdoc
+++ b/man/zip_error_to_str.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH$
+.\" $NiH: zip_error_to_str.mdoc,v 1.7 2005/06/09 21:13:12 wiz Exp $
 .\"
-.\" zip_error_str.mdoc -- get string representation of zip error code
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_error_to_str.mdoc -- get string representation of zip error code
+.\" Copyright (C) 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,45 +31,60 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd November 24, 2004
+.Dt ZIP_ERROR_TO_STR 3
 .Os
 .Sh NAME
-.Nm zip_error_str
+.Nm zip_error_to_str
 .Nd get string representation of zip error
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
 .Ft int
-.Fn zip_error_str "char *buf" "int len" "int ze" "int se"
+.Fn zip_error_to_str "char *buf" "int len" "int ze" "int se"
 .Sh DESCRIPTION
 The
-.Fn zip_error_str
-function returns a string describing the zip error code
+.Fn zip_error_to_str
+function stores a string describing the libzip error code
 .Ar ze
-in
+in the user-provided buffer
 .Ar buf
 which has size
 .Ar len .
+The buffer is always NUL-terminated.
 .Ar se
 should be the value of the global variable
 .Ar errno
-at the time of the error.
-.Fn zip_error_str
+at the time of the error or the zlib error code, depending on
+.Ar ze .
+.Pp
+.Fn zip_error_to_str
 is especially useful if
 .Fn zip_open
-failed and no
+failed, since then there is no
 .Vt struct zip
-is available; otherwise
+is available to store the error code; otherwise
 .Fn zip_strerror
-should be used.
+or
+.Fn zip_file_strerror
+are more convenient.
 .Sh RETURN VALUES
-.Fn zip_error_str
+.Fn zip_error_to_str
 returns the number of characters that would have been written to a
 sufficiently sized
 .Ar buf ,
 excluding the terminating NUL character.
 .Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_error_get 3 ,
+.Xr zip_error_get_sys_type 3 ,
+.Xr zip_file_error_get 3 ,
+.Xr zip_file_strerror 3 ,
 .Xr zip_open 3 ,
 .Xr zip_strerror 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_errors.man b/man/zip_errors.man
new file mode 100644
index 0000000..c8e2fdd
--- /dev/null
+++ b/man/zip_errors.man
@@ -0,0 +1,128 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_errors.mdoc,v 1.6 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_errors.mdoc,v 1.6 2005/06/09 21:14:54 wiz Exp $
+.\"
+.\" zip_errors.mdoc \-- list of all libzip error codes
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\"   This file was generated automatically by./make_zip_errors.sh
+.\"   from./../lib/zip.h; make changes there.
+.\"	NiH: make_zip_errors.sh,v 1.3 2005/01/20 21:03:36 dillo Exp 
+.\"	NiH: zip.h,v 1.48 2005/01/20 21:00:29 dillo Exp
+.\"
+.TH ZIP_ERRORS 3 "January 20, 2005" NiH
+.SH "NAME"
+zip_errors \- list of all libzip error codes
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.SH "DESCRIPTION"
+The following error codes are used by libzip:
+.RS
+.TP 23
+[ZIP_ER_OK]
+No error.
+.TP 23
+[ZIP_ER_MULTIDISK]
+Multi-disk zip archives not supported.
+.TP 23
+[ZIP_ER_RENAME]
+Renaming temporary file failed.
+.TP 23
+[ZIP_ER_CLOSE]
+Closing zip archive failed.
+.TP 23
+[ZIP_ER_SEEK]
+Seek error.
+.TP 23
+[ZIP_ER_READ]
+Read error.
+.TP 23
+[ZIP_ER_WRITE]
+Write error.
+.TP 23
+[ZIP_ER_CRC]
+CRC error.
+.TP 23
+[ZIP_ER_ZIPCLOSED]
+Containing zip archive was closed.
+.TP 23
+[ZIP_ER_NOENT]
+No such file.
+.TP 23
+[ZIP_ER_EXISTS]
+File already exists.
+.TP 23
+[ZIP_ER_OPEN]
+Can't open file.
+.TP 23
+[ZIP_ER_TMPOPEN]
+Failure to create temporary file.
+.TP 23
+[ZIP_ER_ZLIB]
+Zlib error.
+.TP 23
+[ZIP_ER_MEMORY]
+Malloc failure.
+.TP 23
+[ZIP_ER_CHANGED]
+Entry has been changed.
+.TP 23
+[ZIP_ER_COMPNOTSUPP]
+Compression method not supported.
+.TP 23
+[ZIP_ER_EOF]
+Premature EOF.
+.TP 23
+[ZIP_ER_INVAL]
+Invalid argument.
+.TP 23
+[ZIP_ER_NOZIP]
+Not a zip archive.
+.TP 23
+[ZIP_ER_INTERNAL]
+Internal error.
+.TP 23
+[ZIP_ER_INCONS]
+Zip archive inconsistent.
+.TP 23
+[ZIP_ER_REMOVE]
+Can't remove file.
+.TP 23
+[ZIP_ER_DELETED]
+Entry has been deleted.
+.RE
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_errors.mdoc b/man/zip_errors.mdoc
new file mode 100644
index 0000000..a2f1f86
--- /dev/null
+++ b/man/zip_errors.mdoc
@@ -0,0 +1,105 @@
+.\" $NiH: zip_errors.mdoc,v 1.5 2005/06/09 21:13:12 wiz Exp $
+.\"
+.\" zip_errors.mdoc -- list of all libzip error codes
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.\"   This file was generated automatically by ./make_zip_errors.sh
+.\"   from ./../lib/zip.h; make changes there.
+.\"	NiH: make_zip_errors.sh,v 1.3 2005/01/20 21:03:36 dillo Exp 
+.\"	NiH: zip.h,v 1.48 2005/01/20 21:00:29 dillo Exp
+.\"
+.Dd January 20, 2005
+.Dt ZIP_ERRORS 3
+.Os
+.Sh NAME
+.Nm zip_errors
+.Nd list of all libzip error codes
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.In zip.h
+.Sh DESCRIPTION
+The following error codes are used by libzip:
+.Bl -tag -width XZIPXERXCOMPNOTSUPPXX
+.It Bq Er ZIP_ER_OK
+No error.
+.It Bq Er ZIP_ER_MULTIDISK
+Multi-disk zip archives not supported.
+.It Bq Er ZIP_ER_RENAME
+Renaming temporary file failed.
+.It Bq Er ZIP_ER_CLOSE
+Closing zip archive failed.
+.It Bq Er ZIP_ER_SEEK
+Seek error.
+.It Bq Er ZIP_ER_READ
+Read error.
+.It Bq Er ZIP_ER_WRITE
+Write error.
+.It Bq Er ZIP_ER_CRC
+CRC error.
+.It Bq Er ZIP_ER_ZIPCLOSED
+Containing zip archive was closed.
+.It Bq Er ZIP_ER_NOENT
+No such file.
+.It Bq Er ZIP_ER_EXISTS
+File already exists.
+.It Bq Er ZIP_ER_OPEN
+Can't open file.
+.It Bq Er ZIP_ER_TMPOPEN
+Failure to create temporary file.
+.It Bq Er ZIP_ER_ZLIB
+Zlib error.
+.It Bq Er ZIP_ER_MEMORY
+Malloc failure.
+.It Bq Er ZIP_ER_CHANGED
+Entry has been changed.
+.It Bq Er ZIP_ER_COMPNOTSUPP
+Compression method not supported.
+.It Bq Er ZIP_ER_EOF
+Premature EOF.
+.It Bq Er ZIP_ER_INVAL
+Invalid argument.
+.It Bq Er ZIP_ER_NOZIP
+Not a zip archive.
+.It Bq Er ZIP_ER_INTERNAL
+Internal error.
+.It Bq Er ZIP_ER_INCONS
+Zip archive inconsistent.
+.It Bq Er ZIP_ER_REMOVE
+Can't remove file.
+.It Bq Er ZIP_ER_DELETED
+Entry has been deleted.
+.El
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_fclose.man b/man/zip_fclose.man
index e074271..a0be20a 100644
--- a/man/zip_fclose.man
+++ b/man/zip_fclose.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_fclose.mdoc,v 1.3 2003/10/03 23:40:00 wiz Exp 
-.\" $NiH: zip_fclose.mdoc,v 1.3 2003/10/03 23:40:00 wiz Exp $
+.\" from NiH: zip_fclose.mdoc,v 1.9 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_fclose.mdoc,v 1.9 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_fclose.mdoc \-- close file in zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -39,22 +39,25 @@
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_fclose "struct zip_file *file"
+#include <zip.h>
+.PP
+int
+zip_fclose(struct zip_file *file);
 .SH "DESCRIPTION"
 The
-.Fn zip_fclose
+zip_fclose
 function closes
 \fBfile\fR
 and frees the memory allocated for it.
 .SH "RETURN VALUES"
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
-is set to indicate the error.
-.\".SH "ERRORS"
-.\" XXX: the code needs checking.
+Otherwise, the error code is returned.
 .SH "SEE ALSO"
+libzip(3),
 zip_fopen(3),
 zip_fread(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_fclose.mdoc b/man/zip_fclose.mdoc
index 0092998..b4809a1 100644
--- a/man/zip_fclose.mdoc
+++ b/man/zip_fclose.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_fclose.mdoc,v 1.2 2003/10/03 12:04:08 dillo Exp $
+.\" $NiH: zip_fclose.mdoc,v 1.8 2005/06/09 21:13:12 wiz Exp $
 .\"
 .\" zip_fclose.mdoc -- close file in zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -51,11 +51,13 @@
 and frees the memory allocated for it.
 .Sh RETURN VALUES
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
-is set to indicate the error.
-.\" .Sh ERRORS
-.\" XXX: the code needs checking.
+Otherwise, the error code is returned.
 .Sh SEE ALSO
+.Xr libzip 3 ,
 .Xr zip_fopen 3 ,
 .Xr zip_fread 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_file_strerror.man b/man/zip_file_strerror.man
index f024363..a995bf0 100644
--- a/man/zip_file_strerror.man
+++ b/man/zip_file_strerror.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_file_strerror.mdoc,v 1.2 2003/12/27 22:27:27 wiz Exp 
-.\" $NiH: zip_file_strerror.mdoc,v 1.2 2003/12/27 22:27:27 wiz Exp $
+.\" from NiH: zip_file_strerror.mdoc,v 1.7 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_file_strerror.mdoc,v 1.7 2005/06/09 21:14:54 wiz Exp $
 .\"
-.\" zip_file_strerror.mdoc \-- get string representation of zip file error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_file_strerror.mdoc \-- get string representation for a zip error
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,26 +33,51 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_FILE_STRERROR 3 "October 3, 2003" NiH
+.TH ZIP_FILE_STRERROR 3 "December 27, 2004" NiH
 .SH "NAME"
-zip_file_strerror \- get string representation of zip file error
+zip_file_strerror , \- .Nm zip_strerror
+get string representation for a zip error
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft const char *
-.Fn zip_file_strerror "struct zip_file *file"
+#include <zip.h>
+.PP
+const char *
+zip_file_strerror(struct zip_file *file);
+.PP
+const char *
+zip_strerror(struct zip *archive);
 .SH "DESCRIPTION"
 The
-.Fn zip_file_strerror
-function returns a string describing the last error for
-\fBfile.\fR
-The returned string must not be modified or freed, and becomes invalid when
+zip_strerror
+function returns a string describing the last error for the zip archive
+\fBarchive,\fR
+while the
+zip_file_strerror
+function does the same for a zip file
 \fBfile\fR
+(one file in an archive).
+The returned string must not be modified or freed, and becomes invalid when
+\fBarchive\fR
+or
+\fBfile,\fR
+respectively,
 is closed or on the next call to
-.Fn zip_file_strerror
-for the same zip file.
+zip_strerror
+or
+zip_file_strerror,
+respectively,
+for the same archive.
 .SH "RETURN VALUES"
-.Fn zip_file_strerror
-returns a pointer to the error string.
-.\".SH "SEE ALSO"
+zip_file_strerror
+and
+zip_strerror
+return a pointer to the error string.
+.SH "SEE ALSO"
+libzip(3),
+zip_error_to_str(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_file_strerror.mdoc b/man/zip_file_strerror.mdoc
index 64541a6..e56d8af 100644
--- a/man/zip_file_strerror.mdoc
+++ b/man/zip_file_strerror.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_file_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH: zip_file_strerror.mdoc,v 1.6 2005/06/09 21:13:12 wiz Exp $
 .\"
-.\" zip_file_strerror.mdoc -- get string representation of zip file error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_file_strerror.mdoc -- get string representation for a zip error
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,29 +31,52 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
+.Dd December 27, 2004
 .Dt ZIP_FILE_STRERROR 3
 .Os
 .Sh NAME
-.Nm zip_file_strerror
-.Nd get string representation of zip file error
+.Nm zip_file_strerror ,
+.Nm zip_strerror
+.Nd get string representation for a zip error
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
 .Ft const char *
 .Fn zip_file_strerror "struct zip_file *file"
+.Ft const char *
+.Fn zip_strerror "struct zip *archive"
 .Sh DESCRIPTION
 The
+.Fn zip_strerror
+function returns a string describing the last error for the zip archive
+.Ar archive ,
+while the
 .Fn zip_file_strerror
-function returns a string describing the last error for
-.Ar file .
-The returned string must not be modified or freed, and becomes invalid when
+function does the same for a zip file
 .Ar file
+(one file in an archive).
+The returned string must not be modified or freed, and becomes invalid when
+.Ar archive
+or
+.Ar file ,
+respectively,
 is closed or on the next call to
-.Fn zip_file_strerror
-for the same zip file.
+.Fn zip_strerror
+or
+.Fn zip_file_strerror ,
+respectively,
+for the same archive.
 .Sh RETURN VALUES
 .Fn zip_file_strerror
-returns a pointer to the error string.
-.\" .Sh SEE ALSO
+and
+.Fn zip_strerror
+return a pointer to the error string.
+.Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_error_to_str 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_fopen.man b/man/zip_fopen.man
index 6c232d8..b4f7bf9 100644
--- a/man/zip_fopen.man
+++ b/man/zip_fopen.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_fopen.mdoc,v 1.5 2003/10/06 16:37:07 dillo Exp 
-.\" $NiH: zip_fopen.mdoc,v 1.5 2003/10/06 16:37:07 dillo Exp $
+.\" from NiH: zip_fopen.mdoc,v 1.14 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_fopen.mdoc,v 1.14 2005/06/09 21:14:54 wiz Exp $
 .\"
-.\" zip_fopen.mdoc \-- open file in zip archvie for reading
-.\" Copyright (C) 2003, 2004 Dieter Baron and Thomas Klausner
+.\" zip_fopen.mdoc \-- open file in zip archive for reading
+.\" Copyright (C) 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -40,14 +40,16 @@
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft struct zip_file *
-.Fn zip_fopen "struct zip *archive" "const char *fname" "int flags"
-.Ft struct zip_file *
-.Fn zip_fopen_index "struct zip *archive" "int index" "int flags"
+#include <zip.h>
+.PP
+struct zip_file *
+zip_fopen(struct zip *archive, const char *fname, int flags);
+.PP
+struct zip_file *
+zip_fopen_index(struct zip *archive, int index, int flags);
 .SH "DESCRIPTION"
 The
-.Fn zip_fopen
+zip_fopen
 function opens the file name
 \fBfname\fR
 in
@@ -58,69 +60,77 @@
 the values are described in
 zip_name_locate(3).
 Also, the following values may be
-.I orNo 'ed
+.I or'ed
 to it.
 .RS
 .TP 19
-Dv ZIP_FL_COMPRESSED
-Read the compressed data.  Otherwise the data is uncompressed by 
-.Fn zip_fread.
+\fBZIP_FL_COMPRESSED\fR
+Read the compressed data.
+Otherwise the data is uncompressed by
+zip_fread.
 .TP 19
-Dv ZIP_FL_UNCHANGED
+\fBZIP_FL_UNCHANGED\fR
 Read the original data from the zip archive, ignoring any changes made
 to the file.
 .RE
 .PP
 The
-.Fn zip_fopen_index
+zip_fopen_index
 function opens the file at position
 \fBindex.\fR
 .SH "RETURN VALUES"
 Upon successful completion, a
-.Ft struct zip_file
+.PP
+struct zip_file
 pointer is returned.
 Otherwise,
-.Dv NULL
+\fBNULL\fR
 is returned and the error code in
 \fBarchive\fR
 is set to indicate the error.
 .SH "ERRORS"
 .RS
 .TP 4
-Bq Er ZERR_CHANGED
+[ZIP_ER_CHANGED]
 The file data has been changed.
 .TP 4
-Bq Er ZERR_COMPNOTSUPP
+[ZIP_ER_COMPNOTSUPP]
 The compression method used is not supported.
 .TP 4
-Bq Er ZERR_MEMORY
+[ZIP_ER_MEMORY]
 Required memory could not be allocated.
 .TP 4
-Bq Er ZERR_READ
+[ZIP_ER_READ]
 A file read error occurred.
 .TP 4
-Bq Er ZERR_SEEK
+[ZIP_ER_SEEK]
 A file seek error occurred.
 .TP 4
-Bq Er ZERR_ZLIB
+[ZIP_ER_ZLIB]
 Initializing the zlib stream failed.
 .RE
 .PP
 The function
-.Fn zip_fopen
+zip_fopen
 may also fail and set
 .Va zip_err
 for any of the errors specified for the routine
 zip_name_locate(3).
 .PP
 The function
-.Fn zip_fopen_index
+zip_fopen_index
 may also fail with
-.Er ZERR_INVAL
+ZIP_ER_INVAL
 if
 \fBindex\fR
 is invalid.
 .SH "SEE ALSO"
+libzip(3),
 zip_fclose(3),
 zip_fread(3),
 zip_name_locate(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_fopen.mdoc b/man/zip_fopen.mdoc
index 11bd178..8b1c814 100644
--- a/man/zip_fopen.mdoc
+++ b/man/zip_fopen.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_fopen.mdoc,v 1.5 2003/10/06 16:37:07 dillo Exp $
+.\" $NiH: zip_fopen.mdoc,v 1.13 2005/06/09 21:13:12 wiz Exp $
 .\"
-.\" zip_fopen.mdoc -- open file in zip archvie for reading
-.\" Copyright (C) 2003, 2004 Dieter Baron and Thomas Klausner
+.\" zip_fopen.mdoc -- open file in zip archive for reading
+.\" Copyright (C) 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -63,7 +63,8 @@
 to it.
 .Bl -tag -offset indent -width ZIP_FL_COMPRESSED
 .It Dv ZIP_FL_COMPRESSED
-Read the compressed data.  Otherwise the data is uncompressed by 
+Read the compressed data.
+Otherwise the data is uncompressed by
 .Fn zip_fread .
 .It Dv ZIP_FL_UNCHANGED
 Read the original data from the zip archive, ignoring any changes made
@@ -85,17 +86,17 @@
 is set to indicate the error.
 .Sh ERRORS
 .Bl -tag -width Er
-.It Bq Er ZERR_CHANGED
+.It Bq Er ZIP_ER_CHANGED
 The file data has been changed.
-.It Bq Er ZERR_COMPNOTSUPP
+.It Bq Er ZIP_ER_COMPNOTSUPP
 The compression method used is not supported.
-.It Bq Er ZERR_MEMORY
+.It Bq Er ZIP_ER_MEMORY
 Required memory could not be allocated.
-.It Bq Er ZERR_READ
+.It Bq Er ZIP_ER_READ
 A file read error occurred.
-.It Bq Er ZERR_SEEK
+.It Bq Er ZIP_ER_SEEK
 A file seek error occurred.
-.It Bq Er ZERR_ZLIB
+.It Bq Er ZIP_ER_ZLIB
 Initializing the zlib stream failed.
 .El
 .Pp
@@ -109,11 +110,17 @@
 The function
 .Fn zip_fopen_index
 may also fail with
-.Er ZERR_INVAL
+.Er ZIP_ER_INVAL
 if
 .Ar index
 is invalid.
 .Sh SEE ALSO
+.Xr libzip 3 ,
 .Xr zip_fclose 3 ,
 .Xr zip_fread 3 ,
 .Xr zip_name_locate 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_fread.man b/man/zip_fread.man
index db4c530..c00c759 100644
--- a/man/zip_fread.man
+++ b/man/zip_fread.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_fread.mdoc,v 1.3 2003/10/03 23:36:25 wiz Exp 
-.\" $NiH: zip_fread.mdoc,v 1.3 2003/10/03 23:36:25 wiz Exp $
+.\" from NiH: zip_fread.mdoc,v 1.9 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_fread.mdoc,v 1.9 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_fread.mdoc \-- read from file
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -39,13 +39,13 @@
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.\" XXX: buf should be void *
-.Fn zip_fread "struct zip_file *file" "char *buf" "int nbytes"
+#include <zip.h>
+.PP
+int
+zip_fread(struct zip_file *file, void *buf, int nbytes);
 .SH "DESCRIPTION"
 The
-.Fn zip_fread
+zip_fread
 function reads at most
 \fBnbytes\fR
 bytes from
@@ -55,8 +55,12 @@
 .SH "RETURN VALUES"
 If successful, the number of bytes actually read is returned.
 Otherwise, \-1 is returned.
-.\".SH "ERRORS"
-.\" XXX: the code needs checking.
 .SH "SEE ALSO"
+libzip(3),
 zip_fclose(3),
 zip_fopen(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_fread.mdoc b/man/zip_fread.mdoc
index 83f116d..ce190b3 100644
--- a/man/zip_fread.mdoc
+++ b/man/zip_fread.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_fread.mdoc,v 1.2 2003/10/03 12:04:08 dillo Exp $
+.\" $NiH: zip_fread.mdoc,v 1.8 2005/06/09 21:13:12 wiz Exp $
 .\"
 .\" zip_fread.mdoc -- read from file
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -42,8 +42,7 @@
 .Sh SYNOPSIS
 .In zip.h
 .Ft int
-.\" XXX: buf should be void *
-.Fn zip_fread "struct zip_file *file" "char *buf" "int nbytes"
+.Fn zip_fread "struct zip_file *file" "void *buf" "int nbytes"
 .Sh DESCRIPTION
 The
 .Fn zip_fread
@@ -56,8 +55,12 @@
 .Sh RETURN VALUES
 If successful, the number of bytes actually read is returned.
 Otherwise, \-1 is returned.
-.\" .Sh ERRORS
-.\" XXX: the code needs checking.
 .Sh SEE ALSO
+.Xr libzip 3 ,
 .Xr zip_fclose 3 ,
 .Xr zip_fopen 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_get_archive_comment.man b/man/zip_get_archive_comment.man
new file mode 100644
index 0000000..e584776
--- /dev/null
+++ b/man/zip_get_archive_comment.man
@@ -0,0 +1,81 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_get_archive_comment.mdoc,v 1.2 2006/04/23 13:06:29 wiz Exp 
+.\" $NiH: zip_get_archive_comment.mdoc,v 1.2 2006/04/23 13:06:29 wiz Exp $
+.\"
+.\" zip_get_archive_comment.mdoc \-- get zip archive comment
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_GET_ARCHIVE_COMMENT 3 "April 23, 2006" NiH
+.SH "NAME"
+zip_get_archive_comment \- get zip archive comment
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.PP
+const char *
+zip_get_archive_comment(struct zip *archive, int *lenp, int flags);
+.SH "DESCRIPTION"
+The
+zip_get_archive_comment
+function returns the comment for the entire zip archive.
+This pointer should not be modified or
+free(3)
+Ap d.
+If
+\fBlenp\fR
+is not
+\fBNULL,\fR
+the integer to which it points will be set to the length of the
+comment.
+If
+\fBflags\fR
+is set to
+\fBZIP_FL_UNCHANGED,\fR
+the original unchanged comment is returned.
+.SH "RETURN VALUES"
+Upon successful completion, a pointer to the comment is returned,
+or
+\fBNULL\fR
+if there is no comment.
+.\" In case of an error,
+.\" \fBNULL\fR
+.\" is returned and the error code in
+.\" \fBarchive\fR
+.\" is set to indicate the error.
+.SH "SEE ALSO"
+libzip(3),
+zip_get_file_comment(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_strerror.mdoc b/man/zip_get_archive_comment.mdoc
similarity index 61%
copy from man/zip_strerror.mdoc
copy to man/zip_get_archive_comment.mdoc
index 529c361..43f4dfe 100644
--- a/man/zip_strerror.mdoc
+++ b/man/zip_get_archive_comment.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH: zip_get_archive_comment.mdoc,v 1.1 2006/04/09 19:05:48 wiz Exp $
 .\"
-.\" zip_strerror.mdoc -- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_get_archive_comment.mdoc -- get zip archive comment
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,30 +31,50 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd April 23, 2006
+.Dt ZIP_GET_ARCHIVE_COMMENT 3
 .Os
 .Sh NAME
-.Nm zip_strerror
-.Nd get string representation of zip error
+.Nm zip_get_archive_comment
+.Nd get zip archive comment
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
 .Ft const char *
-.Fn zip_strerror "struct zip *archive"
+.Fn zip_get_archive_comment "struct zip *archive" "int *lenp" "int flags"
 .Sh DESCRIPTION
 The
-.Fn zip_strerror
-function returns a string describing the last error for
-.Ar archive .
-The returned string must not be modified or freed, and becomes invalid when
-.Ar archive
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
+.Fn zip_get_archive_comment
+function returns the comment for the entire zip archive.
+This pointer should not be modified or
+.Xr free 3 Ap d .
+If
+.Ar lenp
+is not
+.Dv NULL ,
+the integer to which it points will be set to the length of the
+comment.
+If
+.Ar flags
+is set to
+.Dv ZIP_FL_UNCHANGED ,
+the original unchanged comment is returned.
 .Sh RETURN VALUES
-.Fn zip_strerror
-returns a pointer to the error string.
+Upon successful completion, a pointer to the comment is returned,
+or
+.Dv NULL
+if there is no comment.
+.\" In case of an error,
+.\" .Dv NULL
+.\" is returned and the error code in
+.\" .Ar archive
+.\" is set to indicate the error.
 .Sh SEE ALSO
-.Xr zip_error_str 3
+.Xr libzip 3 ,
+.Xr zip_get_file_comment 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_get_file_comment.man b/man/zip_get_file_comment.man
new file mode 100644
index 0000000..4b4dfdb
--- /dev/null
+++ b/man/zip_get_file_comment.man
@@ -0,0 +1,92 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_get_file_comment.mdoc,v 1.4 2006/04/23 13:06:29 wiz Exp 
+.\" $NiH: zip_get_file_comment.mdoc,v 1.4 2006/04/23 13:06:29 wiz Exp $
+.\"
+.\" zip_get_file_comment.mdoc \-- get comment for file in zip
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP files.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_GET_FILE_COMMENT 3 "April 23, 2006" NiH
+.SH "NAME"
+zip_get_file_comment \- get comment for file in zip
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.PP
+const char *
+zip_get_file_comment(struct zip *archive, int index, int *lenp, int flags);
+.SH "DESCRIPTION"
+The
+zip_get_file_comment
+function returns the comment for the file at position
+\fBindex\fR
+in the zip archive.
+This pointer should not be modified or
+free(3)
+Ap d.
+If
+\fBlenp\fR
+is not
+\fBNULL,\fR
+the integer to which it points will be set to the length of the
+comment.
+If
+\fBflags\fR
+is set to
+\fBZIP_FL_UNCHANGED,\fR
+the original unchanged comment is returned.
+.SH "RETURN VALUES"
+Upon successful completion, a pointer to the comment is returned,
+or
+\fBNULL\fR
+if there is no comment.
+In case of an error,
+\fBNULL\fR
+is returned and the error code in
+\fBarchive\fR
+is set to indicate the error.
+.SH "ERRORS"
+zip_get_file_comment
+fails if:
+.RS
+.TP 4
+[ZIP_ER_INVAL]
+\fBindex\fR
+is not a valid file index in
+\fBarchive.\fR
+.SH "SEE ALSO"
+libzip(3),
+zip_get_archive_comment(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_get_file_comment.mdoc b/man/zip_get_file_comment.mdoc
new file mode 100644
index 0000000..cf05456
--- /dev/null
+++ b/man/zip_get_file_comment.mdoc
@@ -0,0 +1,90 @@
+.\" $NiH: zip_get_file_comment.mdoc,v 1.3 2006/04/23 12:45:31 wiz Exp $
+.\"
+.\" zip_get_file_comment.mdoc -- get comment for file in zip
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP files.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 23, 2006
+.Dt ZIP_GET_FILE_COMMENT 3
+.Os
+.Sh NAME
+.Nm zip_get_file_comment
+.Nd get comment for file in zip
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.In zip.h
+.Ft const char *
+.Fn zip_get_file_comment "struct zip *archive" "int index" "int *lenp" "int flags"
+.Sh DESCRIPTION
+The
+.Fn zip_get_file_comment
+function returns the comment for the file at position
+.Ar index
+in the zip archive.
+This pointer should not be modified or
+.Xr free 3 Ap d .
+If
+.Ar lenp
+is not
+.Dv NULL ,
+the integer to which it points will be set to the length of the
+comment.
+If
+.Ar flags
+is set to
+.Dv ZIP_FL_UNCHANGED ,
+the original unchanged comment is returned.
+.Sh RETURN VALUES
+Upon successful completion, a pointer to the comment is returned,
+or
+.Dv NULL
+if there is no comment.
+In case of an error,
+.Dv NULL
+is returned and the error code in
+.Ar archive
+is set to indicate the error.
+.Sh ERRORS
+.Fn zip_get_file_comment
+fails if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_INVAL
+.Ar index
+is not a valid file index in
+.Ar archive .
+.Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_get_archive_comment 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_get_name.man b/man/zip_get_name.man
index 7da7d26..d760266 100644
--- a/man/zip_get_name.man
+++ b/man/zip_get_name.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_get_name.mdoc,v 1.3 2003/12/27 22:50:28 wiz Exp 
-.\" $NiH: zip_get_name.mdoc,v 1.3 2003/12/27 22:50:28 wiz Exp $
+.\" from NiH: zip_get_name.mdoc,v 1.10 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_get_name.mdoc,v 1.10 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_get_name.mdoc \-- get name of file by index
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,40 +33,64 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_GET_NAME 3 "October 3, 2003" NiH
+.TH ZIP_GET_NAME 3 "January 20, 2005" NiH
 .SH "NAME"
 zip_get_name \- get name of file by index
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft const char *
-.Fn zip_get_name "struct zip *archive" "int index"
+#include <zip.h>
+.PP
+const char *
+zip_get_name(struct zip *archive, int index, int flags);
 .SH "DESCRIPTION"
 The
-.Fn zip_get_name
+zip_get_name
 function returns the name of the file at position
 \fBindex\fR
 in
 \fBarchive.\fR
+If
+\fBflags\fR
+is set to
+\fBZIP_FL_UNCHANGED,\fR
+the original unchanged filename is returned.
 The returned string must not be modified or freed, and becomes invalid when
 \fBarchive\fR
 is closed.
 .SH "RETURN VALUES"
 Upon successful completion, a pointer to the name is returned.
 Otherwise,
-.Dv NULL
-is returned and the global variable
-.Va zip_err
+\fBNULL\fR
+and the error code in
+\fBarchive\fR
 is set to indicate the error.
 .SH "ERRORS"
-.Fn zip_get_name
+zip_get_name
 fails if:
 .RS
 .TP 4
-Bq Er ZERR_INVAL
+[ZIP_ER_DELETED]
+\fBindex\fR
+refers to a file that has been deleted
+(see
+zip_delete(3)
+).
+.TP 4
+[ZIP_ER_INVAL]
 \fBindex\fR
 is not a valid file index in
-\fBarchive.\fR
+\fBarchive,\fR
+or
+\fBindex\fR
+points to an added file and
+\fBZIP_FL_UNCHANGED\fR
+is set.
 .SH "SEE ALSO"
+libzip(3),
 zip_name_locate(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_get_name.mdoc b/man/zip_get_name.mdoc
index a03c77f..2965f83 100644
--- a/man/zip_get_name.mdoc
+++ b/man/zip_get_name.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_get_name.mdoc,v 1.2 2003/10/03 23:34:23 wiz Exp $
+.\" $NiH: zip_get_name.mdoc,v 1.9 2005/06/09 21:13:12 wiz Exp $
 .\"
 .\" zip_get_name.mdoc -- get name of file by index
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,7 +31,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
+.Dd January 20, 2005
 .Dt ZIP_GET_NAME 3
 .Os
 .Sh NAME
@@ -42,7 +42,7 @@
 .Sh SYNOPSIS
 .In zip.h
 .Ft const char *
-.Fn zip_get_name "struct zip *archive" "int index"
+.Fn zip_get_name "struct zip *archive" "int index" "int flags"
 .Sh DESCRIPTION
 The
 .Fn zip_get_name
@@ -50,6 +50,11 @@
 .Ar index
 in
 .Ar archive .
+If
+.Ar flags
+is set to
+.Dv ZIP_FL_UNCHANGED ,
+the original unchanged filename is returned.
 The returned string must not be modified or freed, and becomes invalid when
 .Ar archive
 is closed.
@@ -57,16 +62,32 @@
 Upon successful completion, a pointer to the name is returned.
 Otherwise,
 .Dv NULL
-is returned and the global variable
-.Va zip_err
+and the error code in
+.Ar archive
 is set to indicate the error.
 .Sh ERRORS
 .Fn zip_get_name
 fails if:
 .Bl -tag -width Er
-.It Bq Er ZERR_INVAL
+.It Bq Er ZIP_ER_DELETED
+.Ar index
+refers to a file that has been deleted
+(see
+.Xr zip_delete 3 ) .
+.It Bq Er ZIP_ER_INVAL
 .Ar index
 is not a valid file index in
-.Ar archive .
+.Ar archive ,
+or
+.Ar index
+points to an added file and
+.Dv ZIP_FL_UNCHANGED
+is set.
 .Sh SEE ALSO
+.Xr libzip 3 ,
 .Xr zip_name_locate 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_get_num_files.man b/man/zip_get_num_files.man
index 70f4a1b..d7bc88e 100644
--- a/man/zip_get_num_files.man
+++ b/man/zip_get_num_files.man
@@ -1,7 +1,9 @@
-.\" $NiH$
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_get_num_files.mdoc,v 1.5 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_get_num_files.mdoc,v 1.5 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_get_num_files.mdoc \-- get number of files in archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -37,19 +39,26 @@
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_get_num_files "struct zip *archive"
+#include <zip.h>
+.PP
+int
+zip_get_num_files(struct zip *archive);
 .SH "DESCRIPTION"
 The
-.Fn zip_get_num_files
+zip_get_num_files
 function returns the number of files in
 \fBarchive.\fR
 .SH "RETURN VALUES"
-.Fn zip_get_num_files
+zip_get_num_files
 returns the number of files in the zip archive,
 or \-1 if
 \fBarchive\fR
 is
-.Dv NULL.
-.\".SH "SEE ALSO"
+\fBNULL.\fR
+.SH "SEE ALSO"
+libzip(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_get_num_files.mdoc b/man/zip_get_num_files.mdoc
index 372b632..d4da66f 100644
--- a/man/zip_get_num_files.mdoc
+++ b/man/zip_get_num_files.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH$
+.\" $NiH: zip_get_num_files.mdoc,v 1.4 2005/06/09 21:13:12 wiz Exp $
 .\"
 .\" zip_get_num_files.mdoc -- get number of files in archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -55,4 +55,10 @@
 .Ar archive
 is
 .Dv NULL .
-.\" .Sh SEE ALSO
+.Sh SEE ALSO
+.Xr libzip 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_name_locate.man b/man/zip_name_locate.man
index bbabc77..d46f362 100644
--- a/man/zip_name_locate.man
+++ b/man/zip_name_locate.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_name_locate.mdoc,v 1.3 2003/12/27 22:48:58 wiz Exp 
-.\" $NiH: zip_name_locate.mdoc,v 1.3 2003/12/27 22:48:58 wiz Exp $
+.\" from NiH: zip_name_locate.mdoc,v 1.9 2006/10/04 19:42:02 wiz Exp 
+.\" $NiH: zip_name_locate.mdoc,v 1.9 2006/10/04 19:42:02 wiz Exp $
 .\"
 .\" zip_name_locate.mdoc \-- get index of file by name
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,18 +33,19 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_NAME_LOCATE 3 "October 3, 2003" NiH
+.TH ZIP_NAME_LOCATE 3 "October 4, 2006" NiH
 .SH "NAME"
 zip_name_locate \- get index of file by name
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_name_locate "struct zip *archive" "const char *fname" "int flags"
+#include <zip.h>
+.PP
+int
+zip_name_locate(struct zip *archive, const char *fname, int flags);
 .SH "DESCRIPTION"
 The
-.Fn zip_name_locate
+zip_name_locate
 function returns the index of the file named
 \fBfname\fR
 in
@@ -55,16 +56,38 @@
 The
 .Fa flags
 are specified by
-.I orNo 'ing
+.I or'ing
 the following values, or 0 for none of them.
 .RS
 .TP 15
-Dv ZIP_FL_NOCASE
+\fBZIP_FL_NOCASE\fR
 Ignore case distinctions.
 .TP 15
-Dv ZIP_FL_NODIR
+\fBZIP_FL_NODIR\fR
 Ignore directory part of file name in archive.
 .RE
-.\".SH "RETURN VALUES"
+.SH "RETURN VALUES"
+zip_name_locate
+returns the index of the file named
+\fBfname\fR
+or \-1, if
+\fBarchive\fR
+does not contain an entry of that name.
+.SH "ERRORS"
+The
+zip_name_locate
+function fails and sets the error information to
+ZIP_ER_NOENT
+if no entry of the name
+\fBfname\fR
+is found in the archive.
+If one of the arguments is invalid, the error information is set to
+ZIP_ER_INVAL.
 .SH "SEE ALSO"
+libzip(3),
 zip_get_name(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_name_locate.mdoc b/man/zip_name_locate.mdoc
index 8b03b8f..b8063e0 100644
--- a/man/zip_name_locate.mdoc
+++ b/man/zip_name_locate.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_name_locate.mdoc,v 1.3 2003/12/27 22:48:58 wiz Exp $
+.\" $NiH: zip_name_locate.mdoc,v 1.8 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_name_locate.mdoc -- get index of file by name
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,7 +31,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
+.Dd October 4, 2006
 .Dt ZIP_NAME_LOCATE 3
 .Os
 .Sh NAME
@@ -64,6 +64,28 @@
 .It Dv ZIP_FL_NODIR
 Ignore directory part of file name in archive.
 .El
-.\" .Sh RETURN VALUES
+.Sh RETURN VALUES
+.Fn zip_name_locate
+returns the index of the file named
+.Ar fname
+or \-1, if
+.Ar archive
+does not contain an entry of that name.
+.Sh ERRORS
+The
+.Fn zip_name_locate
+function fails and sets the error information to
+.Er ZIP_ER_NOENT
+if no entry of the name
+.Ar fname
+is found in the archive.
+If one of the arguments is invalid, the error information is set to
+.Er ZIP_ER_INVAL .
 .Sh SEE ALSO
+.Xr libzip 3 ,
 .Xr zip_get_name 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_open.man b/man/zip_open.man
index 608606a..d357cc8 100644
--- a/man/zip_open.man
+++ b/man/zip_open.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_open.mdoc,v 1.15 2003/12/28 00:51:51 wiz Exp 
-.\" $NiH: zip_open.mdoc,v 1.15 2003/12/28 00:51:51 wiz Exp $
+.\" from NiH: zip_open.mdoc,v 1.22 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_open.mdoc,v 1.22 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_open.mdoc \-- open zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -39,15 +39,16 @@
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft struct zip *
-.Fn zip_open "const char *path" "int flags" "int *errorp"
+#include <zip.h>
+.PP
+struct zip *
+zip_open(const char *path, int flags, int *errorp);
 .SH "DESCRIPTION"
 The zip archive specified by
 \fBpath\fR
 is opened and a pointer to a
-.\" XXX: also marks up,
-.Ft struct zip,
+.PP
+struct zip,
 used to manipulate the archive, is returned.
 The
 .Fa flags
@@ -56,13 +57,13 @@
 the following values, or 0 for none of them.
 .RS
 .TP 15
-Dv ZIP_CREATE
+\fBZIP_CREATE\fR
 Create the archive if it does not exist.
 .TP 15
-Dv ZIP_EXCL
+\fBZIP_EXCL\fR
 Error if archive already exists.
 .TP 15
-Dv ZIP_CHECKCONS
+\fBZIP_CHECKCONS\fR
 Perform additional consistency checks on the archive, and error if
 they fail.
 .RE
@@ -72,12 +73,13 @@
 is non-NULL, it will be set to the corresponding error code.
 .SH "RETURN VALUES"
 Upon successful completion
-.Fn zip_open
+zip_open
 returns a
-.Ft struct zip
+.PP
+struct zip
 pointer.
 Otherwise,
-.Dv NULL
+\fBNULL\fR
 is returned and
 \fB*errorp\fR
 is set to indicate the error.
@@ -87,56 +89,62 @@
 is opened unless:
 .RS
 .TP 4
-Bq Er ZERR_EXISTS
+[ZIP_ER_EXISTS]
 The file specified by
 \fBpath\fR
 exists and
-.Dv ZIP_EXCL
+\fBZIP_EXCL\fR
 is set.
 .TP 4
-Bq Er ZERR_INCONS
+[ZIP_ER_INCONS]
 Inconsistencies were found in the file specified by
 \fBpath\fR
 and
-.Dv ZIP_CHECKCONS
+\fBZIP_CHECKCONS\fR
 was specified.
 .TP 4
-Bq Er ZERR_INVAL
+[ZIP_ER_INVAL]
 The
 \fBpath\fR
 argument is
-.Dv NULL.
+\fBNULL.\fR
 .TP 4
-Bq Er ZERR_MEMORY
+[ZIP_ER_MEMORY]
 Required memory could not be allocated.
 .TP 4
-Bq Er ZERR_NOENT
+[ZIP_ER_NOENT]
 The file specified by
 \fBpath\fR
 does not exist and
-.Dv ZIP_CREATE
+\fBZIP_CREATE\fR
 is not set.
 .TP 4
-Bq Er ZERR_NOZIP
+[ZIP_ER_NOZIP]
 The file specified by
 \fBpath\fR
 is not a zip archive.
 .TP 4
-Bq Er ZERR_OPEN
+[ZIP_ER_OPEN]
 The file specified by
 \fBpath\fR
 could not be opened.
 .TP 4
-Bq Er ZERR_READ
+[ZIP_ER_READ]
 A read error occurred; see
 .Va errno
 for details.
 .TP 4
-Bq Er ZERR_SEEK
+[ZIP_ER_SEEK]
 The file specified by
 \fBpath\fR
 does not allow seeks.
 .RE
 .SH "SEE ALSO"
+libzip(3),
 zip_close(3),
-zip_error_str(3)
+zip_error_to_str(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_open.mdoc b/man/zip_open.mdoc
index 67ce74c..cabafb2 100644
--- a/man/zip_open.mdoc
+++ b/man/zip_open.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_open.mdoc,v 1.14 2003/12/27 22:37:34 wiz Exp $
+.\" $NiH: zip_open.mdoc,v 1.21 2005/06/09 21:13:12 wiz Exp $
 .\"
 .\" zip_open.mdoc -- open zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -47,7 +47,6 @@
 The zip archive specified by
 .Ar path
 is opened and a pointer to a
-.\" XXX: also marks up ,
 .Ft struct zip ,
 used to manipulate the archive, is returned.
 The
@@ -84,48 +83,54 @@
 .Ar path
 is opened unless:
 .Bl -tag -width Er
-.It Bq Er ZERR_EXISTS
+.It Bq Er ZIP_ER_EXISTS
 The file specified by
 .Ar path
 exists and
 .Dv ZIP_EXCL
 is set.
-.It Bq Er ZERR_INCONS
+.It Bq Er ZIP_ER_INCONS
 Inconsistencies were found in the file specified by
 .Ar path
 and
 .Dv ZIP_CHECKCONS
 was specified.
-.It Bq Er ZERR_INVAL
+.It Bq Er ZIP_ER_INVAL
 The
 .Ar path
 argument is
 .Dv NULL .
-.It Bq Er ZERR_MEMORY
+.It Bq Er ZIP_ER_MEMORY
 Required memory could not be allocated.
-.It Bq Er ZERR_NOENT
+.It Bq Er ZIP_ER_NOENT
 The file specified by
 .Ar path
 does not exist and
 .Dv ZIP_CREATE
 is not set.
-.It Bq Er ZERR_NOZIP
+.It Bq Er ZIP_ER_NOZIP
 The file specified by
 .Ar path
 is not a zip archive.
-.It Bq Er ZERR_OPEN
+.It Bq Er ZIP_ER_OPEN
 The file specified by
 .Ar path
 could not be opened.
-.It Bq Er ZERR_READ
+.It Bq Er ZIP_ER_READ
 A read error occurred; see
 .Va errno
 for details.
-.It Bq Er ZERR_SEEK
+.It Bq Er ZIP_ER_SEEK
 The file specified by
 .Ar path
 does not allow seeks.
 .El
 .Sh SEE ALSO
+.Xr libzip 3 ,
 .Xr zip_close 3 ,
-.Xr zip_error_str 3
+.Xr zip_error_to_str 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_rename.man b/man/zip_rename.man
index 06cef81..0622ef0 100644
--- a/man/zip_rename.man
+++ b/man/zip_rename.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_rename.mdoc,v 1.1 2003/10/03 23:26:01 dillo Exp 
-.\" $NiH: zip_rename.mdoc,v 1.1 2003/10/03 23:26:01 dillo Exp $
+.\" from NiH: zip_rename.mdoc,v 1.8 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zip_rename.mdoc,v 1.8 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_rename.mdoc \-- rename file in zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,15 +33,16 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_RENAME 3 "October 3, 2003" NiH
+.TH ZIP_RENAME 3 "November 30, 2003" NiH
 .SH "NAME"
 zip_rename \- rename file in zip archive
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_rename "struct zip *archive" "int index" "const char *name"
+#include <zip.h>
+.PP
+int
+zip_rename(struct zip *archive, int index, const char *name);
 .SH "DESCRIPTION"
 The file at position
 \fBindex\fR
@@ -51,18 +52,29 @@
 \fBname.\fR
 .SH "RETURN VALUES"
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+\fBarchive\fR
 is set to indicate the error.
 .SH "ERRORS"
-.Fn zip_rename
+zip_rename
 fails if:
 .RS
 .TP 4
-Bq Er ZERR_INVAL
+[ZIP_ER_EXISTS]
+There is already a file called
+\fBname\fR
+in the archive.
+.TP 4
+[ZIP_ER_INVAL]
 \fBindex\fR
 is not a valid file index in
 \fBarchive.\fR
 .RE
 .SH "SEE ALSO"
+libzip(3),
 zip_unchange(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_rename.mdoc b/man/zip_rename.mdoc
index 3064354..92e5b30 100644
--- a/man/zip_rename.mdoc
+++ b/man/zip_rename.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH$
+.\" $NiH: zip_rename.mdoc,v 1.7 2005/06/09 21:13:12 wiz Exp $
 .\"
 .\" zip_rename.mdoc -- rename file in zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,7 +31,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
+.Dd November 30, 2003
 .Dt ZIP_RENAME 3
 .Os
 .Sh NAME
@@ -52,17 +52,27 @@
 .Ar name .
 .Sh RETURN VALUES
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+.Ar archive
 is set to indicate the error.
 .Sh ERRORS
 .Fn zip_rename
 fails if:
 .Bl -tag -width Er
-.It Bq Er ZERR_INVAL
+.It Bq Er ZIP_ER_EXISTS
+There is already a file called
+.Ar name
+in the archive.
+.It Bq Er ZIP_ER_INVAL
 .Ar index
 is not a valid file index in
 .Ar archive .
 .El
 .Sh SEE ALSO
+.Xr libzip 3 ,
 .Xr zip_unchange 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_set_archive_comment.man b/man/zip_set_archive_comment.man
new file mode 100644
index 0000000..55809da
--- /dev/null
+++ b/man/zip_set_archive_comment.man
@@ -0,0 +1,85 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_set_archive_comment.mdoc,v 1.2 2006/04/23 14:57:12 wiz Exp 
+.\" $NiH: zip_set_archive_comment.mdoc,v 1.2 2006/04/23 14:57:12 wiz Exp $
+.\"
+.\" zip_set_archive_comment.mdoc \-- set zip archive comment
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_SET_ARCHIVE_COMMENT 3 "April 23, 2006" NiH
+.SH "NAME"
+zip_set_archive_comment \- set zip archive comment
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.PP
+int
+zip_set_archive_comment(struct zip *archive); \
+"const char *comment" "int *lenp"
+.SH "DESCRIPTION"
+The
+zip_set_archive_comment
+function sets the comment for the entire zip archive.
+If
+\fBcomment\fR
+is
+\fBNULL\fR
+and
+\fBlen\fR
+is 0, the archive comment will be removed.
+.SH "RETURN VALUES"
+Upon successful completion 0 is returned.
+Otherwise, \-1 is returned and the error information in
+\fBarchive\fR
+is set to indicate the error.
+.SH "ERRORS"
+zip_set_archive_comment
+fails if:
+.RS
+.TP 4
+[ZIP_ER_INVAL]
+\fBlen\fR
+is less than 0 or longer than the maximum comment length in a zip file
+(65535).
+.TP 4
+[ZIP_ER_MEMORY]
+Required memory could not be allocated.
+.RE
+.SH "SEE ALSO"
+libzip(3),
+zip_get_archive_comment(3),
+zip_get_file_comment(3),
+zip_set_file_comment(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_strerror.mdoc b/man/zip_set_archive_comment.mdoc
similarity index 60%
copy from man/zip_strerror.mdoc
copy to man/zip_set_archive_comment.mdoc
index 529c361..4eef112 100644
--- a/man/zip_strerror.mdoc
+++ b/man/zip_set_archive_comment.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH: zip_set_archive_comment.mdoc,v 1.1 2006/04/23 12:47:30 wiz Exp $
 .\"
-.\" zip_strerror.mdoc -- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_set_archive_comment.mdoc -- set zip archive comment
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,30 +31,53 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd April 23, 2006
+.Dt ZIP_SET_ARCHIVE_COMMENT 3
 .Os
 .Sh NAME
-.Nm zip_strerror
-.Nd get string representation of zip error
+.Nm zip_set_archive_comment
+.Nd set zip archive comment
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+.Ft int
+.Fn zip_set_archive_comment "struct zip *archive" \
+"const char *comment" "int *lenp"
 .Sh DESCRIPTION
 The
-.Fn zip_strerror
-function returns a string describing the last error for
-.Ar archive .
-The returned string must not be modified or freed, and becomes invalid when
-.Ar archive
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
+.Fn zip_set_archive_comment
+function sets the comment for the entire zip archive.
+If
+.Ar comment
+is
+.Dv NULL
+and
+.Ar len
+is 0, the archive comment will be removed.
 .Sh RETURN VALUES
-.Fn zip_strerror
-returns a pointer to the error string.
+Upon successful completion 0 is returned.
+Otherwise, \-1 is returned and the error information in
+.Ar archive
+is set to indicate the error.
+.Sh ERRORS
+.Fn zip_set_archive_comment
+fails if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_INVAL
+.Ar len
+is less than 0 or longer than the maximum comment length in a zip file
+(65535).
+.It Bq Er ZIP_ER_MEMORY
+Required memory could not be allocated.
+.El
 .Sh SEE ALSO
-.Xr zip_error_str 3
+.Xr libzip 3 ,
+.Xr zip_get_archive_comment 3 ,
+.Xr zip_get_file_comment 3 ,
+.Xr zip_set_file_comment 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_set_file_comment.man b/man/zip_set_file_comment.man
new file mode 100644
index 0000000..e12a06a
--- /dev/null
+++ b/man/zip_set_file_comment.man
@@ -0,0 +1,94 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_set_file_comment.mdoc,v 1.2 2006/04/23 14:57:12 wiz Exp 
+.\" $NiH: zip_set_file_comment.mdoc,v 1.2 2006/04/23 14:57:12 wiz Exp $
+.\"
+.\" zip_set_file_comment.mdoc \-- set comment for file in zip
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP files.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_SET_FILE_COMMENT 3 "April 23, 2006" NiH
+.SH "NAME"
+zip_set_file_comment \- set comment for file in zip
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.PP
+int
+zip_set_file_comment(struct zip *archive, int index); \
+"const char *comment" "int len"
+.SH "DESCRIPTION"
+The
+zip_set_file_comment
+function sets the comment for the file at position
+\fBindex\fR
+in the zip archive to
+\fBcomment\fR
+of length
+\fBlen.\fR
+If
+\fBcomment\fR
+is
+\fBNULL\fR
+and
+\fBlen\fR
+is 0, the file comment will be removed.
+.SH "RETURN VALUES"
+Upon successful completion 0 is returned.
+Otherwise, \-1 is returned and the error information in
+\fBarchive\fR
+is set to indicate the error.
+.SH "ERRORS"
+zip_set_file_comment
+fails if:
+.RS
+.TP 4
+[ZIP_ER_INVAL]
+\fBindex\fR
+is not a valid file index in
+\fBarchive,\fR
+or
+\fBlen\fR
+is less than 0 or longer than the maximum comment length in a zip file
+(65535).
+.TP 4
+[ZIP_ER_MEMORY]
+Required memory could not be allocated.
+.RE
+.SH "SEE ALSO"
+libzip(3),
+zip_get_archive_comment(3),
+zip_get_file_comment(3),
+zip_set_archive_comment(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_set_file_comment.mdoc b/man/zip_set_file_comment.mdoc
new file mode 100644
index 0000000..0205f6b
--- /dev/null
+++ b/man/zip_set_file_comment.mdoc
@@ -0,0 +1,92 @@
+.\" $NiH: zip_set_file_comment.mdoc,v 1.1 2006/04/23 12:47:30 wiz Exp $
+.\"
+.\" zip_set_file_comment.mdoc -- set comment for file in zip
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP files.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd April 23, 2006
+.Dt ZIP_SET_FILE_COMMENT 3
+.Os
+.Sh NAME
+.Nm zip_set_file_comment
+.Nd set comment for file in zip
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.In zip.h
+.Ft int
+.Fn zip_set_file_comment "struct zip *archive" "int index" \
+"const char *comment" "int len"
+.Sh DESCRIPTION
+The
+.Fn zip_set_file_comment
+function sets the comment for the file at position
+.Ar index
+in the zip archive to
+.Ar comment
+of length
+.Ar len .
+If
+.Ar comment
+is
+.Dv NULL
+and
+.Ar len
+is 0, the file comment will be removed.
+.Sh RETURN VALUES
+Upon successful completion 0 is returned.
+Otherwise, \-1 is returned and the error information in
+.Ar archive
+is set to indicate the error.
+.Sh ERRORS
+.Fn zip_set_file_comment
+fails if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_INVAL
+.Ar index
+is not a valid file index in
+.Ar archive ,
+or
+.Ar len
+is less than 0 or longer than the maximum comment length in a zip file
+(65535).
+.It Bq Er ZIP_ER_MEMORY
+Required memory could not be allocated.
+.El
+.Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_get_archive_comment 3 ,
+.Xr zip_get_file_comment 3 ,
+.Xr zip_set_archive_comment 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_source_buffer.man b/man/zip_source_buffer.man
new file mode 100644
index 0000000..8cf8360
--- /dev/null
+++ b/man/zip_source_buffer.man
@@ -0,0 +1,94 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_source_buffer.mdoc,v 1.6 2005/07/20 17:18:04 wiz Exp 
+.\" $NiH: zip_source_buffer.mdoc,v 1.6 2005/07/20 17:18:04 wiz Exp $
+.\"
+.\" zip_source_buffer.mdoc \-- create zip data source from buffer
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_SOURCE_DATA 3 "July 20, 2005" NiH
+.SH "NAME"
+zip_source_buffer \- create zip data source from buffer
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.PP
+struct zip_source *
+zip_source_buffer(struct zip *archive, const void *data, off_t len); \
+"int freep"
+.SH "DESCRIPTION"
+The function
+zip_source_buffer
+creates a zip source from the buffer
+\fBdata\fR
+of size
+\fBlen.\fR
+If
+\fBfreep\fR
+is non-zero, the buffer will be freed when the it is no longer needed.
+.SH "RETURN VALUES"
+Upon successful completion, the created source is returned.
+Otherwise,
+\fBNULL\fR
+is returned and the error code in
+\fBarchive\fR
+is set to indicate the error.
+.SH "ERRORS"
+zip_source_buffer
+fails if:
+.RS
+.TP 4
+[ZIP_ER_INVAL]
+\fBlen\fR
+is negative, or
+\fBlen\fR
+is greater than zero and
+\fBdata\fR
+is
+\fBNULL.\fR
+.TP 4
+[ZIP_ER_MEMORY]
+Required memory could not be allocated.
+.RE
+.SH "SEE ALSO"
+libzip(3),
+zip_add(3),
+zip_replace(3),
+zip_source_file(3),
+zip_source_filep(3),
+zip_source_free(3),
+zip_source_function(3),
+zip_source_zip(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_source_buffer.mdoc b/man/zip_source_buffer.mdoc
new file mode 100644
index 0000000..6f11dd6
--- /dev/null
+++ b/man/zip_source_buffer.mdoc
@@ -0,0 +1,92 @@
+.\" $NiH: zip_source_buffer.mdoc,v 1.5 2005/06/09 21:14:54 wiz Exp $
+.\"
+.\" zip_source_buffer.mdoc -- create zip data source from buffer
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd July 20, 2005
+.Dt ZIP_SOURCE_DATA 3
+.Os
+.Sh NAME
+.Nm zip_source_buffer
+.Nd create zip data source from buffer
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.In zip.h
+.Ft struct zip_source *
+.Fn zip_source_buffer "struct zip *archive" "const void *data" "off_t len" \
+"int freep"
+.Sh DESCRIPTION
+The function
+.Fn zip_source_buffer
+creates a zip source from the buffer
+.Ar data
+of size
+.Ar len .
+If
+.Ar freep
+is non-zero, the buffer will be freed when the it is no longer needed.
+.Sh RETURN VALUES
+Upon successful completion, the created source is returned.
+Otherwise,
+.Dv NULL
+is returned and the error code in
+.Ar archive
+is set to indicate the error.
+.Sh ERRORS
+.Fn zip_source_buffer
+fails if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_INVAL
+.Ar len
+is negative, or
+.Ar len
+is greater than zero and
+.Ar data
+is
+.Dv NULL .
+.It Bq Er ZIP_ER_MEMORY
+Required memory could not be allocated.
+.El
+.Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_add 3 ,
+.Xr zip_replace 3 ,
+.Xr zip_source_file 3 ,
+.Xr zip_source_filep 3 ,
+.Xr zip_source_free 3 ,
+.Xr zip_source_function 3 ,
+.Xr zip_source_zip 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_source_file.man b/man/zip_source_file.man
new file mode 100644
index 0000000..745faf6
--- /dev/null
+++ b/man/zip_source_file.man
@@ -0,0 +1,102 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_source_file.mdoc,v 1.9 2005/07/20 17:18:04 wiz Exp 
+.\" $NiH: zip_source_file.mdoc,v 1.9 2005/07/20 17:18:04 wiz Exp $
+.\"
+.\" zip_source_file.mdoc \-- create data source from a file
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_SOURCE_FILE 3 "July 20, 2005" NiH
+.SH "NAME"
+zip_source_file \- create data source from a file
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+.PP
+struct zip_source *
+zip_source_file(struct zip *archive, const char *fname, off_t start, off_t len);
+.SH "DESCRIPTION"
+The function
+zip_source_file
+creates a zip source from a file.
+zip_source_file
+opens
+\fBfname\fR
+and reads
+\fBlen\fR
+bytes from offset
+\fBstart\fR
+from it.
+If
+\fBlen\fR
+is 0 or \-1, the whole file (starting from
+\fBstart )\fR
+is used.
+.SH "RETURN VALUES"
+Upon successful completion, the created source is returned.
+Otherwise,
+\fBNULL\fR
+is returned and the error code in
+\fBarchive\fR
+is set to indicate the error.
+.SH "ERRORS"
+zip_source_file
+fails if:
+.RS
+.TP 4
+[ZIP_ER_INVAL]
+\fBfname,\fR
+\fBstart,\fR
+or
+\fBlen\fR
+are invalid.
+.TP 4
+[ZIP_ER_MEMORY]
+Required memory could not be allocated.
+.TP 4
+[ZIP_ER_OPEN]
+Opening
+\fBfname\fR
+failed.
+.RE
+.SH "SEE ALSO"
+libzip(3),
+zip_add(3),
+zip_replace(3),
+zip_source_buffer(3),
+zip_source_filep(3),
+zip_source_free(3),
+zip_source_function(3),
+zip_source_zip(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_source_file.mdoc b/man/zip_source_file.mdoc
new file mode 100644
index 0000000..fd78d88
--- /dev/null
+++ b/man/zip_source_file.mdoc
@@ -0,0 +1,99 @@
+.\" $NiH: zip_source_file.mdoc,v 1.8 2005/07/15 14:11:16 wiz Exp $
+.\"
+.\" zip_source_file.mdoc -- create data source from a file
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd July 20, 2005
+.Dt ZIP_SOURCE_FILE 3
+.Os
+.Sh NAME
+.Nm zip_source_file
+.Nd create data source from a file
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.Ft struct zip_source *
+.Fn zip_source_file "struct zip *archive" "const char *fname" "off_t start" "off_t len"
+.Sh DESCRIPTION
+The function
+.Fn zip_source_file
+creates a zip source from a file.
+.Fn zip_source_file
+opens
+.Ar fname
+and reads
+.Ar len
+bytes from offset
+.Ar start
+from it.
+If
+.Ar len
+is 0 or \-1, the whole file (starting from
+.Ar start )
+is used.
+.Sh RETURN VALUES
+Upon successful completion, the created source is returned.
+Otherwise,
+.Dv NULL
+is returned and the error code in
+.Ar archive
+is set to indicate the error.
+.Sh ERRORS
+.Fn zip_source_file
+fails if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_INVAL
+.Ar fname ,
+.Ar start ,
+or
+.Ar len
+are invalid.
+.It Bq Er ZIP_ER_MEMORY
+Required memory could not be allocated.
+.It Bq Er ZIP_ER_OPEN
+Opening
+.Ar fname
+failed.
+.El
+.Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_add 3 ,
+.Xr zip_replace 3 ,
+.Xr zip_source_buffer 3 ,
+.Xr zip_source_filep 3 ,
+.Xr zip_source_free 3 ,
+.Xr zip_source_function 3 ,
+.Xr zip_source_zip 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_source_filep.man b/man/zip_source_filep.man
new file mode 100644
index 0000000..a3ec7b2
--- /dev/null
+++ b/man/zip_source_filep.man
@@ -0,0 +1,96 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_source_filep.mdoc,v 1.7 2005/07/20 17:18:04 wiz Exp 
+.\" $NiH: zip_source_filep.mdoc,v 1.7 2005/07/20 17:18:04 wiz Exp $
+.\"
+.\" zip_source_filep.mdoc \-- create data source from a file stream
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_SOURCE_FILEP 3 "July 20, 2005" NiH
+.SH "NAME"
+zip_source_filep \- create data source from FILE *
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+.PP
+struct zip_source *
+zip_source_filep(struct zip *archive, FILE *file, off_t start, off_t len);
+.SH "DESCRIPTION"
+The function
+zip_source_filep
+creates a zip source from a file stream.
+zip_source_filep
+reads
+\fBlen\fR
+bytes from offset
+\fBstart\fR
+from the open file stream
+\fBfile.\fR
+If
+\fBlen\fR
+is 0 or \-1, the whole file (starting from
+\fBstart )\fR
+is used.
+.SH "RETURN VALUES"
+Upon successful completion, the created source is returned.
+Otherwise,
+\fBNULL\fR
+is returned and the error code in
+\fBarchive\fR
+is set to indicate the error.
+.SH "ERRORS"
+zip_source_filep
+fails if:
+.RS
+.TP 4
+[ZIP_ER_INVAL]
+\fBfile,\fR
+\fBstart,\fR
+or
+\fBlen\fR
+are invalid.
+.TP 4
+[ZIP_ER_MEMORY]
+Required memory could not be allocated.
+.RE
+.SH "SEE ALSO"
+libzip(3),
+zip_add(3),
+zip_replace(3),
+zip_source_buffer(3),
+zip_source_file(3),
+zip_source_free(3),
+zip_source_function(3),
+zip_source_zip(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_source_filep.mdoc b/man/zip_source_filep.mdoc
new file mode 100644
index 0000000..59fd25e
--- /dev/null
+++ b/man/zip_source_filep.mdoc
@@ -0,0 +1,94 @@
+.\" $NiH: zip_source_filep.mdoc,v 1.6 2005/06/09 21:14:54 wiz Exp $
+.\"
+.\" zip_source_filep.mdoc -- create data source from a file stream
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd July 20, 2005
+.Dt ZIP_SOURCE_FILEP 3
+.Os
+.Sh NAME
+.Nm zip_source_filep
+.Nd create data source from FILE *
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.Ft struct zip_source *
+.Fn zip_source_filep "struct zip *archive" "FILE *file" "off_t start" "off_t len"
+.Sh DESCRIPTION
+The function
+.Fn zip_source_filep
+creates a zip source from a file stream.
+.Fn zip_source_filep
+reads
+.Ar len
+bytes from offset
+.Ar start
+from the open file stream
+.Ar file .
+If
+.Ar len
+is 0 or \-1, the whole file (starting from
+.Ar start )
+is used.
+.Sh RETURN VALUES
+Upon successful completion, the created source is returned.
+Otherwise,
+.Dv NULL
+is returned and the error code in
+.Ar archive
+is set to indicate the error.
+.Sh ERRORS
+.Fn zip_source_filep
+fails if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_INVAL
+.Ar file ,
+.Ar start ,
+or
+.Ar len
+are invalid.
+.It Bq Er ZIP_ER_MEMORY
+Required memory could not be allocated.
+.El
+.Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_add 3 ,
+.Xr zip_replace 3 ,
+.Xr zip_source_buffer 3 ,
+.Xr zip_source_file 3 ,
+.Xr zip_source_free 3 ,
+.Xr zip_source_function 3 ,
+.Xr zip_source_zip 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_strerror.man b/man/zip_source_free.man
similarity index 66%
copy from man/zip_strerror.man
copy to man/zip_source_free.man
index 3b82061..ed13b65 100644
--- a/man/zip_strerror.man
+++ b/man/zip_source_free.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp 
-.\" $NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp $
+.\" from NiH: zip_source_free.mdoc,v 1.7 2006/04/23 14:55:32 wiz Exp 
+.\" $NiH: zip_source_free.mdoc,v 1.7 2006/04/23 14:55:32 wiz Exp $
 .\"
-.\" zip_strerror.mdoc \-- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_source_free.mdoc \-- free zip data source
+.\" Copyright (C) 2004, 2005, 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,27 +33,44 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_STRERROR 3 "October 3, 2003" NiH
+.TH ZIP_SOURCE_FREE 3 "April 23, 2006" NiH
 .SH "NAME"
-zip_strerror \- get string representation of zip error
+zip_source_free \- free zip data source
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+#include <zip.h>
+.PP
+void
+zip_source_free(struct zip_source *source);
 .SH "DESCRIPTION"
-The
-.Fn zip_strerror
-function returns a string describing the last error for
-\fBarchive.\fR
-The returned string must not be modified or freed, and becomes invalid when
-\fBarchive\fR
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
-.SH "RETURN VALUES"
-.Fn zip_strerror
-returns a pointer to the error string.
+The function
+zip_source_free
+frees the zip data source
+\fBsource.\fR
+If
+\fBsource\fR
+is
+\fBNULL,\fR
+it does nothing.
+.PP
+.I NOTE :
+This function should not be called on a
+\fBsource\fR
+after it was used successfully in a
+zip_add(3)
+or
+zip_replace(3)
+call.
 .SH "SEE ALSO"
-zip_error_str(3)
+libzip(3),
+zip_source_buffer(3),
+zip_source_file(3),
+zip_source_filep(3),
+zip_source_function(3),
+zip_source_zip(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_strerror.mdoc b/man/zip_source_free.mdoc
similarity index 66%
copy from man/zip_strerror.mdoc
copy to man/zip_source_free.mdoc
index 529c361..acaaa1d 100644
--- a/man/zip_strerror.mdoc
+++ b/man/zip_source_free.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH: zip_source_free.mdoc,v 1.6 2005/06/09 21:14:54 wiz Exp $
 .\"
-.\" zip_strerror.mdoc -- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_source_free.mdoc -- free zip data source
+.\" Copyright (C) 2004, 2005, 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,30 +31,46 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd April 23, 2006
+.Dt ZIP_SOURCE_FREE 3
 .Os
 .Sh NAME
-.Nm zip_strerror
-.Nd get string representation of zip error
+.Nm zip_source_free
+.Nd free zip data source
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+.Ft void
+.Fn zip_source_free "struct zip_source *source"
 .Sh DESCRIPTION
-The
-.Fn zip_strerror
-function returns a string describing the last error for
-.Ar archive .
-The returned string must not be modified or freed, and becomes invalid when
-.Ar archive
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
-.Sh RETURN VALUES
-.Fn zip_strerror
-returns a pointer to the error string.
+The function
+.Fn zip_source_free
+frees the zip data source
+.Ar source .
+If
+.Ar source
+is
+.Dv NULL ,
+it does nothing.
+.Pp
+.Em NOTE :
+This function should not be called on a
+.Ar source
+after it was used successfully in a
+.Xr zip_add 3
+or
+.Xr zip_replace 3
+call.
 .Sh SEE ALSO
-.Xr zip_error_str 3
+.Xr libzip 3 ,
+.Xr zip_source_buffer 3 ,
+.Xr zip_source_file 3 ,
+.Xr zip_source_filep 3 ,
+.Xr zip_source_function 3 ,
+.Xr zip_source_zip 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_source_function.man b/man/zip_source_function.man
new file mode 100644
index 0000000..b14695c
--- /dev/null
+++ b/man/zip_source_function.man
@@ -0,0 +1,164 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_source_function.mdoc,v 1.18 2007/03/04 11:13:05 wiz Exp 
+.\" $NiH: zip_source_function.mdoc,v 1.18 2007/03/04 11:13:05 wiz Exp $
+.\"
+.\" zip_source_function.mdoc \-- create data source from function
+.\" Copyright (C) 2004-2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_SOURCE_FUNCTION 3 "March 4, 2007" NiH
+.SH "NAME"
+zip_source_function \- create data source from function
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.PP
+struct zip_source *
+zip_source_function(struct zip *archive, zip_source_callback fn, void *userdata);
+.SH "DESCRIPTION"
+The function
+zip_source_function
+creates a zip source from the user-provided function
+\fBfn,\fR
+which must be of the following type:
+.Bd \-literal
+typedef ssize_t (*zip_source_callback)(void *state,
+    void *data, size_t len, enum zip_source_cmd cmd);
+.Ed
+.PP
+When called by the library, the first argument is the
+\fBuserdata\fR
+argument supplied to
+zip_source_function.
+The next two arguments are a buffer
+\fBdata\fR
+of size
+\fBlen\fR
+when data is expected to be returned, or else
+\fBNULL\fR
+and 0.
+The last argument,
+\fBcmd,\fR
+specifies which action the function should perform:
+.RS
+.TP 21
+\fBZIP_SOURCE_OPEN\fR
+Prepare for reading.
+Return 0 on success, \-1 on error.
+.TP 21
+\fBZIP_SOURCE_READ\fR
+Read data into the buffer
+\fBdata\fR
+of size
+\fBlen.\fR
+Return the number of bytes placed into
+\fBdata\fR
+on success, \-1 on error.
+.TP 21
+\fBZIP_SOURCE_CLOSE\fR
+Reading is done.
+.TP 21
+\fBZIP_SOURCE_STAT\fR
+Get meta information for the input data.
+\fBdata\fR
+points to a struct zip_stat, which should be filled in.
+(See
+zip_stat_init(3). )
+Usually, for uncompressed data, after
+zip_stat_init(3),
+only the mtime and size struct members will need to be set.
+Return sizeof(struct zip_stat) on success, \-1 on error.
+.TP 21
+\fBZIP_SOURCE_ERROR\fR
+Get error information.
+\fBdata\fR
+points to an array of two ints, which should be filled with the libzip
+error code and the corresponding system error code for the error that
+occurred.
+See
+zip_errors(3)
+for details on the error codes.
+Return return(2 * sizeof(int)).
+.TP 21
+\fBZIP_SOURCE_FREE\fR
+Clean up and free all resources.
+Return 0.
+.RE
+.PP
+The library will always issue
+\fBZIP_SOURCE_OPEN\fR
+before issuing
+\fBZIP_SOURCE_READ.\fR
+When it no longer wishes to read from this source, it will issue
+\fBZIP_SOURCE_CLOSE.\fR
+If the library wishes to read the data again, it will issue
+\fBZIP_SOURCE_OPEN\fR
+a second time.
+If the function is unable to provide the data again, it should
+return \-1.
+.PP
+\fBZIP_SOURCE_STAT\fR
+can be issued at any time.
+\fBZIP_SOURCE_ERROR\fR
+will only be issued in response to the function
+returning \-1.
+\fBZIP_SOURCE_FREE\fR
+will be the last command issued.
+.SH "RETURN VALUES"
+Upon successful completion, the created source is returned.
+Otherwise,
+\fBNULL\fR
+is returned and the error code in
+\fBarchive\fR
+is set to indicate the error.
+.SH "ERRORS"
+zip_source_function
+fails if:
+.RS
+.TP 4
+[ZIP_ER_MEMORY]
+Required memory could not be allocated.
+.RE
+.SH "SEE ALSO"
+libzip(3),
+zip_add(3),
+zip_replace(3),
+zip_source_buffer(3),
+zip_source_file(3),
+zip_source_filep(3),
+zip_source_free(3),
+zip_source_zip(3),
+zip_stat_init(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_source_function.mdoc b/man/zip_source_function.mdoc
new file mode 100644
index 0000000..aa365bb
--- /dev/null
+++ b/man/zip_source_function.mdoc
@@ -0,0 +1,157 @@
+.\" $NiH: zip_source_function.mdoc,v 1.17 2006/12/16 10:12:58 wiz Exp $
+.\"
+.\" zip_source_function.mdoc -- create data source from function
+.\" Copyright (C) 2004-2006 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd March 4, 2007
+.Dt ZIP_SOURCE_FUNCTION 3
+.Os
+.Sh NAME
+.Nm zip_source_function
+.Nd create data source from function
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.In zip.h
+.Ft struct zip_source *
+.Fn zip_source_function "struct zip *archive" "zip_source_callback fn" "void *userdata"
+.Sh DESCRIPTION
+The function
+.Fn zip_source_function
+creates a zip source from the user-provided function
+.Ar fn ,
+which must be of the following type:
+.Bd -literal
+typedef ssize_t (*zip_source_callback)(void *state,
+    void *data, size_t len, enum zip_source_cmd cmd);
+.Ed
+.Pp
+When called by the library, the first argument is the
+.Ar userdata
+argument supplied to
+.Fn zip_source_function .
+The next two arguments are a buffer
+.Ar data
+of size
+.Ar len
+when data is expected to be returned, or else
+.Dv NULL
+and 0.
+The last argument,
+.Ar cmd ,
+specifies which action the function should perform:
+.Bl -tag -width XZIPXSOURCEXCLOSEXX -offset indent
+.It Dv ZIP_SOURCE_OPEN
+Prepare for reading.
+Return 0 on success, \-1 on error.
+.It Dv ZIP_SOURCE_READ
+Read data into the buffer
+.Ar data
+of size
+.Ar len .
+Return the number of bytes placed into
+.Ar data
+on success, \-1 on error.
+.It Dv ZIP_SOURCE_CLOSE
+Reading is done.
+.It Dv ZIP_SOURCE_STAT
+Get meta information for the input data.
+.Ar data
+points to a struct zip_stat, which should be filled in.
+(See
+.Xr zip_stat_init 3 . )
+Usually, for uncompressed data, after
+.Xr zip_stat_init 3 ,
+only the mtime and size struct members will need to be set.
+Return sizeof(struct zip_stat) on success, \-1 on error.
+.It Dv ZIP_SOURCE_ERROR
+Get error information.
+.Ar data
+points to an array of two ints, which should be filled with the libzip
+error code and the corresponding system error code for the error that
+occurred.
+See
+.Xr zip_errors 3
+for details on the error codes.
+Return return(2 * sizeof(int)).
+.It Dv ZIP_SOURCE_FREE
+Clean up and free all resources.
+Return 0.
+.El
+.Pp
+The library will always issue
+.Dv ZIP_SOURCE_OPEN
+before issuing
+.Dv ZIP_SOURCE_READ .
+When it no longer wishes to read from this source, it will issue
+.Dv ZIP_SOURCE_CLOSE .
+If the library wishes to read the data again, it will issue
+.Dv ZIP_SOURCE_OPEN
+a second time.
+If the function is unable to provide the data again, it should
+return \-1.
+.Pp
+.Dv ZIP_SOURCE_STAT
+can be issued at any time.
+.Dv ZIP_SOURCE_ERROR
+will only be issued in response to the function
+returning \-1.
+.Dv ZIP_SOURCE_FREE
+will be the last command issued.
+.Sh RETURN VALUES
+Upon successful completion, the created source is returned.
+Otherwise,
+.Dv NULL
+is returned and the error code in
+.Ar archive
+is set to indicate the error.
+.Sh ERRORS
+.Fn zip_source_function
+fails if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_MEMORY
+Required memory could not be allocated.
+.El
+.Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_add 3 ,
+.Xr zip_replace 3 ,
+.Xr zip_source_buffer 3 ,
+.Xr zip_source_file 3 ,
+.Xr zip_source_filep 3 ,
+.Xr zip_source_free 3 ,
+.Xr zip_source_zip 3 ,
+.Xr zip_stat_init 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_source_zip.man b/man/zip_source_zip.man
new file mode 100644
index 0000000..12f83e6
--- /dev/null
+++ b/man/zip_source_zip.man
@@ -0,0 +1,122 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zip_source_zip.mdoc,v 1.8 2005/07/29 14:13:25 dillo Exp 
+.\" $NiH: zip_source_zip.mdoc,v 1.8 2005/07/29 14:13:25 dillo Exp $
+.\"
+.\" zip_source_zip.mdoc \-- create data source from zip file
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIP_SOURCE_ZIP 3 "July 29, 2005" NiH
+.SH "NAME"
+zip_source_zip \- create data source from zip file
+.SH "LIBRARY"
+libzip (-lzip)
+.SH "SYNOPSIS"
+#include <zip.h>
+.PP
+struct zip_source *
+zip_source_zip(struct zip *archive, struct zip *srcarchive); \
+"int srcidx" "int flags" "off_t start" "off_t len"
+.SH "DESCRIPTION"
+The function
+zip_source_zip
+creates a zip source from a file in a zip archive.
+The
+\fBsrcarchive\fR
+argument is the (open) zip archive containing the source zip file
+at index
+\fBsrcidx.\fR
+\fBlen\fR
+bytes from offset
+\fBstart\fR
+will be used in the zip_source.
+If
+\fBlen\fR
+is 0 or \-1, the rest of the file, starting from
+\fBstart,\fR
+is used.
+If
+\fBstart\fR
+is zero and
+\fBlen\fR
+is \-1, the whole file will be copied without decompressing it.
+If
+\fBflags\fR
+is
+\fBZIP_FL_UNCHANGED,\fR
+zip_source_zip
+will try to get the original data without any changes that may
+have been made to
+\fBsrcarchive\fR
+after opening it.
+.SH "RETURN VALUES"
+Upon successful completion, the created source is returned.
+Otherwise,
+\fBNULL\fR
+is returned and the error code in
+\fBarchive\fR
+is set to indicate the error.
+.SH "ERRORS"
+zip_source_zip
+fails if:
+.RS
+.TP 4
+[ZIP_ER_CHANGED]
+Unchanged data was requested, but it is not available.
+.TP 4
+[ZIP_ER_INVAL]
+\fBsrcarchive,\fR
+\fBsrcidx,\fR
+\fBstart,\fR
+or
+\fBlen\fR
+are invalid.
+.TP 4
+[ZIP_ER_MEMORY]
+Required memory could not be allocated.
+.RE
+Additionally, it can return all error codes from
+zip_stat_index
+and
+zip_fopen_index.
+.SH "SEE ALSO"
+libzip(3),
+zip_add(3),
+zip_replace(3),
+zip_source_buffer(3),
+zip_source_file(3),
+zip_source_filep(3),
+zip_source_free(3),
+zip_source_function(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_source_zip.mdoc b/man/zip_source_zip.mdoc
new file mode 100644
index 0000000..5432caa
--- /dev/null
+++ b/man/zip_source_zip.mdoc
@@ -0,0 +1,119 @@
+.\" $NiH: zip_source_zip.mdoc,v 1.7 2005/07/20 17:18:04 wiz Exp $
+.\"
+.\" zip_source_zip.mdoc -- create data source from zip file
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd July 29, 2005
+.Dt ZIP_SOURCE_ZIP 3
+.Os
+.Sh NAME
+.Nm zip_source_zip
+.Nd create data source from zip file
+.Sh LIBRARY
+libzip (-lzip)
+.Sh SYNOPSIS
+.In zip.h
+.Ft struct zip_source *
+.Fn zip_source_zip "struct zip *archive" "struct zip *srcarchive" \
+"int srcidx" "int flags" "off_t start" "off_t len"
+.Sh DESCRIPTION
+The function
+.Fn zip_source_zip
+creates a zip source from a file in a zip archive.
+The
+.Ar srcarchive
+argument is the (open) zip archive containing the source zip file
+at index
+.Ar srcidx .
+.Ar len
+bytes from offset
+.Ar start
+will be used in the zip_source.
+If
+.Ar len
+is 0 or \-1, the rest of the file, starting from
+.Ar start ,
+is used.
+If
+.Ar start
+is zero and
+.Ar len
+is \-1, the whole file will be copied without decompressing it.
+If
+.Ar flags
+is
+.Dv ZIP_FL_UNCHANGED ,
+.Fn zip_source_zip
+will try to get the original data without any changes that may
+have been made to
+.Ar srcarchive
+after opening it.
+.Sh RETURN VALUES
+Upon successful completion, the created source is returned.
+Otherwise,
+.Dv NULL
+is returned and the error code in
+.Ar archive
+is set to indicate the error.
+.Sh ERRORS
+.Fn zip_source_zip
+fails if:
+.Bl -tag -width Er
+.It Bq Er ZIP_ER_CHANGED
+Unchanged data was requested, but it is not available.
+.It Bq Er ZIP_ER_INVAL
+.Ar srcarchive ,
+.Ar srcidx ,
+.Ar start ,
+or
+.Ar len
+are invalid.
+.It Bq Er ZIP_ER_MEMORY
+Required memory could not be allocated.
+.El
+Additionally, it can return all error codes from
+.Fn zip_stat_index
+and
+.Fn zip_fopen_index .
+.Sh SEE ALSO
+.Xr libzip 3 ,
+.Xr zip_add 3 ,
+.Xr zip_replace 3 ,
+.Xr zip_source_buffer 3 ,
+.Xr zip_source_file 3 ,
+.Xr zip_source_filep 3 ,
+.Xr zip_source_free 3 ,
+.Xr zip_source_function 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_stat.man b/man/zip_stat.man
index 5353c85..23c2942 100644
--- a/man/zip_stat.man
+++ b/man/zip_stat.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_stat.mdoc,v 1.1 2003/10/06 02:50:11 dillo Exp 
-.\" $NiH: zip_stat.mdoc,v 1.1 2003/10/06 02:50:11 dillo Exp $
+.\" from NiH: zip_stat.mdoc,v 1.13 2006/12/29 20:36:20 wiz Exp 
+.\" $NiH: zip_stat.mdoc,v 1.13 2006/12/29 20:36:20 wiz Exp $
 .\"
 .\" zip_stat.mdoc \-- get information about file
-.\" Copyright (C) 2003, 2004 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2004, 2005, 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,21 +33,23 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_STAT 3 "April 14, 2004" NiH
+.TH ZIP_STAT 3 "December 16, 2006" NiH
 .SH "NAME"
 zip_stat , \- .Nm zip_stat_index
 get information about file
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_stat "struct zip *archive" "const char *fname" "int flags" "struct zip_stat *sb"
-.Ft int
-.Fn zip_stat_index "struct zip *archive" "int index" "int flags" "struct zip_stat *sb"
+#include <zip.h>
+.PP
+int
+zip_stat(struct zip *archive, const char *fname, int flags, struct zip_stat *sb);
+.PP
+int
+zip_stat_index(struct zip *archive, int index, int flags, struct zip_stat *sb);
 .SH "DESCRIPTION"
 The
-.Fn zip_stat
+zip_stat
 function obtains information about the file named
 \fBfname\fR
 in
@@ -58,21 +60,22 @@
 Its values are described in
 zip_name_locate(3).
 Also,
-.Dv ZIP_FL_UNCHANGED
+\fBZIP_FL_UNCHANGED\fR
 may be
-.I orNo 'ed
+.I or'ed
 to it to request information about the original file in the archive,
 ignoring any changes made.
 .PP
 The
-.Fn zip_stat_index
+zip_stat_index
 function obtains information about the file at position
 \fBindex.\fR
 .PP
 The
 \fBsb\fR
 argument is a pointer to a
-.Ft struct zip_stat
+.PP
+struct zip_stat
 (shown below), into which information about the file is placed.
 .Bd \-literal
 struct zip_stat {
@@ -83,7 +86,9 @@
     time_t mtime;			/* modification time */
     unsigned int comp_size;		/* size of file (compressed) */
     unsigned short comp_method;		/* compression method used */
+    unsigned short encryption_method;	/* encryption method used */
 };
+.Ed
 .SH "RETURN VALUES"
 Upon successful completion 0 is returned.
 Otherwise, \-1 is returned and the error information in
@@ -91,17 +96,28 @@
 is set to indicate the error.
 .SH "ERRORS"
 The function
-.Fn zip_stat
+zip_stat
 can fail for any of the errors specified for the routine
 zip_name_locate(3).
 .PP
 The function
-.Fn zip_stata_index
+zip_stat_index
 fails and sets the error information to
-.Er ZERR_INVAL
+ZIP_ER_INVAL
 if
 \fBindex\fR
 is invalid.
-.\" XXX: ZERR_CHANGED
+If
+\fBZIP_FL_UNCHANGED\fR
+is not set and no information can be obtained from the source
+callback, the error information is set to
+ZIP_ER_CHANGED.
 .SH "SEE ALSO"
-zip_name_locate(3)
+libzip(3),
+zip_name_locate(3),
+zip_stat_init(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_stat.mdoc b/man/zip_stat.mdoc
index 4bfa5af..a2a5a9a 100644
--- a/man/zip_stat.mdoc
+++ b/man/zip_stat.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_stat.mdoc,v 1.1 2003/10/06 02:50:11 dillo Exp $
+.\" $NiH: zip_stat.mdoc,v 1.12 2006/12/16 10:12:58 wiz Exp $
 .\"
 .\" zip_stat.mdoc -- get information about file
-.\" Copyright (C) 2003, 2004 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2004, 2005, 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,7 +31,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 14, 2004
+.Dd December 16, 2006
 .Dt ZIP_STAT 3
 .Os
 .Sh NAME
@@ -84,7 +84,9 @@
     time_t mtime;			/* modification time */
     unsigned int comp_size;		/* size of file (compressed) */
     unsigned short comp_method;		/* compression method used */
+    unsigned short encryption_method;	/* encryption method used */
 };
+.Ed
 .Sh RETURN VALUES
 Upon successful completion 0 is returned.
 Otherwise, \-1 is returned and the error information in
@@ -97,12 +99,23 @@
 .Xr zip_name_locate 3 .
 .Pp
 The function
-.Fn zip_stata_index
+.Fn zip_stat_index
 fails and sets the error information to
-.Er ZERR_INVAL
+.Er ZIP_ER_INVAL
 if
 .Ar index
 is invalid.
-.\" XXX: ZERR_CHANGED
+If
+.Dv ZIP_FL_UNCHANGED
+is not set and no information can be obtained from the source
+callback, the error information is set to
+.Er ZIP_ER_CHANGED .
 .Sh SEE ALSO
-.Xr zip_name_locate 3
+.Xr libzip 3 ,
+.Xr zip_name_locate 3 ,
+.Xr zip_stat_init 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_strerror.man b/man/zip_stat_init.man
similarity index 69%
copy from man/zip_strerror.man
copy to man/zip_stat_init.man
index 3b82061..9f176fe 100644
--- a/man/zip_strerror.man
+++ b/man/zip_stat_init.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp 
-.\" $NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp $
+.\" from NiH: zip_stat_init.mdoc,v 1.1 2006/12/16 10:13:13 wiz Exp 
+.\" $NiH: zip_stat_init.mdoc,v 1.1 2006/12/16 10:13:13 wiz Exp $
 .\"
-.\" zip_strerror.mdoc \-- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_stat_init.mdoc \-- init zip_stat structure
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,27 +33,33 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_STRERROR 3 "October 3, 2003" NiH
+.TH ZIP_STAT_INIT 3 "December 16, 2006" NiH
 .SH "NAME"
-zip_strerror \- get string representation of zip error
+zip_stat_init \- initialize zip_stat structure
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+#include <zip.h>
+.PP
+void
+zip_stat_init(struct zip_stat *sb);
 .SH "DESCRIPTION"
 The
-.Fn zip_strerror
-function returns a string describing the last error for
-\fBarchive.\fR
-The returned string must not be modified or freed, and becomes invalid when
-\fBarchive\fR
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
+zip_stat_init
+function initializes the members of a struct zip_stat.
+The current members are described in
+zip_stat(3),
+but this function should be used to initialize it to
+make sure none are missed.
 .SH "RETURN VALUES"
-.Fn zip_strerror
-returns a pointer to the error string.
+If
+\fBsb\fR
+is valid, the function is always successful.
 .SH "SEE ALSO"
-zip_error_str(3)
+libzip(3),
+zip_stat(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_strerror.mdoc b/man/zip_stat_init.mdoc
similarity index 71%
copy from man/zip_strerror.mdoc
copy to man/zip_stat_init.mdoc
index 529c361..fac9052 100644
--- a/man/zip_strerror.mdoc
+++ b/man/zip_stat_init.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH$
 .\"
-.\" zip_strerror.mdoc -- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_stat_init.mdoc -- init zip_stat structure
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,30 +31,35 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd December 16, 2006
+.Dt ZIP_STAT_INIT 3
 .Os
 .Sh NAME
-.Nm zip_strerror
-.Nd get string representation of zip error
+.Nm zip_stat_init
+.Nd initialize zip_stat structure
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+.Ft void
+.Fn zip_stat_init "struct zip_stat *sb"
 .Sh DESCRIPTION
 The
-.Fn zip_strerror
-function returns a string describing the last error for
-.Ar archive .
-The returned string must not be modified or freed, and becomes invalid when
-.Ar archive
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
+.Fn zip_stat_init
+function initializes the members of a struct zip_stat.
+The current members are described in
+.Xr zip_stat 3 ,
+but this function should be used to initialize it to
+make sure none are missed.
 .Sh RETURN VALUES
-.Fn zip_strerror
-returns a pointer to the error string.
+If
+.Ar sb
+is valid, the function is always successful.
 .Sh SEE ALSO
-.Xr zip_error_str 3
+.Xr libzip 3 ,
+.Xr zip_stat 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_unchange.man b/man/zip_unchange.man
index 2411cd7..caa2aaf 100644
--- a/man/zip_unchange.man
+++ b/man/zip_unchange.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_unchange.mdoc,v 1.3 2003/10/03 12:04:09 dillo Exp 
-.\" $NiH: zip_unchange.mdoc,v 1.3 2003/10/03 12:04:09 dillo Exp $
+.\" from NiH: zip_unchange.mdoc,v 1.12 2006/04/23 13:14:46 wiz Exp 
+.\" $NiH: zip_unchange.mdoc,v 1.12 2006/04/23 13:14:46 wiz Exp $
 .\"
 .\" zip_unchange.mdoc \-- undo changes to file in zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005, 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,34 +33,44 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_UNCHANGE 3 "October 3, 2003" NiH
+.TH ZIP_UNCHANGE 3 "April 23, 2006" NiH
 .SH "NAME"
 zip_unchange \- undo changes to file in zip archive
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_unchange "struct zip *archive" "int index"
+#include <zip.h>
+.PP
+int
+zip_unchange(struct zip *archive, int index);
 .SH "DESCRIPTION"
 Changes to the file at position
 \fBindex\fR
 are reverted.
 .SH "RETURN VALUES"
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+\fBarchive\fR
 is set to indicate the error.
 .SH "ERRORS"
-.Fn zip_unchange
+zip_unchange
 fails if:
 .RS
 .TP 4
-Bq Er ZERR_INVAL
+[ZIP_ER_EXISTS]
+Unchanging the name would result in a duplicate name in the archive.
+.TP 4
+[ZIP_ER_INVAL]
 \fBindex\fR
 is not a valid file index in
 \fBzip.\fR
-.\: XXX: also ch_func ZIP_CMD_CLOSE errors
 .RE
 .SH "SEE ALSO"
-zip_unchange_all(3)
+libzip(3),
+zip_unchange_all(3),
+zip_unchange_archive(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_unchange.mdoc b/man/zip_unchange.mdoc
index 35c813b..337a5d9 100644
--- a/man/zip_unchange.mdoc
+++ b/man/zip_unchange.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_unchange.mdoc,v 1.2 2003/10/03 09:44:43 wiz Exp $
+.\" $NiH: zip_unchange.mdoc,v 1.11 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_unchange.mdoc -- undo changes to file in zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005, 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,7 +31,7 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
+.Dd April 23, 2006
 .Dt ZIP_UNCHANGE 3
 .Os
 .Sh NAME
@@ -49,18 +49,26 @@
 are reverted.
 .Sh RETURN VALUES
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+.Ar archive
 is set to indicate the error.
 .Sh ERRORS
 .Fn zip_unchange
 fails if:
 .Bl -tag -width Er
-.It Bq Er ZERR_INVAL
+.It Bq Er ZIP_ER_EXISTS
+Unchanging the name would result in a duplicate name in the archive.
+.It Bq Er ZIP_ER_INVAL
 .Ar index
 is not a valid file index in
 .Ar zip .
-.\: XXX: also ch_func ZIP_CMD_CLOSE errors
 .El
 .Sh SEE ALSO
-.Xr zip_unchange_all 3
+.Xr libzip 3 ,
+.Xr zip_unchange_all 3 ,
+.Xr zip_unchange_archive 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_unchange_all.man b/man/zip_unchange_all.man
index 0a94008..b995fc8 100644
--- a/man/zip_unchange_all.man
+++ b/man/zip_unchange_all.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_unchange_all.mdoc,v 1.3 2003/10/03 12:04:09 dillo Exp 
-.\" $NiH: zip_unchange_all.mdoc,v 1.3 2003/10/03 12:04:09 dillo Exp $
+.\" from NiH: zip_unchange_all.mdoc,v 1.11 2006/04/23 13:14:46 wiz Exp 
+.\" $NiH: zip_unchange_all.mdoc,v 1.11 2006/04/23 13:14:46 wiz Exp $
 .\"
 .\" zip_unchange_all.mdoc \-- undo changes to all files in zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005, 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,26 +33,31 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_UNCHANGE_ALL 3 "October 3, 2003" NiH
+.TH ZIP_UNCHANGE_ALL 3 "April 23, 2006" NiH
 .SH "NAME"
-zip_unchange_all \- undo changes to all files in zip archive
+zip_unchange_all \- undo all changes in a zip archive
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft int
-.Fn zip_unchange_all "struct zip *archive"
+#include <zip.h>
+.PP
+int
+zip_unchange_all(struct zip *archive);
 .SH "DESCRIPTION"
-Changes to all files in
+All changes to files and global information in
 \fBarchive\fR
 are reverted.
 .SH "RETURN VALUES"
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+\fBarchive\fR
 is set to indicate the error.
-.\".SH "ERRORS"
-.\: XXX: ch_func ZIP_CMD_CLOSE errors
-.RE
 .SH "SEE ALSO"
-zip_unchange(3)
+libzip(3),
+zip_unchange(3),
+zip_unchange_archive(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_unchange_all.mdoc b/man/zip_unchange_all.mdoc
index 21c4e44..7fb338e 100644
--- a/man/zip_unchange_all.mdoc
+++ b/man/zip_unchange_all.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_unchange_all.mdoc,v 1.2 2003/10/03 09:44:43 wiz Exp $
+.\" $NiH: zip_unchange_all.mdoc,v 1.10 2005/06/09 21:14:54 wiz Exp $
 .\"
 .\" zip_unchange_all.mdoc -- undo changes to all files in zip archive
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005, 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,12 +31,12 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
+.Dd April 23, 2006
 .Dt ZIP_UNCHANGE_ALL 3
 .Os
 .Sh NAME
 .Nm zip_unchange_all
-.Nd undo changes to all files in zip archive
+.Nd undo all changes in a zip archive
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
@@ -44,16 +44,20 @@
 .Ft int
 .Fn zip_unchange_all "struct zip *archive"
 .Sh DESCRIPTION
-Changes to all files in
+All changes to files and global information in
 .Ar archive
 are reverted.
 .Sh RETURN VALUES
 Upon successful completion 0 is returned.
-Otherwise, \-1 is returned and the global variable
-.Va zip_err
+Otherwise, \-1 is returned and the error code in
+.Ar archive
 is set to indicate the error.
-.\".Sh ERRORS
-.\: XXX: ch_func ZIP_CMD_CLOSE errors
-.El
 .Sh SEE ALSO
-.Xr zip_unchange 3
+.Xr libzip 3 ,
+.Xr zip_unchange 3 ,
+.Xr zip_unchange_archive 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zip_strerror.man b/man/zip_unchange_archive.man
similarity index 68%
copy from man/zip_strerror.man
copy to man/zip_unchange_archive.man
index 3b82061..be0bdad 100644
--- a/man/zip_strerror.man
+++ b/man/zip_unchange_archive.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp 
-.\" $NiH: zip_strerror.mdoc,v 1.2 2003/12/27 22:29:12 wiz Exp $
+.\" from NiH: zip_unchange_archive.mdoc,v 1.1 2006/04/23 13:14:46 wiz Exp 
+.\" $NiH: zip_unchange_archive.mdoc,v 1.1 2006/04/23 13:14:46 wiz Exp $
 .\"
-.\" zip_strerror.mdoc \-- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_unchange_archive.mdoc \-- undo changes to all files in zip archive
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -33,27 +33,31 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.TH ZIP_STRERROR 3 "October 3, 2003" NiH
+.TH ZIP_UNCHANGE_ARCHIVE 3 "April 23, 2006" NiH
 .SH "NAME"
-zip_strerror \- get string representation of zip error
+zip_unchange_archive \- undo global changes to zip archive
 .SH "LIBRARY"
 libzip (-lzip)
 .SH "SYNOPSIS"
-.In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+#include <zip.h>
+.PP
+int
+zip_unchange_archive(struct zip *archive);
 .SH "DESCRIPTION"
-The
-.Fn zip_strerror
-function returns a string describing the last error for
+Revert all global changes to the archive
 \fBarchive.\fR
-The returned string must not be modified or freed, and becomes invalid when
-\fBarchive\fR
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
+For now, this only reverts archive comment changes.
 .SH "RETURN VALUES"
-.Fn zip_strerror
-returns a pointer to the error string.
+Upon successful completion 0 is returned.
+Otherwise, \-1 is returned and the error code in
+\fBarchive\fR
+is set to indicate the error.
 .SH "SEE ALSO"
-zip_error_str(3)
+libzip(3),
+zip_unchange(3),
+zip_unchange_all(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zip_strerror.mdoc b/man/zip_unchange_archive.mdoc
similarity index 69%
copy from man/zip_strerror.mdoc
copy to man/zip_unchange_archive.mdoc
index 529c361..9ecc31f 100644
--- a/man/zip_strerror.mdoc
+++ b/man/zip_unchange_archive.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zip_strerror.mdoc,v 1.1 2003/10/05 16:05:25 dillo Exp $
+.\" $NiH: zip_unchange_all.mdoc,v 1.10 2005/06/09 21:14:54 wiz Exp $
 .\"
-.\" zip_strerror.mdoc -- get string representation of zip error
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" zip_unchange_archive.mdoc -- undo changes to all files in zip archive
+.\" Copyright (C) 2006 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -31,30 +31,33 @@
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 3, 2003
-.Dt ZIP_STRERROR 3
+.Dd April 23, 2006
+.Dt ZIP_UNCHANGE_ARCHIVE 3
 .Os
 .Sh NAME
-.Nm zip_strerror
-.Nd get string representation of zip error
+.Nm zip_unchange_archive
+.Nd undo global changes to zip archive
 .Sh LIBRARY
 libzip (-lzip)
 .Sh SYNOPSIS
 .In zip.h
-.Ft const char *
-.Fn zip_strerror "struct zip *archive"
+.Ft int
+.Fn zip_unchange_archive "struct zip *archive"
 .Sh DESCRIPTION
-The
-.Fn zip_strerror
-function returns a string describing the last error for
+Revert all global changes to the archive
 .Ar archive .
-The returned string must not be modified or freed, and becomes invalid when
-.Ar archive
-is closed or on the next call to
-.Fn zip_strerror
-for the same archive.
+For now, this only reverts archive comment changes.
 .Sh RETURN VALUES
-.Fn zip_strerror
-returns a pointer to the error string.
+Upon successful completion 0 is returned.
+Otherwise, \-1 is returned and the error code in
+.Ar archive
+is set to indicate the error.
 .Sh SEE ALSO
-.Xr zip_error_str 3
+.Xr libzip 3 ,
+.Xr zip_unchange 3 ,
+.Xr zip_unchange_all 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zipcmp.man b/man/zipcmp.man
index c71e64f..00d5be5 100644
--- a/man/zipcmp.man
+++ b/man/zipcmp.man
@@ -1,9 +1,9 @@
 .\" Converted with mdoc2man 0.2
-.\" from NiH: zipcmp.mdoc,v 1.7 2003/10/03 23:55:12 dillo Exp 
-.\" $NiH: zipcmp.mdoc,v 1.7 2003/10/03 23:55:12 dillo Exp $
+.\" from NiH: zipcmp.mdoc,v 1.12 2005/06/17 12:59:06 wiz Exp 
+.\" $NiH: zipcmp.mdoc,v 1.12 2005/06/17 12:59:06 wiz Exp $
 .\"
 .\" zipcmp.mdoc \-- compare zip archives
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -76,5 +76,11 @@
 .B zipcmp
 exits 0 if the two zip archives contain the same files, 1 if they differ,
 and \*[Gt]1 if an error occurred.
-.\".SH "SEE ALSO"
-.\" XXX
+.SH "SEE ALSO"
+zipmerge(1),
+libzip(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zipcmp.mdoc b/man/zipcmp.mdoc
index 4f27d2c..38622b9 100644
--- a/man/zipcmp.mdoc
+++ b/man/zipcmp.mdoc
@@ -1,7 +1,7 @@
-.\" $NiH: zipcmp.mdoc,v 1.6 2003/10/03 23:54:30 dillo Exp $
+.\" $NiH: zipcmp.mdoc,v 1.11 2005/06/09 21:13:13 wiz Exp $
 .\"
 .\" zipcmp.mdoc -- compare zip archives
-.\" Copyright (C) 2003 Dieter Baron and Thomas Klausner
+.\" Copyright (C) 2003, 2005 Dieter Baron and Thomas Klausner
 .\"
 .\" This file is part of libzip, a library to manipulate ZIP archives.
 .\" The authors can be contacted at <nih@giga.or.at>
@@ -52,7 +52,7 @@
 File order and compressed size differences are ignored.
 .Pp
 Supported options:
-.Bl -tag -width XXX
+.Bl -tag -width MMM
 .It Fl h
 Display a short help message and exit.
 .It Fl i
@@ -72,5 +72,11 @@
 .Nm
 exits 0 if the two zip archives contain the same files, 1 if they differ,
 and \*[Gt]1 if an error occurred.
-.\".Sh SEE ALSO
-.\" XXX
+.Sh SEE ALSO
+.Xr zipmerge 1 ,
+.Xr libzip 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/man/zipmerge.man b/man/zipmerge.man
new file mode 100644
index 0000000..ca56e4d
--- /dev/null
+++ b/man/zipmerge.man
@@ -0,0 +1,93 @@
+.\" Converted with mdoc2man 0.2
+.\" from NiH: zipmerge.mdoc,v 1.6 2005/06/09 21:14:54 wiz Exp 
+.\" $NiH: zipmerge.mdoc,v 1.6 2005/06/09 21:14:54 wiz Exp $
+.\"
+.\" zipmerge.mdoc \-- merge zip archives
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.TH ZIPMERGE 1 "December 22, 2004" NiH
+.SH "NAME"
+zipmerge \- merge zip archives
+.SH "SYNOPSIS"
+.B zipmerge
+[\fB-DhIiSsV\fR]
+\fBtarget-zip\fR
+\fBsource-zip Op \fBsource-zip ...\fR\fR
+.SH "DESCRIPTION"
+.B zipmerge
+merges the source zip archives
+\fBsource-zip\fR
+into the target zip archive
+\fBtarget-zip.\fR
+By default, files in the source zip archives overwrite
+existing files of the same name in the target zip archive.
+.PP
+Supported options:
+.RS
+.TP 5
+\fB-D\fR
+Ignore directory components in file name comparisons.
+.TP 5
+\fB-h\fR
+Display a short help message and exit.
+.TP 5
+\fB-I\fR
+Ignore case in file name comparisons
+.TP 5
+\fB-i\fR
+Ask before overwriting files.
+See also
+\fB-s\fR.
+.TP 5
+\fB-S\fR
+Do not overwrite files that have the same size and
+CRC32 in both the source and target archives.
+.TP 5
+\fB-s\fR
+When
+\fB-i\fR
+is given, do not before overwriting files that have the same size
+and CRC32.
+.TP 5
+\fB-V\fR
+Display version information and exit.
+.RE
+.SH "EXIT STATUS"
+.B zipmerge
+exits 0 on success and \*[Gt]1 if an error code.
+.SH "SEE ALSO"
+zipcmp(1),
+libzip(3)
+.SH "AUTHORS"
+
+Dieter Baron <dillo@giga.or.at>
+and
+Thomas Klausner <tk@giga.or.at>
diff --git a/man/zipmerge.mdoc b/man/zipmerge.mdoc
new file mode 100644
index 0000000..acabbea
--- /dev/null
+++ b/man/zipmerge.mdoc
@@ -0,0 +1,87 @@
+.\" $NiH: zipmerge.mdoc,v 1.5 2005/06/09 21:13:13 wiz Exp $
+.\"
+.\" zipmerge.mdoc -- merge zip archives
+.\" Copyright (C) 2004, 2005 Dieter Baron and Thomas Klausner
+.\"
+.\" This file is part of libzip, a library to manipulate ZIP archives.
+.\" The authors can be contacted at <nih@giga.or.at>
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in
+.\"    the documentation and/or other materials provided with the
+.\"    distribution.
+.\" 3. The names of the authors may not be used to endorse or promote
+.\"    products derived from this software without specific prior
+.\"    written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+.\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+.\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+.\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd December 22, 2004
+.Dt ZIPMERGE 1
+.Os
+.Sh NAME
+.Nm zipmerge
+.Nd merge zip archives
+.Sh SYNOPSIS
+.Nm
+.Op Fl DhIiSsV
+.Ar target-zip
+.Ar source-zip Op Ar source-zip ...
+.Sh DESCRIPTION
+.Nm
+merges the source zip archives
+.Ar source-zip
+into the target zip archive
+.Ar target-zip .
+By default, files in the source zip archives overwrite
+existing files of the same name in the target zip archive.
+.Pp
+Supported options:
+.Bl -tag -width MMM
+.It Fl D
+Ignore directory components in file name comparisons.
+.It Fl h
+Display a short help message and exit.
+.It Fl I
+Ignore case in file name comparisons
+.It Fl i
+Ask before overwriting files.
+See also
+.Fl s .
+.It Fl S
+Do not overwrite files that have the same size and
+CRC32 in both the source and target archives.
+.It Fl s
+When
+.Fl i
+is given, do not before overwriting files that have the same size
+and CRC32.
+.It Fl V
+Display version information and exit.
+.El
+.Sh EXIT STATUS
+.Nm
+exits 0 on success and \*[Gt]1 if an error code.
+.Sh SEE ALSO
+.Xr zipcmp 1 ,
+.Xr libzip 3
+.Sh AUTHORS
+.An -nosplit
+.An Dieter Baron Aq dillo@giga.or.at
+and
+.An Thomas Klausner Aq tk@giga.or.at
diff --git a/missing b/missing
index e7ef83a..1c8ff70 100755
--- a/missing
+++ b/missing
@@ -1,9 +1,9 @@
 #! /bin/sh
 # Common stub for a few missing GNU programs while installing.
 
-scriptversion=2003-09-02.23
+scriptversion=2006-05-10.23
 
-# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003 
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005, 2006
 #   Free Software Foundation, Inc.
 # Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
 
@@ -19,8 +19,8 @@
 
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
 
 # As a special exception to the GNU General Public License, if you
 # distribute this file as part of a program that contains a
@@ -33,6 +33,8 @@
 fi
 
 run=:
+sed_output='s/.* --output[ =]\([^ ]*\).*/\1/p'
+sed_minuso='s/.* -o \([^ ]*\).*/\1/p'
 
 # In the cases where this matters, `missing' is being run in the
 # srcdir already.
@@ -44,7 +46,7 @@
 
 msg="missing on your system"
 
-case "$1" in
+case $1 in
 --run)
   # Try to run requested program, and just exit if it succeeds.
   run=
@@ -60,11 +62,6 @@
     msg="probably too old"
   fi
   ;;
-esac
-
-# If it does not exist, or fails to run (possibly an outdated version),
-# try to emulate it.
-case "$1" in
 
   -h|--h|--he|--hel|--help)
     echo "\
@@ -82,6 +79,7 @@
   aclocal      touch file \`aclocal.m4'
   autoconf     touch file \`configure'
   autoheader   touch file \`config.h.in'
+  autom4te     touch the output file, or create a stub one
   automake     touch all \`Makefile.in' files
   bison        create \`y.tab.[ch]', if possible, from existing .[ch]
   flex         create \`lex.yy.c', if possible, from existing .c
@@ -92,10 +90,12 @@
   yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
 
 Send bug reports to <bug-automake@gnu.org>."
+    exit $?
     ;;
 
   -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
     echo "missing $scriptversion (GNU Automake)"
+    exit $?
     ;;
 
   -*)
@@ -104,12 +104,42 @@
     exit 1
     ;;
 
-  aclocal*)
+esac
+
+# Now exit if we have it, but it failed.  Also exit now if we
+# don't have it and --version was passed (most likely to detect
+# the program).
+case $1 in
+  lex|yacc)
+    # Not GNU programs, they don't have --version.
+    ;;
+
+  tar)
+    if test -n "$run"; then
+       echo 1>&2 "ERROR: \`tar' requires --run"
+       exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       exit 1
+    fi
+    ;;
+
+  *)
     if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
        # We have it, but it failed.
        exit 1
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
+       # Could not run --version or --help.  This is probably someone
+       # running `$TOOL --version' or `$TOOL --help' to check whether
+       # $TOOL exists and not knowing $TOOL uses missing.
+       exit 1
     fi
+    ;;
+esac
 
+# If it does not exist, or fails to run (possibly an outdated version),
+# try to emulate it.
+case $1 in
+  aclocal*)
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
@@ -119,11 +149,6 @@
     ;;
 
   autoconf)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`${configure_ac}'.  You might want to install the
@@ -133,11 +158,6 @@
     ;;
 
   autoheader)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`acconfig.h' or \`${configure_ac}'.  You might want
@@ -147,7 +167,7 @@
     test -z "$files" && files="config.h"
     touch_files=
     for f in $files; do
-      case "$f" in
+      case $f in
       *:*) touch_files="$touch_files "`echo "$f" |
 				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
       *) touch_files="$touch_files $f.in";;
@@ -157,11 +177,6 @@
     ;;
 
   automake*)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
@@ -173,11 +188,6 @@
     ;;
 
   autom4te)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
 WARNING: \`$1' is needed, but is $msg.
          You might have modified some files without having the
@@ -185,8 +195,8 @@
          You can get \`$1' as part of \`Autoconf' from any GNU
          archive site."
 
-    file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
-    test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'`
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
     if test -f "$file"; then
 	touch $file
     else
@@ -207,25 +217,25 @@
          in order for those modifications to take effect.  You can get
          \`Bison' from any GNU archive site."
     rm -f y.tab.c y.tab.h
-    if [ $# -ne 1 ]; then
+    if test $# -ne 1; then
         eval LASTARG="\${$#}"
-	case "$LASTARG" in
+	case $LASTARG in
 	*.y)
 	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
-	    if [ -f "$SRCFILE" ]; then
+	    if test -f "$SRCFILE"; then
 	         cp "$SRCFILE" y.tab.c
 	    fi
 	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
-	    if [ -f "$SRCFILE" ]; then
+	    if test -f "$SRCFILE"; then
 	         cp "$SRCFILE" y.tab.h
 	    fi
 	  ;;
 	esac
     fi
-    if [ ! -f y.tab.h ]; then
+    if test ! -f y.tab.h; then
 	echo >y.tab.h
     fi
-    if [ ! -f y.tab.c ]; then
+    if test ! -f y.tab.c; then
 	echo 'main() { return 0; }' >y.tab.c
     fi
     ;;
@@ -237,39 +247,32 @@
          in order for those modifications to take effect.  You can get
          \`Flex' from any GNU archive site."
     rm -f lex.yy.c
-    if [ $# -ne 1 ]; then
+    if test $# -ne 1; then
         eval LASTARG="\${$#}"
-	case "$LASTARG" in
+	case $LASTARG in
 	*.l)
 	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
-	    if [ -f "$SRCFILE" ]; then
+	    if test -f "$SRCFILE"; then
 	         cp "$SRCFILE" lex.yy.c
 	    fi
 	  ;;
 	esac
     fi
-    if [ ! -f lex.yy.c ]; then
+    if test ! -f lex.yy.c; then
 	echo 'main() { return 0; }' >lex.yy.c
     fi
     ;;
 
   help2man)
-    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
-       # We have it, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
 	 you modified a dependency of a manual page.  You may need the
 	 \`Help2man' package in order for those modifications to take
 	 effect.  You can get \`Help2man' from any GNU archive site."
 
-    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
-    if test -z "$file"; then
-	file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
-    fi
-    if [ -f "$file" ]; then
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
+    if test -f "$file"; then
 	touch $file
     else
 	test -z "$file" || exec >$file
@@ -279,11 +282,6 @@
     ;;
 
   makeinfo)
-    if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then
-       # We have makeinfo, but it failed.
-       exit 1
-    fi
-
     echo 1>&2 "\
 WARNING: \`$1' is $msg.  You should only need it if
          you modified a \`.texi' or \`.texinfo' file, or any other file
@@ -291,20 +289,29 @@
          call might also be the consequence of using a buggy \`make' (AIX,
          DU, IRIX).  You might want to install the \`Texinfo' package or
          the \`GNU make' package.  Grab either from any GNU archive site."
-    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
+    # The file to touch is that specified with -o ...
+    file=`echo "$*" | sed -n "$sed_output"`
+    test -z "$file" && file=`echo "$*" | sed -n "$sed_minuso"`
     if test -z "$file"; then
-      file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
-      file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file`
+      # ... or it is the one specified with @setfilename ...
+      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
+      file=`sed -n '
+	/^@setfilename/{
+	  s/.* \([^ ]*\) *$/\1/
+	  p
+	  q
+	}' $infile`
+      # ... or it is derived from the source name (dir/f.texi becomes f.info)
+      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
     fi
+    # If the file does not exist, the user really needs makeinfo;
+    # let's fail without touching anything.
+    test -f $file || exit 1
     touch $file
     ;;
 
   tar)
     shift
-    if test -n "$run"; then
-      echo 1>&2 "ERROR: \`tar' requires --run"
-      exit 1
-    fi
 
     # We have already tried tar in the generic part.
     # Look for gnutar/gtar before invocation to avoid ugly error
@@ -317,13 +324,13 @@
     fi
     firstarg="$1"
     if shift; then
-	case "$firstarg" in
+	case $firstarg in
 	*o*)
 	    firstarg=`echo "$firstarg" | sed s/o//`
 	    tar "$firstarg" "$@" && exit 0
 	    ;;
 	esac
-	case "$firstarg" in
+	case $firstarg in
 	*h*)
 	    firstarg=`echo "$firstarg" | sed s/h//`
 	    tar "$firstarg" "$@" && exit 0
diff --git a/mkinstalldirs b/mkinstalldirs
index 6504b74..ef7e16f 100755
--- a/mkinstalldirs
+++ b/mkinstalldirs
@@ -1,7 +1,7 @@
 #! /bin/sh
 # mkinstalldirs --- make directory hierarchy
 
-scriptversion=2003-11-08.23
+scriptversion=2006-05-11.19
 
 # Original author: Noah Friedman <friedman@prep.ai.mit.edu>
 # Created: 1993-05-16
@@ -11,8 +11,11 @@
 # bugs to <bug-automake@gnu.org> or send patches to
 # <automake-patches@gnu.org>.
 
+nl='
+'
+IFS=" ""	$nl"
 errstatus=0
-dirmode=""
+dirmode=
 
 usage="\
 Usage: mkinstalldirs [-h] [--help] [--version] [-m MODE] DIR ...
@@ -27,7 +30,7 @@
   case $1 in
     -h | --help | --h*)         # -h for help
       echo "$usage"
-      exit 0
+      exit $?
       ;;
     -m)                         # -m PERM arg
       shift
@@ -37,7 +40,7 @@
       ;;
     --version)
       echo "$0 $scriptversion"
-      exit 0
+      exit $?
       ;;
     --)                         # stop option processing
       shift
@@ -66,9 +69,15 @@
   0) exit 0 ;;
 esac
 
+# Solaris 8's mkdir -p isn't thread-safe.  If you mkdir -p a/b and
+# mkdir -p a/c at the same time, both will detect that a is missing,
+# one will create a, then the other will try to create a and die with
+# a "File exists" error.  This is a problem when calling mkinstalldirs
+# from a parallel make.  We use --version in the probe to restrict
+# ourselves to GNU mkdir, which is thread-safe.
 case $dirmode in
   '')
-    if mkdir -p -- . 2>/dev/null; then
+    if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
       echo "mkdir -p -- $*"
       exec mkdir -p -- "$@"
     else
@@ -77,16 +86,17 @@
       # directories to create, and then abort because `.' already
       # exists.
       test -d ./-p && rmdir ./-p
-      test -d ./-- && rmdir ./--
+      test -d ./--version && rmdir ./--version
     fi
     ;;
   *)
-    if mkdir -m "$dirmode" -p -- . 2>/dev/null; then
+    if mkdir -m "$dirmode" -p --version . >/dev/null 2>&1 &&
+       test ! -d ./--version; then
       echo "mkdir -m $dirmode -p -- $*"
       exec mkdir -m "$dirmode" -p -- "$@"
     else
       # Clean up after NextStep and OpenStep mkdir.
-      for d in ./-m ./-p ./-- "./$dirmode";
+      for d in ./-m ./-p ./--version "./$dirmode";
       do
         test -d $d && rmdir $d
       done
@@ -96,13 +106,21 @@
 
 for file
 do
-  set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
+  case $file in
+    /*) pathcomp=/ ;;
+    *)  pathcomp= ;;
+  esac
+  oIFS=$IFS
+  IFS=/
+  set fnord $file
   shift
+  IFS=$oIFS
 
-  pathcomp=
   for d
   do
-    pathcomp="$pathcomp$d"
+    test "x$d" = x && continue
+
+    pathcomp=$pathcomp$d
     case $pathcomp in
       -*) pathcomp=./$pathcomp ;;
     esac
@@ -117,7 +135,7 @@
       else
 	if test ! -z "$dirmode"; then
 	  echo "chmod $dirmode $pathcomp"
-	  lasterr=""
+	  lasterr=
 	  chmod "$dirmode" "$pathcomp" || lasterr=$?
 
 	  if test ! -z "$lasterr"; then
@@ -127,7 +145,7 @@
       fi
     fi
 
-    pathcomp="$pathcomp/"
+    pathcomp=$pathcomp/
   done
 done
 
diff --git a/regress/CMakeLists.txt b/regress/CMakeLists.txt
new file mode 100644
index 0000000..0a589f3
--- /dev/null
+++ b/regress/CMakeLists.txt
@@ -0,0 +1,27 @@
+# $NiH$
+
+ENABLE_TESTING()
+
+SET(TEST_PROGRAMS
+  add_from_buffer
+  add_from_file
+  add_from_filep
+  encrypt
+  fread
+  get_comment
+  name_locate
+  open
+  set_comment_all
+  set_comment_localonly
+  set_comment_removeglobal
+  set_comment_revert
+)
+
+SET(ENV{srcdir} ${CMAKE_CURRENT_SOURCE_DIR})
+FOREACH(PROGRAM ${TEST_PROGRAMS})
+  ADD_EXECUTABLE(${PROGRAM} ${PROGRAM}.c)
+  TARGET_LINK_LIBRARIES(${PROGRAM} zip)
+  ADD_TEST(${PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/runtest ${CMAKE_CURRENT_SOURCE_DIR}/${PROGRAM})
+ENDFOREACH(PROGRAM ${TEST_PROGRAMS})
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../lib)
diff --git a/regress/Makefile.am b/regress/Makefile.am
index e1f1b8d..4551cf2 100644
--- a/regress/Makefile.am
+++ b/regress/Makefile.am
@@ -1,13 +1,67 @@
-noinst_PROGRAMS=buffadd open
-EXTRA_PROGRAMS=ziptest deltest
+noinst_PROGRAMS= \
+	add_from_buffer \
+	add_from_file \
+	add_from_filep \
+	encrypt \
+	fread \
+	get_comment \
+	open \
+	name_locate \
+	set_comment_all \
+	set_comment_localonly \
+	set_comment_removeglobal \
+	set_comment_revert
 
-EXTRA_DIST=test.zip
+EXTRA_PROGRAMS=deltest ziptest
 
-deltest_SOURCES=deltest.c
-buffadd_SOURCES=buffadd.c
-ziptest_SOURCES=ziptest.c
+EXTRA_DIST= \
+	CMakeLists.txt \
+	runtest \
+	${TESTCASES} \
+	testbuffer.zip \
+	testchanged.zip testchangedlocal.zip \
+	testcomment.zip testcommentremoved.zip \
+	testfile.txt testfile.zip \
+	broken.zip test.zip encrypt.zip
 
-TESTS=buffadd open
+TESTS_ENVIRONMENT=	ZIPCMP=${top_builddir}/src/zipcmp
+
+TESTCASES= \
+	add_from_buffer.test \
+	add_from_file.test \
+	add_from_filep.test \
+	encrypt.test \
+	fread.test \
+	get_comment.test \
+	name_locate.test \
+	open.test \
+	set_comment_all.test \
+	set_comment_localonly.test \
+	set_comment_removeglobal.test \
+	set_comment_revert.test
+
+check:
+	@failed=0; all=0; \
+	for tst in ${TESTCASES}; do \
+	  if ${TESTS_ENVIRONMENT} $(srcdir)/runtest `pwd`/${top_srcdir}/regress/$$tst; then \
+	    all=`expr $$all + 1`; \
+	    echo "PASS: $$tst"; \
+	  elif test $$? -ne 77; then \
+	    all=`expr $$all + 1`; \
+	    failed=`expr $$failed + 1`; \
+	    echo "FAIL: $$tst"; \
+	  fi; \
+	done; \
+	if test "$$failed" -eq 0; then \
+	  banner="All $$all tests passed"; \
+	else \
+	  banner="$$failed of $$all tests failed"; \
+	fi; \
+	dashes=`echo "$$banner" | sed s/./=/g`; \
+	echo "$$dashes"; \
+	echo "$$banner"; \
+	echo "$$dashes"; \
+	test "$$failed" -eq 0
 
 AM_CPPFLAGS=-I${top_srcdir}/lib
-LDADD=../lib/libzip.la
+LDADD=${top_builddir}/lib/libzip.la
diff --git a/regress/add_from_buffer.c b/regress/add_from_buffer.c
new file mode 100644
index 0000000..fd11f92
--- /dev/null
+++ b/regress/add_from_buffer.c
@@ -0,0 +1,94 @@
+/*
+  $NiH: add_from_buffer.c,v 1.2 2006/02/21 09:41:13 dillo Exp $
+
+  add_from_buffer.c -- test case for adding file from buffer to archive
+  Copyright (C) 1999, 2003, 2005 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zip.h"
+
+const char *teststr="This is a test, and it seems to have been successful.\n";
+const char *file="teststring.txt";
+const char *prg;
+
+int
+main(int argc, char *argv[])
+{
+    const char *archive;
+    struct zip *za;
+    struct zip_source *zs;
+    char buf[100];
+    int err;
+
+    prg = argv[0];
+
+    if (argc != 2) {
+	fprintf(stderr, "usage: %s archive\n", prg);
+	return 1;
+    }
+
+    archive = argv[1];
+    
+    if ((za=zip_open(archive, ZIP_CREATE, &err)) == NULL) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr,"%s: can't open zip archive %s: %s\n", prg,
+		archive, buf);
+	return 1;
+    }
+
+    if ((zs=zip_source_buffer(za, teststr, strlen(teststr), 0)) == NULL) {
+	fprintf(stderr,"%s: can't create zip_source from buffer: %s\n", prg,
+		zip_strerror(za));
+	exit(1);
+    }
+
+    if (zip_add(za, file, zs) == -1) {
+	zip_source_free(zs);
+	fprintf(stderr,"%s: can't add file `%s': %s\n", prg,
+		file, zip_strerror(za));
+	return 1;
+    }
+
+    if (zip_close(za) == -1) {
+	fprintf(stderr,"%s: can't close zip archive %s\n", prg,
+		archive);
+	return 1;
+    }
+
+    return 0;
+}
diff --git a/regress/add_from_buffer.test b/regress/add_from_buffer.test
new file mode 100644
index 0000000..c6e75a0
--- /dev/null
+++ b/regress/add_from_buffer.test
@@ -0,0 +1,6 @@
+# add buffer contents as file to zip
+# $NiH: add_from_buffer.test,v 1.1 2005/07/15 16:54:25 wiz Exp $
+program add_from_buffer
+return 0
+args testbuffer.zip
+file-new testbuffer.zip testbuffer.zip
diff --git a/regress/add_from_file.c b/regress/add_from_file.c
new file mode 100644
index 0000000..35e3ba7
--- /dev/null
+++ b/regress/add_from_file.c
@@ -0,0 +1,98 @@
+/*
+  $NiH: add_from_file.c,v 1.1 2005/07/15 16:53:37 wiz Exp $
+
+  add_from_file.c -- test case for adding file to archive
+  Copyright (C) 1999, 2003, 2005 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zip.h"
+
+static const char *prg;
+
+int
+main(int argc, char *argv[])
+{
+    const char *archive;
+    const char *file;
+    const char *name;
+    struct zip *za;
+    struct zip_source *zs;
+    char buf[100];
+    int err;
+
+    prg = argv[0];
+
+    if (argc != 3) {
+	fprintf(stderr, "usage: %s archive file\n", prg);
+	return 1;
+    }
+
+    archive = argv[1];
+    file = argv[2];
+    
+    if ((za=zip_open(archive, ZIP_CREATE, &err)) == NULL) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr,"%s: can't open zip archive %s: %s\n", prg,
+		archive, buf);
+	return 1;
+    }
+
+    if ((zs=zip_source_file(za, file, 0, -1)) == NULL) {
+	fprintf(stderr,"%s: error creating file source for `%s': %s\n", prg,
+		file, zip_strerror(za));
+	return 1;
+    }
+
+    if ((name=strrchr(file, '/')) == NULL)
+	name = file;
+
+    if (zip_add(za, name, zs) == -1) {
+	zip_source_free(zs);
+	fprintf(stderr,"%s: can't add file `%s': %s\n", prg,
+		file, zip_strerror(za));
+	return 1;
+    }
+
+    if (zip_close(za) == -1) {
+	fprintf(stderr,"%s: can't close zip archive `%s'\n", prg,
+		archive);
+	return 1;
+    }
+
+    return 0;
+}
diff --git a/regress/add_from_file.test b/regress/add_from_file.test
new file mode 100644
index 0000000..35e9ac3
--- /dev/null
+++ b/regress/add_from_file.test
@@ -0,0 +1,7 @@
+# add file to zip
+# $NiH: add_from_file.test,v 1.1 2005/07/15 16:54:25 wiz Exp $
+program add_from_file
+return 0
+args testfile.zip testfile.txt
+file testfile.txt testfile.txt testfile.txt
+file-new testfile.zip testfile.zip
diff --git a/regress/add_from_filep.c b/regress/add_from_filep.c
new file mode 100644
index 0000000..9c2647f
--- /dev/null
+++ b/regress/add_from_filep.c
@@ -0,0 +1,105 @@
+/*
+  $NiH: add_from_filep.c,v 1.1 2005/07/17 00:01:06 wiz Exp $
+
+  add_from_filep.c -- test case for adding file to archive
+  Copyright (C) 1999, 2003, 2005 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zip.h"
+
+static const char *prg;
+
+int
+main(int argc, char *argv[])
+{
+    const char *archive;
+    const char *file;
+    const char *name;
+    struct zip *za;
+    struct zip_source *zs;
+    char buf[100];
+    int err;
+    FILE *fp;
+
+    prg = argv[0];
+
+    if (argc != 3) {
+	fprintf(stderr, "usage: %s archive file\n", prg);
+	return 1;
+    }
+
+    archive = argv[1];
+    file = argv[2];
+    
+    if ((za=zip_open(archive, ZIP_CREATE, &err)) == NULL) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr,"%s: can't open zip archive %s: %s\n", prg,
+		archive, buf);
+	return 1;
+    }
+
+    if ((fp=fopen(file, "r")) == NULL) {
+	fprintf(stderr,"%s: can't open input file `%s': %s\n", prg,
+		file, strerror(errno));
+	return 1;
+    }
+
+    if ((zs=zip_source_filep(za, fp, 0, -1)) == NULL) {
+	fprintf(stderr,"%s: error creating file source for `%s': %s\n", prg,
+		file, zip_strerror(za));
+	return 1;
+    }
+
+    if ((name=strrchr(file, '/')) == NULL)
+	name = file;
+
+    if (zip_add(za, name, zs) == -1) {
+	zip_source_free(zs);
+	fprintf(stderr,"%s: can't add file `%s': %s\n", prg,
+		file, zip_strerror(za));
+	return 1;
+    }
+
+    if (zip_close(za) == -1) {
+	fprintf(stderr,"%s: can't close zip archive `%s'\n", prg,
+		archive);
+	return 1;
+    }
+
+    return 0;
+}
diff --git a/regress/add_from_filep.test b/regress/add_from_filep.test
new file mode 100644
index 0000000..48f7edc
--- /dev/null
+++ b/regress/add_from_filep.test
@@ -0,0 +1,7 @@
+# add file to zip
+# $NiH: add_from_filep.test,v 1.1 2005/07/17 00:01:06 wiz Exp $
+program add_from_filep
+return 0
+args testfile.zip testfile.txt
+file testfile.txt testfile.txt testfile.txt
+file-new testfile.zip testfile.zip
diff --git a/regress/add_invalid.c b/regress/add_invalid.c
index c8ff5af..01b2e27 100644
--- a/regress/add_invalid.c
+++ b/regress/add_invalid.c
@@ -7,7 +7,7 @@
 int
 main(int argc, char *argv[])
 {
-    struct zip *zf, *destzf;
+    struct zip *za, *destza;
     
     prg = argv[0];
     
@@ -17,27 +17,27 @@
     }
 
     seterrinfo(NULL, argv[1]);
-    if ((zf=zip_open(argv[1], 0))==NULL) {
+    if ((za=zip_open(argv[1], 0))==NULL) {
 	myerror(ERRZIPSTR, "can't open file: %s", zip_err_str[zip_err]);
 	return 1;
     }
 
     seterrinfo(NULL, argv[2]);
-    if ((destzf=zip_open(argv[2], ZIP_CREATE))==NULL) {
+    if ((destza=zip_open(argv[2], ZIP_CREATE))==NULL) {
 	myerror(ERRZIPSTR, "can't open file: %s", zip_err_str[zip_err]);
 	return 1;
     }
 
-    if (zip_add_zip(destzf, NULL, NULL, zf, 1, 0, 0) == -1)
+    if (zip_add_zip(destza, NULL, NULL, za, 1, 0, 0) == -1)
 	myerror(ERRZIPSTR, "can't add file to zip-file: %s", zip_err_str[zip_err]);
 
-    if (zip_close(destzf)!=0) {
+    if (zip_close(destza)!=0) {
 	myerror(ERRZIPSTR, "can't close file: %s", zip_err_str[zip_err]);
 	return 1;
     }
 
     seterrinfo(NULL, argv[1]);
-    if (zip_close(zf)!=0) {
+    if (zip_close(za)!=0) {
 	myerror(ERRZIPSTR, "can't close file %s", zip_err_str[zip_err]);
 	return 1;
     }
diff --git a/regress/broken.zip b/regress/broken.zip
new file mode 100644
index 0000000..6dbff3e
--- /dev/null
+++ b/regress/broken.zip
Binary files differ
diff --git a/regress/buffadd.c b/regress/buffadd.c
deleted file mode 100644
index e849604..0000000
--- a/regress/buffadd.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
-  $NiH: buffadd.c,v 1.4 2003/10/06 16:36:00 dillo Exp $
-
-  buffadd.c -- test cases for adding files from buffer
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
-
-  This file is part of libzip, a library to manipulate ZIP archives.
-  The authors can be contacted at <nih@giga.or.at>
-
-  Redistribution and use in source and binary forms, with or without
-  modification, are permitted provided that the following conditions
-  are met:
-  1. Redistributions of source code must retain the above copyright
-     notice, this list of conditions and the following disclaimer.
-  2. Redistributions in binary form must reproduce the above copyright
-     notice, this list of conditions and the following disclaimer in
-     the documentation and/or other materials provided with the
-     distribution.
-  3. The names of the authors may not be used to endorse or promote
-     products derived from this software without specific prior
-     written permission.
- 
-  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
-  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
-  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
-  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
-  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "zip.h"
-
-char *teststr="This is a test, and it seems to have been successful.\n";
-char *testname="testfile.txt";
-char *testzip="test_zip.zip";
-
-int
-main(int argc, char *argv[])
-{
-    struct zip *z;
-    struct zip_file *ze;
-    int err;
-    
-    char buf[2000];
-
-    remove(testzip);
-    
-    if ((z=zip_open(testzip, ZIP_CREATE, &err)) == NULL) {
-	zip_error_str(buf, sizeof(buf), err, errno);
-	fprintf(stderr,"%s: can't open zipfile %s: %s\n", argv[0],
-		testzip, buf);
-	exit(1);
-    }
-
-    if (zip_add_data(z, testname, teststr, strlen(teststr), 0)==-1) {
-	fprintf(stderr,"%s: can't add buffer '%s': %s\n", argv[0],
-		teststr, zip_strerror(z));
-	exit(1);
-    }
-
-    if (zip_close(z) == -1) {
-	fprintf(stderr,"%s: can't close zipfile %s\n", argv[0],
-		testzip);
-	exit(1);
-    }
-
-    if ((z=zip_open(testzip, ZIP_CHECKCONS, &err))==NULL) {
-	zip_error_str(buf, sizeof(buf), err, errno);
-	fprintf(stderr,"%s: can't re-open zipfile %s: %s\n", argv[0],
-		testzip, buf);
-	exit(1);
-    }
-
-    if ((ze=zip_fopen(z, testname, 0))==NULL) {
-	fprintf(stderr,"%s: can't fopen file '%s' in '%s': %s\n", argv[0],
-		testname, testzip, zip_strerror(z));
-	exit(1);
-    }
-
-    if (zip_fread(ze, buf, 2000) < 0) {
-	fprintf(stderr,"%s: can't read from '%s' in zipfile '%s': %s\n",
-		argv[0], testname, testzip, zip_file_strerror(ze));
-	exit(1);
-    }
-    
-    if (strcmp(buf, teststr)) {
-	fprintf(stderr,"%s: wrong data: '%s' instead of '%s'\n", argv[0],
-		buf, teststr);
-	exit(1);
-    }
-
-    if (zip_close(z) == -1) {
-	fprintf(stderr,"%s: can't close zipfile %s\n", argv[0],
-		testzip);
-	exit(1);
-    }
-
-    remove(testzip);
-    
-    return 0;
-}
diff --git a/regress/deltest.c b/regress/deltest.c
index 9262e15..87991e5 100644
--- a/regress/deltest.c
+++ b/regress/deltest.c
@@ -7,7 +7,7 @@
 int
 main(int argc, char *argv[])
 {
-    struct zip *z;
+    struct zip *za;
 
     if (argc != 2) {
 	fprintf(stderr, "%s: call with one option: zip-file. First file"
@@ -15,19 +15,19 @@
 	return 1;
     }
 
-    if ((z=zip_open(argv[1], ZIP_CHECKCONS))==NULL) {
+    if ((za=zip_open(argv[1], ZIP_CHECKCONS))==NULL) {
 	fprintf(stderr, "%s: can't open '%s': %s\n", argv[0], argv[1],
 		zip_err_str[zip_err]);
 	return 1;
     }
 
-    if (zip_delete(z, 0)< 0) {
+    if (zip_delete(za, 0)< 0) {
 	fprintf(stderr, "%s: can't delete first file in '%s': %s", 
 		argv[0], argv[1], zip_err_str[zip_err]);
 	return 1;
     }
 
-    if (zip_close(z)!=0) {
+    if (zip_close(za)!=0) {
 	fprintf(stderr, "%s: can't close file '%s': %s", argv[0], argv[1],
 		zip_err_str[zip_err]);
 	return 1;
diff --git a/lib/zip_error_str.c b/regress/encrypt.c
similarity index 65%
copy from lib/zip_error_str.c
copy to regress/encrypt.c
index a22a673..c36762b 100644
--- a/lib/zip_error_str.c
+++ b/regress/encrypt.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_error_str.c,v 1.1 2003/10/06 02:50:05 dillo Exp $
+  $NiH$
 
-  zip_error_str.c -- get string representation of zip error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  encrypt.c -- test encryption support
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -41,33 +41,44 @@
 #include <string.h>
 
 #include "zip.h"
-#include "zipint.h"
 
-
+const char *prg;
 
 int
-zip_error_str(char *buf, size_t len, int ze, int se)
+main(int argc, char *argv[])
 {
-    const char *zs, *ss;
+    const char *archive;
+    struct zip *za;
+    char buf[100];
+    int err;
+    int i;
+    struct zip_stat st;
 
-    if (ze < 0 || ze >= _zip_nerr_str)
-	return snprintf(buf, len, "Unknown error %d", ze);
+    prg = argv[0];
 
-    zs = _zip_err_str[ze];
-	
-    switch (_zip_err_type[ze]) {
-    case ZIP_ET_SYS:
-	ss = strerror(se);
-	break;
-	
-    case ZIP_ET_ZIP:
-	ss = zError(se);
-	break;
-	
-    default:
-	ss = NULL;
+    if (argc != 2) {
+	fprintf(stderr, "usage: %s archive\n", prg);
+	return 1;
     }
 
-    return snprintf(buf, len, "%s%s%s",
-		    zs, (ss ? ": " : ""), (ss ? ss : ""));
+    archive = argv[1];
+    
+    if ((za=zip_open(archive, 0, &err)) == NULL) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr, "%s: can't open zip archive `%s': %s\n", prg,
+		archive, buf);
+	return 1;
+    }
+
+    for (i=0; i<zip_get_num_files(za); i++) {
+	if (zip_stat_index(za, i, 0, &st) < 0)
+	    fprintf(stderr, "%s: can't stat file %d: %s\n",
+		    prg, i, zip_strerror(za));
+	else
+	    printf("%d: %d\n", i, st.encryption_method);
+    }
+
+    zip_close(za);
+
+    return 0;
 }
diff --git a/regress/encrypt.test b/regress/encrypt.test
new file mode 100644
index 0000000..6fb7371
--- /dev/null
+++ b/regress/encrypt.test
@@ -0,0 +1,8 @@
+# test encryption support
+# $NiH$
+program encrypt
+return 0
+args encrypt.zip
+file encrypt.zip encrypt.zip encrypt.zip
+stdout 0: 1
+stdout 1: 0
diff --git a/regress/encrypt.zip b/regress/encrypt.zip
new file mode 100644
index 0000000..e50aa38
--- /dev/null
+++ b/regress/encrypt.zip
Binary files differ
diff --git a/regress/fileadd.c b/regress/fileadd.c
index f8d4b3a..3e1cdfe 100644
--- a/regress/fileadd.c
+++ b/regress/fileadd.c
@@ -6,7 +6,7 @@
 int
 main(int argc, char *argv[])
 {
-    struct zip *z;
+    struct zip *za;
     int i;
 
     if (argc < 3) {
@@ -15,20 +15,20 @@
 	exit(1);
     }
 
-    if ((z=zip_open(argv[1], ZIP_CHECKCONS|ZIP_CREATE)) == NULL) {
+    if ((za=zip_open(argv[1], ZIP_CHECKCONS|ZIP_CREATE)) == NULL) {
 	fprintf(stderr,"%s: can't open zipfile %s: %s\n", argv[0],
 		argv[1], zip_err_str[zip_err]);
 	exit(1);
     }
 
     for (i=0; i<argc-2; i++)
-	if (zip_add_file(z, NULL, NULL, argv[i+2], 0, -1)==-1) {
+	if (zip_add_file(za, NULL, NULL, argv[i+2], 0, -1)==-1) {
 	    fprintf(stderr,"%s: can't add file %s: %s\n", argv[0],
 		    argv[i+2], zip_err_str[zip_err]);
 	    exit(1);
 	}
 
-    if (zip_close(z) == -1) {
+    if (zip_close(za) == -1) {
 	fprintf(stderr,"%s: can't close zipfile %s: %s\n", argv[0],
 		argv[1], zip_err_str[zip_err]);
 	exit(1);
diff --git a/regress/fread.c b/regress/fread.c
new file mode 100644
index 0000000..caa5745
--- /dev/null
+++ b/regress/fread.c
@@ -0,0 +1,159 @@
+/*
+  $NiH: fread.c,v 1.6 2006/02/21 10:21:25 dillo Exp $
+
+  fread.c -- test cases for reading from zip archives
+  Copyright (C) 2004, 2005, 2006 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "zip.h"
+
+enum when {
+    WHEN_NEVER, WHEN_OPEN, WHEN_READ, WHEN_CLOSE
+};
+
+const char *when_name[] = {
+    "no", "zip_fopen", "zip_fread", "zip_fclose"
+};
+
+int do_read(struct zip *, const char *, int, enum when, int, int);
+
+
+
+const char *prg;
+
+int
+main(int argc, char *argv[])
+{
+    int fail, ze;
+    struct zip *z;
+    struct zip_source *zs;
+    char *archive;
+    char errstr[1024];
+
+    fail = 0;
+
+    prg = argv[0];
+
+    if (argc != 2) {
+        fprintf(stderr, "usage: %s archive\n", prg);
+        return 1;
+    }
+
+    archive = argv[1];
+
+    if ((z=zip_open(archive, 0, &ze)) == NULL) {
+	zip_error_to_str(errstr, sizeof(errstr), ze, errno);
+	printf("%s: opening zip archive ``%s'' failed: %s\n",
+	       prg, archive, errstr);
+	return 1;
+    }
+
+    fail += do_read(z, "storedok", 0, WHEN_NEVER, 0, 0);
+    fail += do_read(z, "deflateok", 0, WHEN_NEVER, 0, 0);
+    fail += do_read(z, "storedcrcerror", 0, WHEN_READ, ZIP_ER_CRC, 0);
+    fail += do_read(z, "deflatecrcerror", 0, WHEN_READ, ZIP_ER_CRC, 0);
+    fail += do_read(z, "deflatezliberror", 0, WHEN_READ, ZIP_ER_ZLIB, -3);
+    fail += do_read(z, NULL, 0, WHEN_OPEN, ZIP_ER_INVAL, 0);
+    fail += do_read(z, "nosuchfile", 0, WHEN_OPEN, ZIP_ER_NOENT, 0);
+    fail += do_read(z, "deflatezliberror", ZIP_FL_COMPRESSED, WHEN_NEVER, 0,0);
+    fail += do_read(z, "deflatecrcerror", ZIP_FL_COMPRESSED, WHEN_NEVER, 0, 0);
+    fail += do_read(z, "storedcrcerror", ZIP_FL_COMPRESSED,
+		    WHEN_READ, ZIP_ER_CRC, 0);
+    fail += do_read(z, "storedok", ZIP_FL_COMPRESSED, WHEN_NEVER, 0, 0);
+
+    zs = zip_source_buffer(z, "asdf", 4, 0);
+    zip_replace(z, zip_name_locate(z, "storedok", 0), zs);
+    fail += do_read(z, "storedok", 0, WHEN_OPEN, ZIP_ER_CHANGED, 0);
+    fail += do_read(z, "storedok", ZIP_FL_UNCHANGED, WHEN_NEVER, 0, 0);
+    zip_delete(z, zip_name_locate(z, "storedok", 0));
+    fail += do_read(z, "storedok", 0, WHEN_OPEN, ZIP_ER_NOENT, 0);
+    fail += do_read(z, "storedok", ZIP_FL_UNCHANGED, WHEN_NEVER, 0, 0);
+    zs = zip_source_buffer(z, "asdf", 4, 0);
+    zip_add(z, "new_file", zs);
+    fail += do_read(z, "new_file", 0, WHEN_OPEN, ZIP_ER_CHANGED, 0);
+    zip_unchange_all(z);
+
+    exit(fail ? 1 : 0);
+}
+
+
+
+int
+do_read(struct zip *z, const char *name, int flags,
+	enum when when_ex, int ze_ex, int se_ex)
+{
+    struct zip_file *zf;
+    enum when when_got;
+    int ze_got, se_got;
+    char b[8192];
+    int n;
+    char expected[80];
+    char got[80];
+
+    when_got = WHEN_NEVER;
+    ze_got = se_got = 0;
+    
+    if ((zf=zip_fopen(z, name, flags)) == NULL) {
+	when_got = WHEN_OPEN;
+	zip_error_get(z, &ze_got, &se_got);
+    }
+    else {
+	while ((n=zip_fread(zf, b, sizeof(b))) > 0)
+	    ;
+	if (n < 0) {
+	    when_got = WHEN_READ;
+	    zip_file_error_get(zf, &ze_got, &se_got);
+	}
+	n = zip_fclose(zf);
+	if (when_got == WHEN_NEVER && n != 0) {
+	    when_got = WHEN_CLOSE;
+	    ze_got = n;
+	    se_got = 0;
+	}
+    }
+
+    if (when_got != when_ex || ze_got != ze_ex || se_got != se_ex) {
+	zip_error_to_str(expected, sizeof(expected), ze_ex, se_ex);
+	zip_error_to_str(got, sizeof(got), ze_got, se_got);
+	printf("%s: got %s error (%s), expected %s error (%s)\n", prg,
+	       when_name[when_got], got, 
+	       when_name[when_ex], expected);
+	return 1;
+    }
+
+    return 0;
+}
diff --git a/regress/fread.test b/regress/fread.test
new file mode 100644
index 0000000..9fbe5d8
--- /dev/null
+++ b/regress/fread.test
@@ -0,0 +1,6 @@
+# various tests for zip_fread
+# $NiH: fread.test,v 1.1 2005/07/16 17:14:32 wiz Exp $
+program fread
+args broken.zip
+return 0
+file broken.zip broken.zip broken.zip
diff --git a/regress/get_comment.c b/regress/get_comment.c
new file mode 100644
index 0000000..8360eb9
--- /dev/null
+++ b/regress/get_comment.c
@@ -0,0 +1,91 @@
+/*
+  $NiH: get_comment.c,v 1.3 2006/04/23 14:17:36 wiz Exp $
+
+  comment.c -- test cases for file and archive comments
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zip.h"
+
+const char *prg;
+
+int
+main(int argc, char *argv[])
+{
+    const char *archive;
+    struct zip *za;
+    char buf[100];
+    int err;
+    const char *com;
+    int i, len;
+
+    prg = argv[0];
+
+    if (argc != 2) {
+	fprintf(stderr, "usage: %s archive\n", prg);
+	return 1;
+    }
+
+    archive = argv[1];
+    
+    if ((za=zip_open(archive, 0, &err)) == NULL) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr,"%s: can't open zip archive `%s': %s\n", prg,
+		archive, buf);
+	return 1;
+    }
+
+    if ((com=zip_get_archive_comment(za, &len, 0)) == NULL)
+	printf("No archive comment\n");
+    else
+	printf("Archive comment: %.*s\n", len, com);
+
+    for (i=0; i<zip_get_num_files(za); i++) {
+	if ((com=zip_get_file_comment(za, i, &len, 0)) == NULL)
+	    printf("No comment for `%s'\n", zip_get_name(za, i, 0));
+	else
+	    printf("File comment for `%s': %.*s\n", zip_get_name(za, i, 0), len, com);
+    }	
+
+    if (zip_close(za) == -1) {
+	fprintf(stderr,"%s: can't close zip archive `%s'\n", prg, archive);
+	return 1;
+    }
+
+    return 0;
+}
diff --git a/regress/get_comment.test b/regress/get_comment.test
new file mode 100644
index 0000000..e2cb829
--- /dev/null
+++ b/regress/get_comment.test
@@ -0,0 +1,16 @@
+# show comments of a zip archive
+# $NiH: comment.test,v 1.1 2006/04/09 19:05:48 wiz Exp $
+program get_comment
+return 0
+args testcomment.zip
+file testcomment.zip testcomment.zip testcomment.zip
+stdout Archive comment: This is the archive comment for the file.

+stdout 

+stdout Long.

+stdout 

+stdout Longer.

+stdout 
+stdout No comment for `file1'
+stdout File comment for `file2': First one had no comment.
+stdout File comment for `file3': Third one.
+stdout File comment for `file4': Last.
diff --git a/lib/zip_error_str.c b/regress/mkname.c
similarity index 67%
copy from lib/zip_error_str.c
copy to regress/mkname.c
index a22a673..b263f58 100644
--- a/lib/zip_error_str.c
+++ b/regress/mkname.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_error_str.c,v 1.1 2003/10/06 02:50:05 dillo Exp $
+  $NiH: mkname.c,v 1.1 2005/06/09 18:49:38 dillo Exp $
 
-  zip_error_str.c -- get string representation of zip error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  mkname.c -- add srcdir to name
+  Copyright (C) 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -35,39 +35,47 @@
 
 
 
-#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "zip.h"
-#include "zipint.h"
+#include "mkname.h"
 
 
 
-int
-zip_error_str(char *buf, size_t len, int ze, int se)
+const char *
+mkname(const char *name)
 {
-    const char *zs, *ss;
+    static const char *srcdir;
+    static char *fullname;
+    static int len = 0;
+    static int srcdir_done = 0;
 
-    if (ze < 0 || ze >= _zip_nerr_str)
-	return snprintf(buf, len, "Unknown error %d", ze);
+    int nlen;
 
-    zs = _zip_err_str[ze];
-	
-    switch (_zip_err_type[ze]) {
-    case ZIP_ET_SYS:
-	ss = strerror(se);
-	break;
-	
-    case ZIP_ET_ZIP:
-	ss = zError(se);
-	break;
-	
-    default:
-	ss = NULL;
+    if (!srcdir_done) {
+	srcdir = getenv("SRCDIR");
+	srcdir_done = 1;
     }
 
-    return snprintf(buf, len, "%s%s%s",
-		    zs, (ss ? ": " : ""), (ss ? ss : ""));
+    if (!srcdir)
+	return name;
+
+    nlen = strlen(srcdir) + strlen(name) + 2;
+
+    if (nlen > len) {
+	if (len == 0)
+	    fullname = malloc(nlen);
+	else
+	    fullname = realloc(fullname, nlen);
+
+	if (fullname == NULL) {
+	    fprintf(stderr, "malloc failure\n");
+	    exit(2);
+	}
+    }
+
+    sprintf(fullname, "%s/%s", srcdir, name);
+
+    return fullname;
 }
diff --git a/regress/mkname.h b/regress/mkname.h
new file mode 100644
index 0000000..d85bde5
--- /dev/null
+++ b/regress/mkname.h
@@ -0,0 +1,5 @@
+#ifndef HAD_MKNAME_H
+
+const char *mkname(const char *);
+
+#endif /* mkname.h */
diff --git a/regress/name_locate.c b/regress/name_locate.c
new file mode 100644
index 0000000..a5596de
--- /dev/null
+++ b/regress/name_locate.c
@@ -0,0 +1,132 @@
+/*
+  $NiH: name_locate.c,v 1.6 2006/02/21 09:41:13 dillo Exp $
+
+  name_locate.c -- test cases for finding files in zip archives
+  Copyright (C) 2005-2006 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "zip.h"
+
+int find_fail(struct zip *, const char *, int, int);
+int find_success(struct zip *, const char *, int);
+
+const char *prg;
+
+
+
+int
+main(int argc, char *argv[])
+{
+    int fail, ze;
+    struct zip *z;
+    const char *archive;
+
+    fail = 0;
+    prg = argv[0];
+
+    if (argc != 2) {
+        fprintf(stderr, "usage: %s archive\n", prg);
+        return 1;
+    }
+
+    archive = argv[1];
+
+    if ((z=zip_open(archive, 0, &ze)) == NULL) {
+	printf("%s: opening zip archive ``%s'' failed (%d)\n", prg,
+	       archive, ze);
+	return 1;
+    }
+
+    fail += find_fail(z, "nosuchfile", 0, ZIP_ER_NOENT);
+    fail += find_success(z, "test", 0);
+    fail += find_fail(z, "TeSt", 0, ZIP_ER_NOENT);
+    fail += find_success(z, "TeSt", ZIP_FL_NOCASE);
+    fail += find_success(z, "testdir/test2", 0);
+    fail += find_success(z, "tesTdir/tESt2", ZIP_FL_NOCASE);
+    fail += find_fail(z, "testdir/test2", ZIP_FL_NODIR, ZIP_ER_NOENT);
+    fail += find_fail(z, "tesTdir/tESt2", ZIP_FL_NOCASE|ZIP_FL_NODIR,
+		      ZIP_ER_NOENT);
+    fail += find_fail(z, "test2", 0, ZIP_ER_NOENT);
+    fail += find_success(z, "test2", ZIP_FL_NODIR);
+    fail += find_success(z, "TeST2", ZIP_FL_NODIR|ZIP_FL_NOCASE);
+    zip_delete(z, 0);
+    fail += find_fail(z, "test", 0, ZIP_ER_NOENT);
+    fail += find_success(z, "test", ZIP_FL_UNCHANGED);
+    zip_unchange_all(z);
+    fail += find_success(z, "test", 0);
+
+    exit(fail ? 1 : 0);
+}
+
+
+
+int
+find_fail(struct zip *z, const char *name, int flags, int zerr)
+{
+    int ze, se;
+    char expected[80];
+
+    if (zip_name_locate(z, name, flags) < 0) {
+	zip_error_get(z, &ze, &se);
+	if (ze != zerr) {
+	    zip_error_to_str(expected, sizeof(expected), zerr, 0);
+	    printf("%s: unexpected error while looking for ``%s'': "
+		   "got ``%s'', expected ``%s''\n", prg, name,
+		   zip_strerror(z), expected);
+	    return 1;
+	}
+
+	return 0;
+    }
+
+    return 1;
+}
+
+
+
+int
+find_success(struct zip *z, const char *name, int flags)
+{
+
+    if (zip_name_locate(z, name, flags) < 0) {
+	printf("%s: unexpected error while looking for ``%s'': %s\n",
+	       prg, name, zip_strerror(z));
+	return 1;
+    }
+
+    return 0;
+}
diff --git a/regress/name_locate.test b/regress/name_locate.test
new file mode 100644
index 0000000..e664fd7
--- /dev/null
+++ b/regress/name_locate.test
@@ -0,0 +1,6 @@
+# various tests for zip_name_locate
+# $NiH: name_locate.test,v 1.1 2005/07/16 17:14:32 wiz Exp $
+program name_locate
+args test.zip
+return 0
+file test.zip test.zip test.zip
diff --git a/regress/open.c b/regress/open.c
index abf32fc..9a2b099 100644
--- a/regress/open.c
+++ b/regress/open.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: open.c,v 1.1 2003/10/06 16:36:00 dillo Exp $
+  $NiH: open.c,v 1.6 2005/07/16 17:14:32 wiz Exp $
 
   open.c -- test cases for opening zip archives
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 1999-2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -44,25 +44,37 @@
 int open_fail(const char *, int, const char *, int, int);
 int open_success(const char *, int, const char *, int);
 
+const char *prg;
 
 
 int
 main(int argc, char *argv[])
 {
     int fail;
+    const char *archive;
+    const char *nonarchive;
 
     fail = 0;
+    prg = argv[0];
+
+    if (argc != 3) {
+        fprintf(stderr, "usage: %s archive non-archive\n", prg);
+        return 1;
+    }
+
+    archive = argv[1];
+    nonarchive = argv[2];
 
     remove("nosuchfile");
-    fail += open_fail("nosuchfile", 0, "non-existing", ZERR_OPEN, ENOENT);
-    fail += open_fail("Makefile", 0, "non-zip", ZERR_NOZIP, 0);
-    fail += open_fail("test.zip", ZIP_EXCL, "existing-excl", ZERR_EXISTS, 0);
-    /* ZERR_OPEN */
-    /* ZERR_READ */
-    /* ZERR_SEEK */
-    /* ZERR_INCONS */
+    fail += open_fail("nosuchfile", 0, "non-existing", ZIP_ER_OPEN, ENOENT);
+    fail += open_fail(nonarchive, 0, "non-zip", ZIP_ER_NOZIP, 0);
+    fail += open_fail(archive, ZIP_EXCL, "existing-excl", ZIP_ER_EXISTS, 0);
+    /* ZIP_ER_OPEN */
+    /* ZIP_ER_READ */
+    /* ZIP_ER_SEEK */
+    /* ZIP_ER_INCONS */
 
-    fail += open_success("test.zip", 0, "existing", 1);
+    fail += open_success(archive, 0, "existing", 3);
     fail += open_success("nosuchfile", ZIP_CREATE, "new", 0);
 
     exit(fail ? 1 : 0);
@@ -79,13 +91,13 @@
     errno = 0;
 
     if ((z=zip_open(fname, flags, &ze)) != NULL) {
-	printf("fail: opening %s succeeded\n", desc);
+	printf("%s: opening %s succeeded\n", prg, desc);
 	zip_close(z);
 	return 1;
     }
     else if (ze != zerr || errno != serr) {
-	printf("fail: opening %s returned wrong error %d/%d, expected %d/%d\n",
-		desc, ze, errno, zerr, serr);
+	printf("%s: opening %s returned wrong error %d/%d, expected %d/%d\n",
+		prg, desc, ze, errno, zerr, serr);
 	return 1;
     }
 
@@ -101,7 +113,7 @@
     int ze, num;
 
     if ((z=zip_open(fname, flags, &ze)) == NULL) {
-	printf("fail: opening %s failed (%d)\n", desc, ze);
+	printf("%s: opening %s failed (%d)\n", prg, desc, ze);
 	return 1;
     }
 
@@ -109,8 +121,8 @@
     zip_close(z);
     
     if (num != nent) {
-	printf("fail: opening %s got wrong number of files %d, expected %d\n",
-		desc, num, nent);
+	printf("%s: opening %s got wrong number of files %d, expected %d\n",
+		prg, desc, num, nent);
 	return 1;
     }
 
diff --git a/regress/open.test b/regress/open.test
new file mode 100644
index 0000000..b843cd4
--- /dev/null
+++ b/regress/open.test
@@ -0,0 +1,7 @@
+# various tests for zip_open
+# $NiH: open.test,v 1.1 2005/07/16 17:14:32 wiz Exp $
+program open
+args test.zip Makefile.am
+return 0
+file test.zip test.zip test.zip
+file Makefile.am Makefile.am Makefile.am
diff --git a/regress/runtest b/regress/runtest
new file mode 100755
index 0000000..9a9629f
--- /dev/null
+++ b/regress/runtest
@@ -0,0 +1,358 @@
+#!/bin/sh
+
+#  $NiH: runtest,v 1.3 2006/04/23 00:38:20 wiz Exp $
+
+#  from ckmame:runtest,v 1.22 2005/12/27 09:41:51 dillo Exp
+#
+#  runtest -- run regression tests
+#  Copyright (C) 2002, 2003 Dieter Baron and Thomas Klausner
+#
+#  This file is part of libzip, a library to manipulate ZIP archives.
+#  The authors can be contacted at <nih@giga.or.at>
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# runtest TESTNAME
+#
+# files: 
+#   TESTNAME.test: test scenario
+#
+# test scenario:
+#    Lines beginning with # are comments.
+#
+#    The following commands are recognized; return and args must
+#    appear exactly once, the others are optional.
+#
+#	args ARGS
+#	    run program with command line arguments ARGS
+#	
+#	description TEXT
+#	    description of what test is for
+#
+#	file TEST IN OUT
+#	    copy file IN as TEST, compare against OUT after program run.
+#
+#	file-del TEST IN
+#	    copy file IN as TEST, check that it is removed by program.
+#
+#	file-new TEST OUT
+#	    check that file TEST is created by program and compare
+#	    against OUT.
+#
+#	mkdir MODE NAME
+#	    create directory NAME with permissions MODE.
+#
+#	program PRG
+#	    run PRG.
+#
+#	return RET
+#	    RET is the expected exit code
+#
+#	stderr TEXT
+#	    program is expected to produce the error message TEXT.  If
+#	    multiple stderr commands are used, the messages are
+#	    expected in the order given.
+#
+#	stdout TEXT
+#	    program is expected to print TEXT to stdout.  If multiple
+#	    stdout commands are used, the messages are expected in
+#	    the order given. 
+#   
+# exit status
+#	runtest uses the following exit codes:
+#	    0: test passed
+#	    1: test failed
+#	    2: other error
+#	   77: test was skipped
+# 
+# environment variables:
+#   VERBOSE: if set, be more verbose (e. g., output diffs)
+#   NOCLEANUP: if set, don't delete directory test is run in
+
+die() {
+	echo "$0: $*" >&2;
+	cleanup;
+	exit 2;
+}
+
+fail() {
+	if [ ! -z "${VERBOSE}" ]
+	then
+	    echo "${TEST} -- FAILED: $*";
+	fi;
+	cleanup;
+	exit 1;
+}
+
+skip() {
+	if [ ! -z "${VERBOSE}" ]
+	then
+		echo "${TEST} -- skipped: $*";
+	fi;
+	cleanup;
+	exit 77;
+}
+
+succeed() {
+	if [ ! -z "${VERBOSE}" ]
+	then
+		echo "${TEST} -- passed";
+	fi
+	cleanup;
+	exit 0;
+}
+
+cleanup() {
+	cd ..;
+	if [ -z "${NOCLEANUP}" ]
+	then
+		chmod -R u+rw ${DIR};
+		rm -r ${DIR};
+	fi
+}
+
+check_in_out_exists() {
+    if [ ! -f "$2" ]
+    then
+	fail "missing output file: '$2'"
+    elif [ ! -f "$1" ]
+    then
+	die "cannot find input file '$1'"
+    fi
+}
+
+checkdb() {
+    check_in_out_exists "$1" "$2"
+    out=`../dbdump "$2" | sort | diff ${DIFF_FLAGS} "$1" -`
+    if [ $? -ne 0 ]
+    then
+	if [ $VERBOSE ]
+	then
+	    echo "$out"
+	fi
+	fail "$3"
+    fi
+
+}
+
+checkfile() {
+    check_in_out_exists "$1" "$2"
+    out=`diff ${DIFF_FLAGS} "$1" "$2"`
+    if [ $? -ne 0 ]
+    then
+	if [ $VERBOSE ]
+	then
+	    echo "$out"
+	fi
+	fail "$3"
+    fi
+}
+
+checkzip() {
+    check_in_out_exists "$1" "$2"
+    # quiet CRC errors
+    ${ZIPCMP} -t ${ZIPCMP_FLAGS} "$1" "$2" 2>/dev/null
+    if [ $? -ne 0 ]
+    then
+	fail "$3"
+    fi
+}
+
+test_empty() {
+    if [ ! -z "$1" ]
+    then
+	die "directive $2 appeared twice in test file"
+    fi
+}
+
+test_set() {
+    if [ -z "$1" ]
+    then
+	die "required directive $2 missing in test file"
+    fi
+}
+
+copy_file() {
+    if [ ! -f "$1" ]
+    then
+	die "source file '$1' does not exist"
+    fi
+    dir=`dirname "$2"`
+    if [ ! -d "$dir" ]
+    then
+	mkdir -p "$dir"
+    fi
+    cp "$1" "$2"
+}
+
+# GNU sort behaves differently on locales other than C, breaking tests
+LC_ALL=C
+export LC_ALL
+
+testdir=$(dirname $1)
+TEST=$(echo $1 | sed -e s',.*/,,' -e 's/\.test$//')
+shift
+
+DIR=${TEST}.d$$
+# echo ${TEST}::${srcdir}::${testdir}
+if [ ! -z "${testdir}" ]
+then
+    srcdir=${testdir}
+else
+    if [ -z "${srcdir}" ]
+    then
+	srcdir=..
+    else
+	# XXX: fix for absolute srcdir?
+	srcdir=../${srcdir}
+    fi
+fi
+
+if [ -z "${ZIPCMP}" ]
+then
+    ZIPCMP=zipcmp
+else
+    if expr "${ZIPCMP}" : '[^/].*/' > /dev/null
+    then
+	ZIPCMP="../${ZIPCMP}"
+    fi
+fi
+
+if [ -z "${VERBOSE}" ]
+then
+    DIFF_FLAGS=''
+    ZIPCMP_FLAGS='-q'
+else
+    DIFF_FLAGS='-u'
+    ZIPCMP_FLAGS='-v'
+fi
+
+# XXX: set up trap to cleanup
+
+mkdir ${DIR} || ( die "cannot create test directory ${DIR}" )
+cd ${DIR} || ( die "cannot cd to test directory ${DIR}" )
+
+{
+
+RET=''
+ARGS=''
+FILES=''
+FILES_SHOULD=''
+DESCR=''
+
+touch stderr stdout
+
+while read cmd arg
+do
+  case $cmd in
+  \#*) ;;
+  args)
+    test_empty "${ARGS}" args
+    ARGS="$arg";;
+  description)
+    test_empty "${DESCR}" description
+    DESCR="$arg";;
+  file)
+    set $arg
+    copy_file "${srcdir}/$2" "$1"
+    FILES="${FILES} ${srcdir}/$3!$1";;
+  file-del)
+    set $arg
+    copy_file "${srcdir}/$2" "$1";;
+  file-new)
+    set $arg
+    FILES="${FILES} ${srcdir}/$2!$1";;
+  mkdir)
+    set $arg
+    mkdir "$2" && chmod "$1" "$2";;
+  program)
+    PROGRAM=../"$arg";;
+  return)
+    test_empty "${RET}" return
+    RET="$arg";;
+  stderr)
+    echo "${PROGRAM}: $arg" >> stderr;;
+  stdout)
+    echo "$arg" >> stdout;;
+  *)
+    die "unknown directive '$cmd'"
+  esac
+done
+
+test_set "${RET}" return
+test_set "${ARGS}" args
+
+if [ -z "${PROGRAM}" ]
+then
+    die no program to run given
+fi
+
+if [ ! -z "${SETUP_ONLY}" ]
+then
+    echo ${DIR}
+    exit 0
+fi
+
+if [ ! -z "${VERBOSE}" ]
+then
+	echo "${TEST}: ${DESCR}"
+	echo "running: ${PROGRAM} ${ARGS}"
+fi
+
+${PROGRAM} ${ARGS} > gotout 2> goterr
+ret=$?
+
+if [ $ret -ne ${RET} ]
+then
+    if [ ! -z "${VERBOSE}" ]
+    then
+	cat gotout
+	cat goterr
+    fi
+    fail "unexpected exit status: got $ret, expected ${RET}"
+fi
+
+FILES_SHOULD="${FILES_SHOULD} stderr stdout gotout goterr"
+
+checkfile stderr goterr "unexpected error output"
+checkfile stdout gotout "unexpected output"
+
+if [ ! -z "${FILES}" ]
+then
+    for fs in ${FILES}
+    do
+        set -- `echo ${fs} | tr '!' ' '`
+	FILES_SHOULD="${FILES_SHOULD} $2"
+	case "$2" in
+	*.db)
+	    checkdb "$1" "$2" "database $2 wrong";;
+	*.zip)
+	    checkzip "$1" "$2" "zip file $2 wrong";;
+	*)
+	    checkfile "$1" "$2" "file $2 wrong";;
+	esac 
+    done
+fi
+
+# check that no additional files exist
+echo gotfiles shouldfiles ${FILES_SHOULD} | tr ' ' '\012' | sort > shouldfiles
+touch gotfiles
+find . -type f -print | sed 's!^./!!' | sort > gotfiles
+
+checkfile shouldfiles gotfiles "unexpected/missing files"
+
+succeed
+
+} < ${srcdir}/${TEST}.test
diff --git a/regress/set_comment_all.c b/regress/set_comment_all.c
new file mode 100644
index 0000000..f3af10f
--- /dev/null
+++ b/regress/set_comment_all.c
@@ -0,0 +1,97 @@
+/*
+  $NiH: set_comment_all.c,v 1.2 2006/04/23 13:28:41 wiz Exp $
+
+  set_comment_all.c -- set global and file comments
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zip.h"
+
+const char *prg;
+const char *new_archive_comment="This is the new,\r\n"
+"multiline archive comment.\r\n"
+"Ain't it nice?";
+
+int
+main(int argc, char *argv[])
+{
+    const char *archive;
+    struct zip *za;
+    char buf[100];
+    int err;
+    int i;
+
+    prg = argv[0];
+
+    if (argc != 2) {
+	fprintf(stderr, "usage: %s archive\n", prg);
+	return 1;
+    }
+
+    archive = argv[1];
+    
+    if ((za=zip_open(archive, 0, &err)) == NULL) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr,"%s: can't open zip archive `%s': %s\n", prg,
+		archive, buf);
+	return 1;
+    }
+
+    if (zip_set_archive_comment(za, new_archive_comment,
+				strlen(new_archive_comment)) < 0) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr, "%s: zip_set_archive_comment failed: %s\n",
+		prg, buf);
+    }
+
+    for (i=0; i<zip_get_num_files(za); i++) {
+	snprintf(buf, sizeof(buf), "File comment no %d", i);
+	if (zip_set_file_comment(za, i, buf, strlen(buf)) < 0) {
+	    zip_error_to_str(buf, sizeof(buf), err, errno);
+	    fprintf(stderr, "%s: zip_set_file_comment on file %d failed: %s\n",
+		    prg, i, buf);
+	}
+    }
+
+    if (zip_close(za) == -1) {
+	fprintf(stderr,"%s: can't close zip archive `%s'\n", prg, archive);
+	return 1;
+    }
+
+    return 0;
+}
diff --git a/regress/set_comment_all.test b/regress/set_comment_all.test
new file mode 100644
index 0000000..a1b9c5c
--- /dev/null
+++ b/regress/set_comment_all.test
@@ -0,0 +1,8 @@
+# change local and global comments in a zip archive
+# $NiH: set_comment.test,v 1.1 2006/04/23 00:39:58 wiz Exp $
+program set_comment_all
+return 0
+# need filename extension != zip to avoid using zipcmp,
+# which doesn't look at comments
+args testcomment.reg
+file testcomment.reg testcomment.zip testchanged.zip
diff --git a/regress/set_comment_localonly.c b/regress/set_comment_localonly.c
new file mode 100644
index 0000000..c732378
--- /dev/null
+++ b/regress/set_comment_localonly.c
@@ -0,0 +1,93 @@
+/*
+  $NiH: set_comment_localonly.c,v 1.3 2006/04/23 13:28:41 wiz Exp $
+
+  set_comment_localonly.c -- set file comments
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zip.h"
+
+const char *prg;
+
+int
+main(int argc, char *argv[])
+{
+    const char *archive;
+    struct zip *za;
+    char buf[100];
+    int err;
+    int i;
+
+    prg = argv[0];
+
+    if (argc != 2) {
+	fprintf(stderr, "usage: %s archive\n", prg);
+	return 1;
+    }
+
+    archive = argv[1];
+    
+    if ((za=zip_open(archive, 0, &err)) == NULL) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr,"%s: can't open zip archive `%s': %s\n", prg,
+		archive, buf);
+	return 1;
+    }
+
+    for (i=0; i<zip_get_num_files(za); i++) {
+	snprintf(buf, sizeof(buf), "File comment no %d", i);
+	if (zip_set_file_comment(za, i, buf, strlen(buf)) < 0) {
+	    zip_error_to_str(buf, sizeof(buf), err, errno);
+	    fprintf(stderr, "%s: zip_set_file_comment on file %d failed: %s\n",
+		    prg, i, buf);
+	}
+    }
+    /* remove comment for third file */
+    if (zip_set_file_comment(za, 2, NULL, 0) < 0) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr, "%s: zip_set_file_comment on file %d failed: %s\n",
+		prg, i, buf);
+    }
+
+    if (zip_close(za) == -1) {
+	fprintf(stderr,"%s: can't close zip archive `%s'\n", prg, archive);
+	return 1;
+    }
+
+    return 0;
+}
diff --git a/regress/set_comment_localonly.test b/regress/set_comment_localonly.test
new file mode 100644
index 0000000..269f9c9
--- /dev/null
+++ b/regress/set_comment_localonly.test
@@ -0,0 +1,8 @@
+# change local comments in a zip archive
+# $NiH: set_comment.test,v 1.1 2006/04/23 00:39:58 wiz Exp $
+program set_comment_localonly
+return 0
+# need filename extension != zip to avoid using zipcmp,
+# which doesn't look at comments
+args testcomment.reg
+file testcomment.reg testcomment.zip testchangedlocal.zip
diff --git a/lib/zip_error_str.c b/regress/set_comment_removeglobal.c
similarity index 63%
copy from lib/zip_error_str.c
copy to regress/set_comment_removeglobal.c
index a22a673..9b850a9 100644
--- a/lib/zip_error_str.c
+++ b/regress/set_comment_removeglobal.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zip_error_str.c,v 1.1 2003/10/06 02:50:05 dillo Exp $
+  $NiH: set_comment_removeglobal.c,v 1.1 2006/04/23 13:28:31 wiz Exp $
 
-  zip_error_str.c -- get string representation of zip error code
-  Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
+  set_comment_removeglobal.c -- remove archive comment
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -41,33 +41,43 @@
 #include <string.h>
 
 #include "zip.h"
-#include "zipint.h"
 
-
+const char *prg;
 
 int
-zip_error_str(char *buf, size_t len, int ze, int se)
+main(int argc, char *argv[])
 {
-    const char *zs, *ss;
+    const char *archive;
+    struct zip *za;
+    char buf[100];
+    int err;
 
-    if (ze < 0 || ze >= _zip_nerr_str)
-	return snprintf(buf, len, "Unknown error %d", ze);
+    prg = argv[0];
 
-    zs = _zip_err_str[ze];
-	
-    switch (_zip_err_type[ze]) {
-    case ZIP_ET_SYS:
-	ss = strerror(se);
-	break;
-	
-    case ZIP_ET_ZIP:
-	ss = zError(se);
-	break;
-	
-    default:
-	ss = NULL;
+    if (argc != 2) {
+	fprintf(stderr, "usage: %s archive\n", prg);
+	return 1;
     }
 
-    return snprintf(buf, len, "%s%s%s",
-		    zs, (ss ? ": " : ""), (ss ? ss : ""));
+    archive = argv[1];
+    
+    if ((za=zip_open(archive, 0, &err)) == NULL) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr,"%s: can't open zip archive `%s': %s\n", prg,
+		archive, buf);
+	return 1;
+    }
+
+    if (zip_set_archive_comment(za, NULL, 0) < 0) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr, "%s: zip_set_archive_comment failed: %s\n",
+		prg, buf);
+    }
+
+    if (zip_close(za) == -1) {
+	fprintf(stderr,"%s: can't close zip archive `%s'\n", prg, archive);
+	return 1;
+    }
+
+    return 0;
 }
diff --git a/regress/set_comment_removeglobal.test b/regress/set_comment_removeglobal.test
new file mode 100644
index 0000000..091fa70
--- /dev/null
+++ b/regress/set_comment_removeglobal.test
@@ -0,0 +1,8 @@
+# remove archive comment
+# $NiH: set_comment_revert.test,v 1.1 2006/04/23 13:21:19 wiz Exp $
+program set_comment_removeglobal
+return 0
+# need filename extension != zip to avoid using zipcmp,
+# which doesn't look at comments
+args testcomment.reg
+file testcomment.reg testcomment.zip testcommentremoved.zip
diff --git a/regress/set_comment_revert.c b/regress/set_comment_revert.c
new file mode 100644
index 0000000..5cdb88d
--- /dev/null
+++ b/regress/set_comment_revert.c
@@ -0,0 +1,102 @@
+/*
+  $NiH: set_comment_revert.c,v 1.2 2006/04/23 13:28:41 wiz Exp $
+
+  set_comment_revert.c -- set global and file comments, but revert
+  Copyright (C) 2006 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "zip.h"
+
+const char *prg;
+const char *new_archive_comment="This is the new,\r\n"
+"multiline archive comment.\r\n"
+"Ain't it nice?";
+
+int
+main(int argc, char *argv[])
+{
+    const char *archive;
+    struct zip *za;
+    char buf[100];
+    int err;
+    int i;
+
+    prg = argv[0];
+
+    if (argc != 2) {
+	fprintf(stderr, "usage: %s archive\n", prg);
+	return 1;
+    }
+
+    archive = argv[1];
+    
+    if ((za=zip_open(archive, 0, &err)) == NULL) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr,"%s: can't open zip archive `%s': %s\n", prg,
+		archive, buf);
+	return 1;
+    }
+
+    if (zip_set_archive_comment(za, new_archive_comment,
+				strlen(new_archive_comment)) < 0) {
+	zip_error_to_str(buf, sizeof(buf), err, errno);
+	fprintf(stderr, "%s: zip_set_archive_comment failed: %s\n",
+		prg, buf);
+    }
+
+    for (i=0; i<zip_get_num_files(za); i++) {
+	snprintf(buf, sizeof(buf), "File comment no %d", i);
+	if (zip_set_file_comment(za, i, buf, strlen(buf)) < 0) {
+	    zip_error_to_str(buf, sizeof(buf), err, errno);
+	    fprintf(stderr, "%s: zip_set_file_comment on file %d failed: %s\n",
+		    prg, i, buf);
+	}
+    }
+
+    if (zip_unchange_all(za) == -1) {
+	fprintf(stderr,"%s: can't revert changes to archive `%s'\n", prg, archive);
+	return 1;
+    }
+
+    if (zip_close(za) == -1) {
+	fprintf(stderr,"%s: can't close zip archive `%s'\n", prg, archive);
+	return 1;
+    }
+
+    return 0;
+}
diff --git a/regress/set_comment_revert.test b/regress/set_comment_revert.test
new file mode 100644
index 0000000..2d83f0c
--- /dev/null
+++ b/regress/set_comment_revert.test
@@ -0,0 +1,8 @@
+# start changing local and global comments, but revert before closing
+# $NiH: set_comment_all.test,v 1.1 2006/04/23 12:25:00 wiz Exp $
+program set_comment_revert
+return 0
+# need filename extension != zip to avoid using zipcmp,
+# which doesn't look at comments
+args testcomment.reg
+file testcomment.reg testcomment.zip testcomment.zip
diff --git a/regress/test.zip b/regress/test.zip
index 69ff08a..e4efd71 100644
--- a/regress/test.zip
+++ b/regress/test.zip
Binary files differ
diff --git a/regress/testbuffer.zip b/regress/testbuffer.zip
new file mode 100644
index 0000000..e474989
--- /dev/null
+++ b/regress/testbuffer.zip
Binary files differ
diff --git a/regress/testchanged.zip b/regress/testchanged.zip
new file mode 100644
index 0000000..d5169c9
--- /dev/null
+++ b/regress/testchanged.zip
Binary files differ
diff --git a/regress/testchangedlocal.zip b/regress/testchangedlocal.zip
new file mode 100644
index 0000000..1c8b301
--- /dev/null
+++ b/regress/testchangedlocal.zip
Binary files differ
diff --git a/regress/testcomment.zip b/regress/testcomment.zip
new file mode 100644
index 0000000..45dc18d
--- /dev/null
+++ b/regress/testcomment.zip
Binary files differ
diff --git a/regress/testcommentremoved.zip b/regress/testcommentremoved.zip
new file mode 100644
index 0000000..b2e4d05
--- /dev/null
+++ b/regress/testcommentremoved.zip
Binary files differ
diff --git a/regress/testfile.txt b/regress/testfile.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/regress/testfile.txt
diff --git a/regress/testfile.zip b/regress/testfile.zip
new file mode 100644
index 0000000..b46d298
--- /dev/null
+++ b/regress/testfile.zip
Binary files differ
diff --git a/regress/ziptest.c b/regress/ziptest.c
index a60ab70..7d37be5 100644
--- a/regress/ziptest.c
+++ b/regress/ziptest.c
@@ -8,10 +8,10 @@
 #if 0
     int i;
 #endif
-    struct zip *zf, *destzf;
+    struct zip *za, *destza;
 #if 0
 #define BUFSIZE 65536
-    struct zip_file *zff1, *zff2;
+    struct zip_file *zf1, *zf2;
     char buf1[BUFSIZE], buf2[BUFSIZE];
 #endif
     
@@ -27,69 +27,69 @@
 	return 1;
     }
 
-    if ((zf=zip_open(argv[1], ZIP_CHECKCONS))==NULL) {
+    if ((za=zip_open(argv[1], ZIP_CHECKCONS))==NULL) {
 	fprintf(stderr, "%s: %s: can't open file: %s\n", argv[0], argv[1],
 		zip_err_str[zip_err]);
 	return 1;
     }
 
-    if ((destzf=zip_open(argv[2], ZIP_CREATE))==NULL) {
+    if ((destza=zip_open(argv[2], ZIP_CREATE))==NULL) {
 	fprintf(stderr, "%s: %s: can't open file: %s\n", argv[0], argv[2],
 		zip_err_str[zip_err]);
 	return 1;
     }
 
 #if 0
-    for (i=0; i<zf->nentry; i++) {
-	printf("%8d %s\n", zf->entry[i].uncomp_size, zf->entry[i].fn);
-	zip_add_zip(destzf, zf->entry[i].fn, zf, i, 0, 0);
+    for (i=0; i<za->nentry; i++) {
+	printf("%8d %s\n", za->entry[i].uncomp_size, za->entry[i].fn);
+	zip_add_zip(destza, za->entry[i].fn, za, i, 0, 0);
     }
 #endif
 
-    if (zip_add_zip(destzf, NULL, NULL, zf, 0, 0, 0) == -1)
+    if (zip_add_zip(destza, NULL, NULL, za, 0, 0, 0) == -1)
 	fprintf(stderr, "%s: %s: can't add file to zip '%s': %s\n", argv[0],
-		zf->entry[0].fn, argv[1], zip_err_str[zip_err]);
+		za->entry[0].fn, argv[1], zip_err_str[zip_err]);
 
 #if 0
-    zff1= zff_open_index(zf, 1);
-    if (!zff1) {
+    zf1= zf_open_index(za, 1);
+    if (!zf1) {
 	fprintf(stderr, "boese, boese\n");
 	exit(100);
     }
     
-    i = zff_read(zff1, buf1, 100);
+    i = zf_read(zf1, buf1, 100);
     if (i < 0)
-	fprintf(stderr, "read error: %s\n", zip_err_str[zff1->flags]);
+	fprintf(stderr, "read error: %s\n", zip_err_str[zf1->flags]);
     else {
 	buf1[i] = 0;
 	printf("read %d bytes: '%s'\n", i, buf1);
     }
-    zff2 = zff_open_index(zf, 1);
-    i = zff_read(zff2, buf2, 200);
+    zf2 = zf_open_index(za, 1);
+    i = zf_read(zf2, buf2, 200);
     if (i < 0)
-	fprintf(stderr, "read error: %s\n", zip_err_str[zff2->flags]);
+	fprintf(stderr, "read error: %s\n", zip_err_str[zf2->flags]);
     else {
 	buf2[i] = 0;
 	printf("read %d bytes: '%s'\n", i, buf2);
     }
-    i = zff_read(zff1, buf1, 100);
+    i = zf_read(zf1, buf1, 100);
     if (i < 0)
-	fprintf(stderr, "read error: %s\n", zip_err_str[zff1->flags]);
+	fprintf(stderr, "read error: %s\n", zip_err_str[zf1->flags]);
     else {
 	buf1[i] = 0;
 	printf("read %d bytes: '%s'\n", i, buf1);
     }
-    zff_close(zff1);
-    zff_close(zff2);
+    zf_close(zf1);
+    zf_close(zf2);
 #endif
     
-    if (zip_close(destzf)!=0) {
+    if (zip_close(destza)!=0) {
 	fprintf(stderr, "%s: %s: can't close file: %s\n", argv[0], argv[2],
 		zip_err_str[zip_err]);
 	return 1;
     }
 
-    if (zip_close(zf)!=0) {
+    if (zip_close(za)!=0) {
 	fprintf(stderr, "%s: %s: can't close file: %s\n", argv[0], argv[1],
 		zip_err_str[zip_err]);
 	return 1;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..c5b76a4
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,10 @@
+# $NiH$
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../lib
+  ${CMAKE_CURRENT_BINARY_DIR}/..)
+
+ADD_EXECUTABLE(zipcmp zipcmp.c)
+TARGET_LINK_LIBRARIES(zipcmp zip)
+
+ADD_EXECUTABLE(zipmerge zipmerge.c)
+TARGET_LINK_LIBRARIES(zipmerge zip)
diff --git a/src/Makefile.am b/src/Makefile.am
index acdaf4b..3235bde 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,8 @@
-bin_PROGRAMS=zipcmp
+bin_PROGRAMS=zipcmp zipmerge
 
 zipcmp_CPPFLAGS=-I${top_srcdir}/lib
-zipcmp_LDADD=../lib/libzip.la
+zipcmp_LDADD=${top_builddir}/lib/libzip.la
+zipmerge_CPPFLAGS=-I${top_srcdir}/lib
+zipmerge_LDADD=${top_builddir}/lib/libzip.la
+
+EXTRA_DIST=	CMakeLists.txt
diff --git a/src/zipcmp.c b/src/zipcmp.c
index 1cf1845..c23aedc 100644
--- a/src/zipcmp.c
+++ b/src/zipcmp.c
@@ -1,8 +1,8 @@
 /*
-  $NiH: zipcmp.c,v 1.7.2.1 2004/04/13 19:48:36 dillo Exp $
+  $NiH: zipcmp.c,v 1.20 2006/04/23 18:47:34 dillo Exp $
 
   zipcmp.c -- compare zip files
-  Copyright (C) 2003 Dieter Baron and Thomas Klausner
+  Copyright (C) 2003, 2004, 2005 Dieter Baron and Thomas Klausner
 
   This file is part of libzip, a library to manipulate ZIP archives.
   The authors can be contacted at <nih@giga.or.at>
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <zlib.h>
 
 #include "config.h"
 #include "zip.h"
@@ -52,11 +53,14 @@
 
 
 
-char *prg;
+const char *prg;
 
-char *usage = "usage: %s [-hViqtv] zip1 zip2\n";
+#define PROGRAM	"zipmerge"
 
-char help_head[] = PACKAGE " by Dieter Baron and Thomas Klausner\n\n";
+char *usage = "usage: %s [-hiqtVv] zip1 zip2\n";
+
+char help_head[] =
+    PROGRAM " (" PACKAGE ") by Dieter Baron and Thomas Klausner\n\n";
 
 char help[] = "\n\
   -h       display this help message\n\
@@ -68,7 +72,7 @@
 \n\
 Report bugs to <nih@giga.or.at>.\n";
 
-char version_string[] = PACKAGE " " VERSION "\n\
+char version_string[] = PROGRAM " (" PACKAGE " " VERSION ")\n\
 Copyright (C) 2003 Dieter Baron and Thomas Klausner\n\
 " PACKAGE " comes with ABSOLUTELY NO WARRANTY, to the extent permitted by law.\n\
 You may redistribute copies of\n\
@@ -81,19 +85,19 @@
 
 static int entry_cmp(const void *p1, const void *p2);
 static void entry_print(const void *p);
-static int compare_list(const char *name[], int verbose,
+static int compare_list(char * const name[], int verbose,
 		 const void *l[], const int n[], int size,
 		 int (*cmp)(const void *, const void *),
 		 void print(const void *));
-static int compare_zip(const char *zn[], int verbose);
-static int test_file(struct zip *z, int idx, off_t size, unsigned int crc);
+static int compare_zip(char * const zn[], int verbose);
+static int test_file(struct zip *za, int idx, off_t size, unsigned int crc);
 
 int ignore_case, test_files;
 
 
 
 int
-main(int argc, char *argv[])
+main(int argc, char * const argv[])
 {
     int verbose;
     int c;
@@ -145,9 +149,9 @@
 
 
 static int
-compare_zip(const char *zn[], int verbose)
+compare_zip(char * const zn[], int verbose)
 {
-    struct zip *z;
+    struct zip *za;
     struct zip_stat st;
     struct entry *e[2];
     int n[2];
@@ -156,14 +160,14 @@
     char errstr[1024];
 
     for (i=0; i<2; i++) {
-	if ((z=zip_open(zn[i], ZIP_CHECKCONS, &err)) == NULL) {
-	    zip_error_str(errstr, sizeof(errstr), err, errno);
+	if ((za=zip_open(zn[i], 0, &err)) == NULL) {
+	    zip_error_to_str(errstr, sizeof(errstr), err, errno);
 	    fprintf(stderr, "%s: cannot open zip archive `%s': %s\n",
 		    prg, zn[i], errstr);
 	    return -1;
 	}
 
-	n[i] = zip_get_num_files(z);
+	n[i] = zip_get_num_files(za);
 
 	if ((e[i]=malloc(sizeof(*e[i]) * n[i])) == NULL) {
 	    fprintf(stderr, "%s: malloc failure\n", prg);
@@ -171,21 +175,21 @@
 	}
 
 	for (j=0; j<n[i]; j++) {
-	    zip_stat_index(z, j, 0, &st);
+	    zip_stat_index(za, j, 0, &st);
 	    e[i][j].name = strdup(st.name);
 	    e[i][j].size = st.size;
 	    e[i][j].crc = st.crc;
 	    if (test_files)
-		test_file(z, j, st.size, st.crc);
+		test_file(za, j, st.size, st.crc);
 	}
 
-	zip_close(z);
+	zip_close(za);
 
 	qsort(e[i], n[i], sizeof(e[i][0]), entry_cmp);
     }
 
     switch (compare_list(zn, verbose,
-			 e, n, sizeof(e[i][0]),
+			 (void *)e, n, sizeof(e[i][0]),
 			 entry_cmp, entry_print)) {
     case 0:
 	exit(0);
@@ -196,12 +200,14 @@
     default:
 	exit(2);
     }
+
+    return 0;
 }
 
 
 
 static int
-compare_list(const char *name[2], int verbose,
+compare_list(char * const name[2], int verbose,
 	     const void *l[2], const int n[2], int size,
 	     int (*cmp)(const void *, const void *),
 	     void print(const void *))
@@ -209,13 +215,16 @@
     int i[2], j, c;
     int diff;
 
-#define INC(k)	(i[k]++, l[k]+=size)
-#define PRINT(k)	(((diff==0 && verbose)				    \
-			     ? printf("--- %s\n+++ %s\n", name[0], name[1]) \
-			     : 0),					    \
-			 (verbose ? (printf("%c ", (k)?'+':'-'),	    \
-				     print(l[k])) : 0),			    \
-			 diff = 1)
+#define INC(k)	(i[k]++, l[k]=((const char *)l[k])+size)
+#define PRINT(k)	do {						      \
+			    if (diff==0 && verbose)			      \
+			        printf("--- %s\n+++ %s\n", name[0], name[1]); \
+			    if (verbose) {				      \
+			        printf("%c ", (k)?'+':'-');		      \
+				print(l[k]);				      \
+			    }						      \
+			    diff = 1;					      \
+			} while (0)
 
     i[0] = i[1] = 0;
     diff = 0;
@@ -282,34 +291,35 @@
 
 
 static int
-test_file(struct zip *z, int idx, off_t size, unsigned int crc)
+test_file(struct zip *za, int idx, off_t size, unsigned int crc)
 {
-    struct zip_file *f;
+    struct zip_file *zf;
     char buf[8192];
-    int n, nsize, ncrc;
+    int n, nsize;
+    unsigned int ncrc;
     
-    if ((f=zip_fopen_index(z, idx, 0)) == NULL) {
+    if ((zf=zip_fopen_index(za, idx, 0)) == NULL) {
 	fprintf(stderr, "%s: cannot open file %d in archive: %s\n",
-		prg, idx, zip_strerror(z));
+		prg, idx, zip_strerror(za));
 	return -1;
     }
 
     ncrc = crc32(0, NULL, 0);
     nsize = 0;
     
-    while ((n=zip_fread(f, buf, sizeof(buf))) > 0) {
+    while ((n=zip_fread(zf, buf, sizeof(buf))) > 0) {
 	nsize += n;
-	ncrc = crc32(ncrc, buf, n);
+	ncrc = crc32(ncrc, (const Bytef *)buf, n);
     }
 
     if (n < 0) {
 	fprintf(stderr, "%s: error reading file %d in archive: %s\n",
-		prg, idx, zip_file_strerror(f));
-	zip_fclose(f);
+		prg, idx, zip_file_strerror(zf));
+	zip_fclose(zf);
 	return -1;
     }
 
-    zip_fclose(f);
+    zip_fclose(zf);
 
     if (nsize != size) {
 	/* XXX: proper printf identifier */
diff --git a/src/zipmerge.c b/src/zipmerge.c
new file mode 100644
index 0000000..8215546
--- /dev/null
+++ b/src/zipmerge.c
@@ -0,0 +1,285 @@
+/*
+  $NiH: zipmerge.c,v 1.12 2006/04/23 14:51:08 wiz Exp $
+
+  zipmerge.c -- merge zip archives
+  Copyright (C) 2004-2006 Dieter Baron and Thomas Klausner
+
+  This file is part of libzip, a library to manipulate ZIP archives.
+  The authors can be contacted at <nih@giga.or.at>
+
+  Redistribution and use in source and binary forms, with or without
+  modification, are permitted provided that the following conditions
+  are met:
+  1. Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+  2. Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+  3. The names of the authors may not be used to endorse or promote
+     products derived from this software without specific prior
+     written permission.
+ 
+  THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
+  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
+  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "config.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "zip.h"
+
+
+
+char *prg;
+
+#define PROGRAM	"zipmerge"
+
+char *usage = "usage: %s [-DhIiSsV] target-zip zip...\n";
+
+char help_head[] =
+    PROGRAM " (" PACKAGE ") by Dieter Baron and Thomas Klausner\n\n";
+
+char help[] = "\n\
+  -h       display this help message\n\
+  -V       display version number\n\
+  -D       ignore directory component in file names\n\
+  -I       ignore case in file names\n\
+  -i       ask before overwriting files\n\
+  -S       don't overwrite identical files\n\
+  -s       overwrite identical files without asking\n\
+\n\
+Report bugs to <nih@giga.or.at>.\n";
+
+char version_string[] = PROGRAM " (" PACKAGE " " VERSION ")\n\
+Copyright (C) 2003 Dieter Baron and Thomas Klausner\n\
+" PACKAGE " comes with ABSOLUTELY NO WARRANTY, to the extent permitted by law.\n\
+You may redistribute copies of\n\
+" PACKAGE " under the terms of the GNU General Public License.\n\
+For more information about these matters, see the files named COPYING.\n";
+
+#define OPTIONS "hVDiIsS"
+
+#define CONFIRM_ALL_YES		0x001
+#define CONFIRM_ALL_NO		0x002
+#define CONFIRM_SAME_YES	0x010
+#define CONFIRM_SAME_NO		0x020
+
+int confirm;
+int name_flags;
+
+static int confirm_replace(struct zip *, const char *, int,
+			   struct zip *, const char *, int);
+static int merge_zip(struct zip *za, const char *, const char *);
+
+
+
+int
+main(int argc, char *argv[])
+{
+    struct zip *za;
+    int c, err;
+    char errstr[1024], *tname;
+
+    prg = argv[0];
+
+    confirm = CONFIRM_ALL_YES;
+    name_flags = 0;
+
+    while ((c=getopt(argc, argv, OPTIONS)) != -1) {
+	switch (c) {
+	case 'D':
+	    name_flags |= ZIP_FL_NODIR;
+	    break;
+	case 'i':
+	    confirm &= ~CONFIRM_ALL_YES;
+	    break;
+	case 'I':
+	    name_flags |= ZIP_FL_NOCASE;
+	    break;
+	case 's':
+	    confirm &= ~CONFIRM_SAME_NO;
+	    confirm |= CONFIRM_SAME_YES;
+	    break;
+	case 'S':
+	    confirm &= ~CONFIRM_SAME_YES;
+	    confirm |= CONFIRM_SAME_NO;
+	    break;
+
+	case 'h':
+	    fputs(help_head, stdout);
+	    printf(usage, prg);
+	    fputs(help, stdout);
+	    exit(0);
+	case 'V':
+	    fputs(version_string, stdout);
+	    exit(0);
+
+	default:
+	    fprintf(stderr, usage, prg);
+	    exit(2);
+	}
+    }
+
+    if (argc < optind+2) {
+	fprintf(stderr, usage, prg);
+	exit(2);
+    }
+
+    tname = argv[optind++];
+    if ((za=zip_open(tname, ZIP_CREATE, &err)) == NULL) {
+	zip_error_to_str(errstr, sizeof(errstr), err, errno);
+	fprintf(stderr, "%s: cannot open zip archive `%s': %s\n",
+		prg, tname, errstr);
+	exit(1);
+    }
+
+    while (optind<argc) {
+	if (merge_zip(za, tname, argv[optind++]) < 0)
+	    exit(1);
+    }
+
+    if (zip_close(za) < 0) {
+	fprintf(stderr, "%s: cannot write zip archive `%s': %s\n",
+		prg, tname, zip_strerror(za));
+	exit(1);
+    }
+
+    exit(0);
+}
+
+
+
+static int
+confirm_replace(struct zip *za, const char *tname, int it,
+		struct zip *zs, const char *sname, int is)
+{
+    char line[1024];
+    struct zip_stat st, ss;
+
+    if (confirm & CONFIRM_ALL_YES)
+	return 1;
+    else if (confirm & CONFIRM_ALL_NO)
+	return 0;
+
+    if (zip_stat_index(za, it, ZIP_FL_UNCHANGED, &st) < 0) {
+	fprintf(stderr, "%s: cannot stat file %d in `%s': %s\n",
+		prg, it, tname, zip_strerror(za));
+	return -1;
+    }
+    if (zip_stat_index(zs, is, 0, &ss) < 0) {
+	fprintf(stderr, "%s: cannot stat file %d in `%s': %s\n",
+		prg, is, sname, zip_strerror(zs));
+	return -1;
+    }
+
+    if (st.size == ss.size && st.crc == ss.crc) {
+	if (confirm & CONFIRM_SAME_YES)
+	    return 1;
+	else if (confirm & CONFIRM_SAME_NO)
+	    return 0;
+    }
+
+    printf("replace `%s' (%llu / %08x) in `%s'\n"
+	   "   with `%s' (%llu / %08x) from `%s'? ",
+	   st.name, st.size, st.crc, tname,
+	   ss.name, ss.size, ss.crc, sname);
+    fflush(stdout);
+
+    if (fgets(line, sizeof(line), stdin) == NULL) {
+	fprintf(stderr, "%s: read error from stdin: %s\n",
+		prg, strerror(errno));
+	return -1;
+    }
+
+    if (tolower((unsigned char)line[0]) == 'y')
+	return 1;
+
+    return 0;
+}
+
+
+
+static int
+merge_zip(struct zip *za, const char *tname, const char *sname)
+{
+    struct zip *zs;
+    struct zip_source *source;
+    int i, idx, err;
+    char errstr[1024];
+    const char *fname;
+    
+    if ((zs=zip_open(sname, 0, &err)) == NULL) {
+	zip_error_to_str(errstr, sizeof(errstr), err, errno);
+	fprintf(stderr, "%s: cannot open zip archive `%s': %s\n",
+		prg, sname, errstr);
+	return -1;
+    }
+
+    for (i=0; i<zip_get_num_files(zs); i++) {
+	fname = zip_get_name(zs, i, 0);
+
+	if ((idx=zip_name_locate(za, fname, name_flags)) != -1) {
+	    switch (confirm_replace(za, tname, idx, zs, sname, i)) {
+	    case 0:
+		break;
+		
+	    case 1:
+		if ((source=zip_source_zip(za, zs, i, 0, 0, 0)) == NULL
+		    || zip_replace(za, idx, source) < 0) {
+		    zip_source_free(source);
+		    fprintf(stderr,
+			    "%s: cannot replace `%s' in `%s': %s\n",
+			    prg, fname, tname, zip_strerror(za));
+		    return -1;
+		}
+		break;
+
+	    case -1:
+		zip_close(zs);
+		return -1;
+		
+	    default:
+		fprintf(stderr,	"%s: internal error: "
+			"unexpected return code from confirm (%d)\n",
+			prg, err);
+		zip_close(zs);
+		return -1;
+	    }
+	}
+	else {
+	    if ((source=zip_source_zip(za, zs, i, 0, 0, 0)) == NULL
+		|| zip_add(za, fname, source) < 0) {
+		zip_source_free(source);
+		fprintf(stderr,
+			"%s: cannot add `%s' to `%s': %s\n",
+			prg, fname, tname, zip_strerror(za));
+		zip_close(zs);
+		return -1;
+	    }
+	}
+    }
+
+    zip_close(zs);
+    return 0;
+}