]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Style cleanup and sketch out the switch from off_t to int64_t for
authorTim Kientzle <kientzle@gmail.com>
Wed, 29 Oct 2008 21:55:12 +0000 (17:55 -0400)
committerTim Kientzle <kientzle@gmail.com>
Wed, 29 Oct 2008 21:55:12 +0000 (17:55 -0400)
libarchive 3.0.  (Linux off_t isn't always the same size thanks to
the Large File System support in the system headers; it's a huge
headache using it in public headers for shared libraries.)
This is still a bit tentative; "long long" may be a more appropriate
choice here.

SVN-Revision: 233

libarchive/archive.h

index 34ba9d6d1545b28e7978d6078c2d652179927174..912b52d2ab02a6742cbf6a9b444bbe701e6734cb 100644 (file)
@@ -184,20 +184,37 @@ struct archive_entry;
  */
 
 /* Returns pointer and size of next block of data from archive. */
-typedef __LA_SSIZE_T   archive_read_callback(struct archive *, void *_client_data,
-                   const void **_buffer);
+typedef __LA_SSIZE_T   archive_read_callback(struct archive *,
+                           void *_client_data, const void **_buffer);
+
 /* Skips at most request bytes from archive and returns the skipped amount */
 #if ARCHIVE_VERSION_NUMBER < 2000000
-typedef __LA_SSIZE_T   archive_skip_callback(struct archive *, void *_client_data,
-                   size_t request);
+/* Libarchive 1.0 used ssize_t for the return, which is only 32 bits
+ * on most 32-bit platforms; not large enough. */
+typedef __LA_SSIZE_T   archive_skip_callback(struct archive *,
+                           void *_client_data, size_t request);
+#elif ARCHIVE_VERSION_NUMBER < 3000000
+/* Libarchive 2.0 used off_t here, but that is a bad idea on Linux and a
+ * few other platforms where off_t varies with build settings. */
+typedef off_t          archive_skip_callback(struct archive *,
+                           void *_client_data, off_t request);
 #else
-typedef off_t  archive_skip_callback(struct archive *, void *_client_data,
-                   off_t request);
+/* Libarchive 3.0 uses int64_t here, which is actually guaranteed to be
+ * 64 bits on every platform. */
+typedef __LA_INT64_T   archive_skip_callback(struct archive *,
+                           void *_client_data, __LA_INT64_T request);
 #endif
+
 /* Returns size actually written, zero on EOF, -1 on error. */
-typedef __LA_SSIZE_T   archive_write_callback(struct archive *, void *_client_data,
-                   const void *_buffer, size_t _length);
+typedef __LA_SSIZE_T   archive_write_callback(struct archive *,
+                           void *_client_data,
+                           const void *_buffer, size_t _length);
+
+#if ARCHIVE_VERSION_NUMBER < 3000000
+/* Open callback is actually never needed; remove it in libarchive 3.0. */
 typedef int    archive_open_callback(struct archive *, void *_client_data);
+#endif
+
 typedef int    archive_close_callback(struct archive *, void *_client_data);
 
 /*
@@ -334,15 +351,23 @@ __LA_DECL int              archive_read_next_header(struct archive *,
 __LA_DECL __LA_INT64_T          archive_read_header_position(struct archive *);
 
 /* Read data from the body of an entry.  Similar to read(2). */
-__LA_DECL __LA_SSIZE_T          archive_read_data(struct archive *, void *, size_t);
+__LA_DECL __LA_SSIZE_T          archive_read_data(struct archive *,
+                                   void *, size_t);
+
 /*
  * A zero-copy version of archive_read_data that also exposes the file offset
  * of each returned block.  Note that the client has no way to specify
  * the desired size of the block.  The API does guarantee that offsets will
  * be strictly increasing and that returned blocks will not overlap.
  */
+#if ARCHIVE_VERSION_NUMBER < 3000000
+__LA_DECL int           archive_read_data_block(struct archive *a,
+                           const void **buff, size_t *size, off_t *offset);
+#else
 __LA_DECL int           archive_read_data_block(struct archive *a,
-                   const void **buff, size_t *size, off_t *offset);
+                           const void **buff, size_t *size,
+                           __LA_INT64_T *offset);
+#endif
 
 /*-
  * Some convenience functions that are built on archive_read_data:
@@ -351,8 +376,8 @@ __LA_DECL int                archive_read_data_block(struct archive *a,
  *  'into_fd': writes data to specified filedes
  */
 __LA_DECL int           archive_read_data_skip(struct archive *);
-__LA_DECL int           archive_read_data_into_buffer(struct archive *, void *buffer,
-                    __LA_SSIZE_T len);
+__LA_DECL int           archive_read_data_into_buffer(struct archive *,
+                           void *buffer, __LA_SSIZE_T len);
 __LA_DECL int           archive_read_data_into_fd(struct archive *, int fd);
 
 /*-
@@ -415,12 +440,11 @@ __LA_DECL void            archive_read_extract_set_skip_file(struct archive *,
 __LA_DECL int           archive_read_close(struct archive *);
 /* Release all resources and destroy the object. */
 /* Note that archive_read_finish will call archive_read_close for you. */
-#if ARCHIVE_VERSION_NUMBER >= 2000000
-__LA_DECL int           archive_read_finish(struct archive *);
-#else
-/* Temporarily allow library to compile with either 1.x or 2.0 API. */
+#if ARCHIVE_VERSION_NUMBER < 2000000
 /* Erroneously declared to return void in libarchive 1.x */
 __LA_DECL void          archive_read_finish(struct archive *);
+#else
+__LA_DECL int           archive_read_finish(struct archive *);
 #endif
 
 /*-
@@ -492,22 +516,36 @@ __LA_DECL int              archive_write_open_memory(struct archive *,
  */
 __LA_DECL int           archive_write_header(struct archive *,
                     struct archive_entry *);
-#if ARCHIVE_VERSION_NUMBER >= 2000000
-__LA_DECL __LA_SSIZE_T          archive_write_data(struct archive *, const void *, size_t);
-#else
-/* Temporarily allow library to compile with either 1.x or 2.0 API. */
+#if ARCHIVE_VERSION_NUMBER < 2000000
 /* This was erroneously declared to return "int" in libarchive 1.x. */
-__LA_DECL int           archive_write_data(struct archive *, const void *, size_t);
+__LA_DECL int           archive_write_data(struct archive *,
+                           const void *, size_t);
+#else
+/* Libarchive 2.0 and later return ssize_t here. */
+__LA_DECL __LA_SSIZE_T  archive_write_data(struct archive *,
+                           const void *, size_t);
+#endif
+
+#if ARCHIVE_VERSION_NUMBER < 3000000
+/* Libarchive 1.x and 2.x use off_t for the argument, but that's not
+ * stable on Linux. */
+__LA_DECL __LA_SSIZE_T  archive_write_data_block(struct archive *,
+                                   const void *, size_t, off_t);
+#else
+/* Libarchive 3.0 uses explicit int64_t to ensure consistent 64-bit support. */
+__LA_DECL __LA_SSIZE_T  archive_write_data_block(struct archive *,
+                                   const void *, size_t, __LA_INT64_T);
 #endif
-__LA_DECL __LA_SSIZE_T          archive_write_data_block(struct archive *, const void *, size_t, off_t);
 __LA_DECL int           archive_write_finish_entry(struct archive *);
 __LA_DECL int           archive_write_close(struct archive *);
-#if ARCHIVE_VERSION_NUMBER >= 2000000
-__LA_DECL int           archive_write_finish(struct archive *);
-#else
-/* Temporarily allow library to compile with either 1.x or 2.0 API. */
+#if ARCHIVE_VERSION_NUMBER < 2000000
 /* Return value was incorrect in libarchive 1.x. */
 __LA_DECL void          archive_write_finish(struct archive *);
+#else
+/* Libarchive 2.x and later returns an error if this fails. */
+/* It can fail if the archive wasn't already closed, in which case
+ * archive_write_finish() will implicitly call archive_write_close(). */
+__LA_DECL int           archive_write_finish(struct archive *);
 #endif
 
 /*-