tar_append_file(3)

✨ tar_append_file β€” bestie we're writing tar archives ✨

okay so this is a page from the C Library Calls section of the manual (that's section 3, iykyk πŸ’…). Three little functions, one big vibe: they append data to tar archives. Let's get into it 🫢


🌸 NAME 🌸

tar_append_file, tar_append_eof, tar_append_regfile β€” append data to tar archives πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

#include <libtar.h>

int tar_append_file(TAR *t, char *realname, char *savename);

int tar_append_regfile(TAR *t, char *realname);

int tar_append_eof(TAR *t);

πŸ¦‹ VERSION πŸ¦‹

This man page documents version 1.2 of libtar. no cap ✨


πŸ‘‘ DESCRIPTION πŸ‘‘

πŸ“ tar_append_file()

So tar_append_file() makes a whole tar file header block that describes the file named by the realname argument β€” but like, it stores it under the encoded filename of savename instead πŸ™ˆ (yes bestie, the name it lives under in the archive can be totally different from the name on disk, that's the whole point).

Then it sets the current header associated with the TAR handle t to that brand-new header block, and writes that block to the tar archive associated with t. slay.

And here's the cute little plot twist: if the file named by realname is a regular file (and it's not encoded as a hard link), then tar_append_file() will go ahead and call tar_append_regfile() to append the actual contents of the file. it's giving teamwork πŸ’–

🌈 tar_append_regfile()

tar_append_regfile() appends the contents of a regular file to the tar archive associated with t.

And since this function is called by tar_append_file() already, you only really need to call it yourself if your app is out here constructing and writing the tar file header all on its own. main character energy, honestly πŸ‘‘

⭐ tar_append_eof()

tar_append_eof() writes an EOF marker (two blocks of all zeros) to the tar file associated with t. that's it, that's the whole job, and it does it flawlessly periodt ✨


πŸ’œ RETURN VALUES πŸ’œ

On successful completion, these functions will return 0 πŸ₯³

On failure, they will return -1 and set errno to an appropriate value 😭


πŸ”₯ ERRORS πŸ”₯

The tar_append_*() functions will fail if:

  • EINVAL β€” Less than T_BLOCKSIZE bytes were written to the tar archive. πŸ’€
  • EINVAL β€” Less than T_BLOCKSIZE bytes were read from the realname file. πŸ’€

They may also fail if any of the following functions fail: lstat(), malloc(), open(), read(), th_write(), or the write function for the file type associated with the TAR handle t. so many ways for things to go sideways ngl πŸ™ˆ


🌸 SEE ALSO 🌸


and that's the whole page, bestie πŸ’– this one came from the University of Illinois, dated Jan 2001, and the page itself is tar_append_file(3) β€” and yup, we're still talking about version 1.2 of libtar ✨ go forth and append, you've got this πŸ«ΆπŸŽ€