---
name: "tar_extract_regfile"
section: "3"
platform: "linux"
package: "libtar"
version: "1.2.20-8"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/tar_extract_file"
---

# tar\_extract\_regfile(3)

extract files from a tar archive

Part of [tar\_extract\_file(3)](/tar_extract_file/3.md).

## NAME

tar\_extract\_file, tar\_extract\_regfile, tar\_extract\_hardlink, tar\_extract\_symlink, tar\_extract\_chardev, tar\_extract\_blockdev, tar\_extract\_dir, tar\_extract\_fifo, tar\_skip\_regfile, tar\_set\_file\_perms - extract files from a tar archive

## SYNOPSIS

**#include \<libtar.h\>**

**int tar\_extract\_file(TAR \****t***, char \****realname***);**

**int tar\_extract\_regfile(TAR \****t***, char \****realname***);**

**int tar\_skip\_regfile(TAR \****t***);**

**int tar\_extract\_dir(TAR \****t***, char \****realname***);**

**int tar\_extract\_hardlink(TAR \****t***, char \****realname***);**

**int tar\_extract\_symlink(TAR \****t***, char \****realname***);**

**int tar\_extract\_blockdev(TAR \****t***, char \****realname***);**

**int tar\_extract\_chardev(TAR \****t***, char \****realname***);**

**int tar\_extract\_fifo(TAR \****t***, char \****realname***);**

**int tar\_set\_file\_perms(TAR \****t***, char \****realname***);**

## VERSION

This man page documents version 1.2 of **libtar**.

## DESCRIPTION

The **tar\_extract\_file**() function acts as a front-end to the other **tar\_extract\_\***() functions.  It checks the current tar header associated with the *TAR* handle *t* (which must be initialized first by calling **th\_read**()) to determine what kind of file the header refers to.  It then calls the appropriate **tar\_extract\_\***() function to extract that kind of file.

The **tar\_skip\_regfile**() function skips over the file content blocks and positions the file pointer at the expected location of the next tar header block.

The **tar\_set\_file\_perms**() function sets the attributes of the extracted file to match the encoded values.  This includes the file's modification time, mode, owner, and group.  This function is automatically called by **tar\_extract\_file**(), but applications which call the other **tar\_extract\_\***() functions directly will need to call **tar\_set\_file\_perms**() manually if this behavior is desired.

## RETURN VALUES

On successful completion, the functions documented here will return 0.  On failure, they will return -1 and set *errno* to an appropriate value.

The **tar\_extract\_dir**() function will return 1 if the directory already exists.

## ERRORS

The **tar\_extract\_file**() function will fail if:

- **EEXIST**

  If the **O\_NOOVERWRITE** flag is set and the file already exists.

The **tar\_extract\_\***() functions will fail if:

- **EINVAL**

  An entry could not be added to the internal file hash.

- **EINVAL**

  Less than **T\_BLOCKSIZE** bytes were read from the tar archive.

- **EINVAL**

  The current file header associated with *t* refers to a kind of file other than the one which the called function knows about.

They may also fail if any of the following functions fail: **mkdir**(), **write**(), **link**(), **symlink**(), **mknod**(), **mkfifo**(), **utime**(), **chown**(), **lchown**(), **chmod**(), or **lstat**().

## SEE ALSO

[**mkdir**(2)](/mkdir/2.md), [**write**(2)](/write/2.md), [**link**(2)](/link/2.md), [**symlink**(2)](/symlink/2.md), [**mknod**(2)](/mknod/2.md), [**mkfifo**(2)](/mkfifo/2.md), [**utime**(2)](/utime/2.md), [**chown**(2)](/chown/2.md), [**lchown**(2)](/lchown/2.md), [**chmod**(2)](/chmod/2.md), [**lstat**(2)](/lstat/2.md)
