DOKK / manpages / debian 10 / libtar-dev / tar_open.3.en
tar_open(3) C Library Calls tar_open(3)

tar_open, tar_close - access a tar archive via a handle

#include <libtar.h>

int tar_open(TAR **t, char *pathname, tartype_t *type, int oflags, int mode, int options);

int tar_fdopen(TAR **t, int fd, char *pathname, tartype_t *type, int oflags, int mode, int options);

int tar_fd(TAR *t");"

int tar_close(TAR *t");"

This man page documents version 1.2 of libtar.

The tar_open() function opens a tar archive file corresponding to the filename named by the pathname argument. The oflags argument must be either O_RDONLY or O_WRONLY.

The type argument specifies the access methods for the given file type. The tartype_t structure has members named openfunc, closefunc, readfunc() and writefunc(), which are pointers to the functions for opening, closing, reading, and writing the file, respectively. If type is NULL, the file type defaults to a normal file, and the standard open(), close(), read(), and write() functions are used.

The options argument is a logical-or'ed combination of zero or more of the following:

Use GNU extensions.
Send status messages to stdout.
Do not overwrite pre-existing files.
Skip all-zero blocks instead of treating them as EOT.
Do not validate the magic field in file headers.
Check the version field in file headers. (This field is normally ignored.)
Do not validate the CRC of file headers.

The tar_open() function allocates memory for a TAR handle, and a pointer to the allocated memory is saved in the location specified by t. The TAR handle may be passed to other libtar calls to modify the opened tar archive. The TAR handle maintains all of the information about the open tar archive, including the archive type, options, and oflags selected when tar_open() was called.

The TAR handle generated by tar_open() contains a file header structure. When reading a tar archive, this structure contains the last file header read from the tar archive. When writing a tar archive, this structure is used as a staging area to construct the next file header to be written to the archive. In addition, the TAR handle contains a hash table which is used to keep track of the device and inode information for each file which gets written to the tar archive. This is used to detect hard links, so that files do not need to be duplicated in the archive.

The tar_fdopen() function is identical to the tar_open() function, except that fd is used as the previously-opened file descriptor for the tar file instead of calling type->openfunc() to open the file.

The tar_fd() function returns the file descriptor associated with the TAR handle t.

The tar_close() function closes the file descriptor associated with the TAR handle t and frees all dynamically-allocated memory.

The tar_open(), tar_fdopen(), and tar_close() functions return 0 on success. On failure, they return -1 and set errno.

The tar_fd() function returns the file descriptor associated with the TAR handle t.

tar_open() will fail if:

The oflags argument was something other than O_RDONLY or O_WRONLY.

In addition, tar_open() and tar_close() may fail if it cannot allocate memory using calloc(), or if the open or close functions for the specified tar archive type fail.

open(2), close(2), calloc(3)

Jan 2001 University of Illinois