Other Aliasarchive_write_open_fd, archive_write_open_FILE
LIBRARYStreaming Archive Library (libarchive, -larchive)
SYNOPSISIn archive.h Ft int Fo archive_write_open Fa struct archive * Fa void *client_data Fa archive_open_callback * Fa archive_write_callback * Fa archive_close_callback * Fc Ft int Fn archive_write_open_fd struct archive * int fd Ft int Fn archive_write_open_FILE struct archive * FILE *file Ft int Fn archive_write_open_filename struct archive * const char *filename Ft int Fo archive_write_open_memory Fa struct archive * Fa void *buffer Fa size_t bufferSize Fa size_t *outUsed Fc
- Fn archive_write_open
- Freeze the settings, open the archive, and prepare for writing entries. This is the most generic form of this function, which accepts pointers to three callback functions which will be invoked by the compression layer to write the constructed archive.
- Fn archive_write_open_fd
- A convenience form of Fn archive_write_open that accepts a file descriptor. The Fn archive_write_open_fd function is safe for use with tape drives or other block-oriented devices.
- Fn archive_write_open_FILE
- A convenience form of Fn archive_write_open that accepts a Ft FILE * pointer. Note that Fn archive_write_open_FILE is not safe for writing to tape drives or other devices that require correct blocking.
- Fn archive_write_open_file
- A deprecated synonym for Fn archive_write_open_filename .
- Fn archive_write_open_filename
- A convenience form of Fn archive_write_open that accepts a filename. A NULL argument indicates that the output should be written to standard output; an argument of ``-'' will open a file with that name. If you have not invoked Fn archive_write_set_bytes_in_last_block , then Fn archive_write_open_filename will adjust the last-block padding depending on the file: it will enable padding when writing to standard output or to a character or block device node, it will disable padding otherwise. You can override this by manually invoking Fn archive_write_set_bytes_in_last_block before calling Fn archive_write_open . The Fn archive_write_open_filename function is safe for use with tape drives or other block-oriented devices.
- Fn archive_write_open_memory
- A convenience form of Fn archive_write_open that accepts a pointer to a block of memory that will receive the archive. The final Ft size_t * argument points to a variable that will be updated after each write to reflect how much of the buffer is currently in use. You should be careful to ensure that this variable remains allocated until after the archive is closed.
More information about the struct archive object and the overall design of the library can be found in the libarchive(3) overview.
CLIENT CALLBACKSTo use this library, you will need to define and register callback functions that will be invoked to write data to the resulting archive. These functions are registered by calling Fn archive_write_open :
- Ft typedef int
- Fn archive_open_callback struct archive * void *client_data
The open callback is invoked by Fn archive_write_open . It should return ARCHIVE_OK if the underlying file or data source is successfully opened. If the open fails, it should call Fn archive_set_error to register an error code and message and return ARCHIVE_FATAL
- Ft typedef la_ssize_t
- Fo archive_write_callback Fa struct archive * Fa void *client_data Fa const void *buffer Fa size_t length Fc
The write callback is invoked whenever the library needs to write raw bytes to the archive. For correct blocking, each call to the write callback function should translate into a single write(2) system call. This is especially critical when writing archives to tape drives. On success, the write callback should return the number of bytes actually written. On error, the callback should invoke Fn archive_set_error to register an error code and message and return -1.
- Ft typedef int
- Fn archive_close_callback struct archive * void *client_data
The close callback is invoked by archive_close when the archive processing is complete. The callback should return ARCHIVE_OK on success. On failure, the callback should invoke Fn archive_set_error to register an error code and message and return ARCHIVE_FATAL.
Note that if the client-provided write callback function returns a non-zero value, that error will be propagated back to the caller through whatever API function resulted in that call, which may include Fn archive_write_header , Fn archive_write_data , Fn archive_write_close , Fn archive_write_finish , or Fn archive_write_free . The client callback can call Fn archive_set_error to provide values that can then be retrieved by Fn archive_errno and Fn archive_error_string .