- memset(&t->th_buf, 0, sizeof(struct tar_header));
-
- th_set_type(t, S_IFREG | 0600);
- th_set_user(t, 0);
- th_set_group(t, 0);
- th_set_mode(t, 0600);
- th_set_size(t, len);
- th_set_mtime(t, time(NULL));
- th_set_path(t, const_cast<char *>(path.c_str()));
- th_finish(t);
-
- if (th_write(t) != 0)
- throw IOException("Error writing tar header");
+ struct tar_header header;
+ memset(&header, 0, sizeof(header));
+
+ assert(path.size() < 100);
+ memcpy(header.name, path.data(), path.size());
+ sprintf(header.mode, "%07o", 0600);
+ sprintf(header.uid, "%07o", 0);
+ sprintf(header.gid, "%07o", 0);
+ sprintf(header.size, "%011o", len);
+ sprintf(header.mtime, "%011o", (int)time(NULL));
+ header.typeflag = '0';
+ strcpy(header.magic, "ustar ");
+ strcpy(header.uname, "root");
+ strcpy(header.gname, "root");
+
+ memset(header.chksum, ' ', sizeof(header.chksum));
+ int checksum = 0;
+ for (int i = 0; i < TAR_BLOCK_SIZE; i++) {
+ checksum += ((uint8_t *)&header)[i];
+ }
+ sprintf(header.chksum, "%06o", checksum);