- unsigned int namelen;
- char *header = NULL;
- unsigned int checksum = 0;
- int i;
- unsigned int ext_header = 0;
-
- if (typeflag == TYPEFLAG_AUTO) {
- if (S_ISDIR(mode))
- typeflag = TYPEFLAG_DIR;
- else if (S_ISLNK(mode))
- typeflag = TYPEFLAG_LNK;
- else
- typeflag = TYPEFLAG_REG;
- }
-
- namelen = path_len(S_ISDIR(mode), basepath, prefix, path);
- if (namelen > 100)
- ext_header |= EXT_HEADER_PATH;
- if (typeflag == TYPEFLAG_LNK && size > 100)
- ext_header |= EXT_HEADER_LINKPATH;
-
- /* the extended header must be written before the normal one */
- if (ext_header) {
- char headerfilename[51];
- sprintf(headerfilename, "%s.paxheader", sha1_to_hex(sha1));
- write_extended_header(headerfilename, S_ISDIR(mode),
- ext_header, basepath, prefix, path,
- namelen, buffer, size);
- }
-
- header = get_record();
-
- if (ext_header) {
- sprintf(header, "%s.data", sha1_to_hex(sha1));
+ struct ustar_header header;
+ struct strbuf ext_header;
+
+ memset(&header, 0, sizeof(header));
+ ext_header.buf = NULL;
+ ext_header.len = ext_header.alloc = 0;
+
+ if (!sha1) {
+ *header.typeflag = TYPEFLAG_GLOBAL_HEADER;
+ mode = 0100666;
+ strcpy(header.name, "pax_global_header");
+ } else if (!path) {
+ *header.typeflag = TYPEFLAG_EXT_HEADER;
+ mode = 0100666;
+ sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1));