usando la biblioteca libtar en c

Estoy tratando de hacer un archivo tar usando c. Por una razón que no puedo usar

system("tar -cvf xxxx.tar xxxx");

mi código es:

#include <stdio.h>
#include <libtar.h>
#include <fcntl.h>

int main(void) {

        TAR *pTar;

        char *tarFilename = "file.tar";
        char *srcDir = "directory";

        char *extractTo = ".";
        tar_open(&pTar, tarFilename, NULL, O_WRONLY | O_CREAT, 0644, TAR_GNU);
        tar_append_tree(pTar, srcDir, extractTo);
        tar_close(pTar);
        return (0);

}

Después de ejecutar este código, cuando quiero untar con

tar -xvf file.tar

Recibo un error

tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

¿Cuál es el problema con mi código c?

Respuestas a la pregunta(3)

Su respuesta a la pregunta