我尝试创建一个函数来读取 C 上 .tar 文件的每个标题,当我打印标题结构的字符大小时,它给了我“0000000016”字节。但文件是 318 字节,所以我不明白。
int get_new_file(int fd, int fd_1, t_list point)
{
long int nb;
char *buff;
int size_buff;
int len;
nb = strtol(point.header.size, NULL, 8);
if ((buff = malloc(sizeof(*buff) * nb + 1)) == NULL)
return (-1);
if ((size_buff = read(fd, buff, nb)) <= 0)
return (-1);
if ((len = write(fd_1, buff, nb)) <= 0)
return (-1);
printf("%s\n", point.header.size); /* this give me 00000000616, is this a special base ? */
printf("%d\n", strtol(point.header.size, NULL, 8)); /* and this 398 */
len = (len - 512) * -1;
if ((len = read(fd, buff, len)) <= 0)
return (-1);
bzero(buff, nb + 1);
return (0);
}
和我的结构:
typedef struct s_head
{
char name[100];
char mode[8];
char uid[8];
char gid[8];
char size[12];
char mtime[12];
char chksum[8];
char linkflag;
char linkname[100];
char magic[8];
char uname[32];
char gname[32];
char devmajor[8];
char devminor[8];
} t_head;
typedef union s_list
{
char tab[512];
t_head header;
} t_list;