Instead of tar_open (& pTar, tarFilename, NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU);
Use the following: tar_open (& pTar, tarFilename, NULL, O_WRONLY | O_CREAT, 0644, TAR_IGNORE_MAGIC); Or tar_open (& pTar, tarFilename, NULL, O_WRONLY | O_CREAT, 0644, TAR_VERBOSE);
The reason may be: The size of "char magic [6]" is 6. Somewhere, the library is trying to copy 8 bytes to the magic, as shown below, if the option is TAR_GNU. Therefore, in this case, we must pass an option other than TAR_GNU.
if (t->options & TAR_GNU) strncpy(t->th_buf.magic, "ustar ", 8);
source share