Make the tar(1)-header fixed again

This is clearer.
This commit is contained in:
FRIGN 2015-02-16 20:01:33 +01:00
parent eb17f2cc9c
commit 8e016fad91

8
tar.c
View File

@ -21,8 +21,8 @@ struct header {
char chksum[8]; char chksum[8];
char type; char type;
char link[100]; char link[100];
char *magic; char magic[6];
char *version; char version[2];
char uname[32]; char uname[32];
char gname[32]; char gname[32];
char major[8]; char major[8];
@ -111,8 +111,8 @@ archive(const char* path)
putoctal(h->gid, (unsigned)st.st_gid, sizeof(h->gid)); putoctal(h->gid, (unsigned)st.st_gid, sizeof(h->gid));
putoctal(h->size, 0, sizeof(h->size)); putoctal(h->size, 0, sizeof(h->size));
putoctal(h->mtime, (unsigned)st.st_mtime, sizeof(h->mtime)); putoctal(h->mtime, (unsigned)st.st_mtime, sizeof(h->mtime));
h->magic = "ustar"; memcpy(h->magic, "ustar", sizeof(h->magic));
h->version = "00"; memcpy(h->version, "00", sizeof(h->version));
snprintf(h->uname, sizeof h->uname, "%s", pw ? pw->pw_name : ""); snprintf(h->uname, sizeof h->uname, "%s", pw ? pw->pw_name : "");
snprintf(h->gname, sizeof h->gname, "%s", gr ? gr->gr_name : ""); snprintf(h->gname, sizeof h->gname, "%s", gr ? gr->gr_name : "");