tar_extract_file(3)
π tar_extract_file(3) β C Library Calls, but make it make sense
okay bestie, buckle up, because this is the <libtar.h> glow-up you didn't know you needed. this whole page is about pulling files out of a tar archive, and there are like a million little functions doing it. no cap. π
β¨ 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 β the whole squad that extracts 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 little man page is documenting version 1.2 of libtar. periodt.
π DESCRIPTION π
so here's the tea β. tar_extract_file() is basically the main character of this whole page β it's the front-end that runs the show for all the other tar_extract_*() girlies. what it does is peek at the current tar header hanging out with the TAR handle t (and heads up: that handle has to be initialized first by calling th_read() β don't skip that step bestie) to figure out what kind of file that header is actually talking about. then it calls the right tar_extract_*() function to extract that specific type of file. it's giving delegator energy. π
tar_skip_regfile() is the "we're not doing that today" function β it skips right over the file content blocks and parks the file pointer exactly where the next tar header block is supposed to be. lowkey iconic. β
tar_set_file_perms() is the glow-up artist β¨ β it sets the attributes of the extracted file so they match the encoded values. that means the file's modification time, mode, owner, and group. and the thing is, tar_extract_file() calls this automatically for you, but if your app is out here calling the other tar_extract_*() functions directly, then you have to call tar_set_file_perms() manually if you want that behavior. yes, manually. i know. π
π RETURN VALUES π
on a successful completion, all the functions documented here return 0. yay! π
on failure, they return -1 and set errno to an appropriate value. sad girl hours. π
and the special one: tar_extract_dir() will return 1 if the directory already exists. (not an error, just a lil "been there, done that" π
)
π₯ ERRORS π₯
heads up bestie, error time. read carefully, this part matters.
tar_extract_file() will fail if:
EEXISTβ if theO_NOOVERWRITEflag is set and the file already exists. like, it's already here?? we're not touching it. π«
the tar_extract_*() functions will fail if:
EINVALβ an entry could not be added to the internal file hash.EINVALβ less thanT_BLOCKSIZEbytes were read from the tar archive.EINVALβ the current file header associated withtrefers to a kind of file other than the one which the called function knows about. (mismatch energy π)
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), write(2), link(2), symlink(2), mknod(2), mkfifo(2), utime(2), chown(2), lchown(2), chmod(2), lstat(2) β go read those too, iykyk π«Ά
and that's the whole page, bestie! this one's brought to you by the University of Illinois, dated Jan 2001 (yes, a vintage queen π), documenting tar_extract_file(3) in the C Library Calls lineup. mwah πβ¨
π¦ where this page comes from
- arch rolling: libtar 1.2.20-8 Β· BSD
- fedora 43: libtar-devel 1.2.20-34.fc43 Β· MIT
- fedora 43: libtar-devel 1.2.20-34.fc43 Β· MIT
- fedora 44: libtar-devel 1.2.20-35.fc44 Β· MIT
- fedora 44: libtar-devel 1.2.20-35.fc44 Β· MIT
- nixos 26.05: libtar 1.2.20
- nixpkgs unstable: libtar 1.2.20
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms