2 ** Copyright 1998-2003 University of Illinois Board of Trustees
3 ** Copyright 1998-2003 Mark D. Roth
4 ** All rights reserved.
6 ** output.c - libtar code to print out tar header blocks
8 ** Mark D. Roth <roth@uiuc.edu>
9 ** Campus Information Technologies and Educational Services
10 ** University of Illinois at Urbana-Champaign
13 #include <libtarint/internal.h>
18 #if !defined(_WIN32) || defined(__CYGWIN__)
31 #ifndef _POSIX_LOGIN_NAME_MAX
32 # define _POSIX_LOGIN_NAME_MAX 9
39 puts("\nPrinting tar header:");
40 printf(" name = \"%.100s\"\n", t
->th_buf
.name
);
41 printf(" mode = \"%.8s\"\n", t
->th_buf
.mode
);
42 printf(" uid = \"%.8s\"\n", t
->th_buf
.uid
);
43 printf(" gid = \"%.8s\"\n", t
->th_buf
.gid
);
44 printf(" size = \"%.12s\"\n", t
->th_buf
.size
);
45 printf(" mtime = \"%.12s\"\n", t
->th_buf
.mtime
);
46 printf(" chksum = \"%.8s\"\n", t
->th_buf
.chksum
);
47 printf(" typeflag = \'%c\'\n", t
->th_buf
.typeflag
);
48 printf(" linkname = \"%.100s\"\n", t
->th_buf
.linkname
);
49 printf(" magic = \"%.6s\"\n", t
->th_buf
.magic
);
50 /*printf(" version = \"%.2s\"\n", t->th_buf.version); */
51 printf(" version[0] = \'%c\',version[1] = \'%c\'\n",
52 t
->th_buf
.version
[0], t
->th_buf
.version
[1]);
53 printf(" uname = \"%.32s\"\n", t
->th_buf
.uname
);
54 printf(" gname = \"%.32s\"\n", t
->th_buf
.gname
);
55 printf(" devmajor = \"%.8s\"\n", t
->th_buf
.devmajor
);
56 printf(" devminor = \"%.8s\"\n", t
->th_buf
.devminor
);
57 printf(" prefix = \"%.155s\"\n", t
->th_buf
.prefix
);
58 printf(" padding = \"%.12s\"\n", t
->th_buf
.padding
);
59 printf(" gnu_longname = \"%s\"\n",
60 (t
->th_buf
.gnu_longname
? t
->th_buf
.gnu_longname
: "[NULL]"));
61 printf(" gnu_longlink = \"%s\"\n",
62 (t
->th_buf
.gnu_longlink
? t
->th_buf
.gnu_longlink
: "[NULL]"));
67 th_print_long_ls(TAR
*t
)
70 #if !defined(_WIN32) || defined(__CYGWIN__)
76 char username
[_POSIX_LOGIN_NAME_MAX
];
77 char groupname
[_POSIX_LOGIN_NAME_MAX
];
85 const char *months
[] = {
86 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
87 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
92 #if !defined(_WIN32) || defined(__CYGWIN__)
95 strlcpy(username
, pw
->pw_name
, sizeof(username
));
98 snprintf(username
, sizeof(username
), "%d", (int)uid
);
100 #if !defined(_WIN32) || defined(__CYGWIN__)
103 strlcpy(groupname
, gr
->gr_name
, sizeof(groupname
));
106 snprintf(groupname
, sizeof(groupname
), "%d", (int)gid
);
108 strmode(th_get_mode(t
), modestring
);
109 printf("%.10s %-8.8s %-8.8s ", modestring
, username
, groupname
);
111 #if !defined(_WIN32) || defined(__CYGWIN__)
112 if (TH_ISCHR(t
) || TH_ISBLK(t
))
113 printf(" %3d, %3d ", th_get_devmajor(t
), th_get_devminor(t
));
116 printf("%9ld ", (long)th_get_size(t
));
118 mtime
= th_get_mtime(t
);
119 mtm
= localtime(&mtime
);
121 strftime(timebuf
, sizeof(timebuf
), "%b %d %H:%M %Y", mtm
);
122 printf("%s", timebuf
);
124 printf("%.3s %2d %2d:%02d %4d",
126 mtm
->tm_mday
, mtm
->tm_hour
, mtm
->tm_min
, mtm
->tm_year
+ 1900);
129 pathname
= th_get_pathname(t
);
132 printf(" %s", pathname
);
136 #if !defined(_WIN32) || defined(__CYGWIN__)
137 if (TH_ISSYM(t
) || TH_ISLNK(t
))
143 if ((t
->options
& TAR_GNU
) && t
->th_buf
.gnu_longlink
!= NULL
)
144 printf("%s", t
->th_buf
.gnu_longlink
);
146 printf("%.100s", t
->th_buf
.linkname
);