Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4 | magnus | 1 | /* |
2 | ** Copyright 1998-2003 University of Illinois Board of Trustees |
||
3 | ** Copyright 1998-2003 Mark D. Roth |
||
4 | ** All rights reserved. |
||
5 | ** |
||
6 | ** output.c - libtar code to print out tar header blocks |
||
7 | ** |
||
8 | ** Mark D. Roth <roth@uiuc.edu> |
||
9 | ** Campus Information Technologies and Educational Services |
||
10 | ** University of Illinois at Urbana-Champaign |
||
11 | */ |
||
12 | |||
13 | #include <internal.h> |
||
14 | |||
15 | #include <stdio.h> |
||
16 | #include <pwd.h> |
||
17 | #include <grp.h> |
||
18 | #include <time.h> |
||
19 | #include <limits.h> |
||
20 | #include <sys/param.h> |
||
21 | |||
22 | #ifdef STDC_HEADERS |
||
23 | # include <string.h> |
||
24 | #endif |
||
25 | |||
26 | |||
27 | #ifndef _POSIX_LOGIN_NAME_MAX |
||
28 | # define _POSIX_LOGIN_NAME_MAX 9 |
||
29 | #endif |
||
30 | |||
31 | |||
32 | void |
||
33 | th_print(TAR *t) |
||
34 | { |
||
35 | puts("\nPrinting tar header:"); |
||
36 | printf(" name = \"%.100s\"\n", t->th_buf.name); |
||
37 | printf(" mode = \"%.8s\"\n", t->th_buf.mode); |
||
38 | printf(" uid = \"%.8s\"\n", t->th_buf.uid); |
||
39 | printf(" gid = \"%.8s\"\n", t->th_buf.gid); |
||
40 | printf(" size = \"%.12s\"\n", t->th_buf.size); |
||
41 | printf(" mtime = \"%.12s\"\n", t->th_buf.mtime); |
||
42 | printf(" chksum = \"%.8s\"\n", t->th_buf.chksum); |
||
43 | printf(" typeflag = \'%c\'\n", t->th_buf.typeflag); |
||
44 | printf(" linkname = \"%.100s\"\n", t->th_buf.linkname); |
||
45 | printf(" magic = \"%.6s\"\n", t->th_buf.magic); |
||
46 | /*printf(" version = \"%.2s\"\n", t->th_buf.version); */ |
||
47 | printf(" version[0] = \'%c\',version[1] = \'%c\'\n", |
||
48 | t->th_buf.version[0], t->th_buf.version[1]); |
||
49 | printf(" uname = \"%.32s\"\n", t->th_buf.uname); |
||
50 | printf(" gname = \"%.32s\"\n", t->th_buf.gname); |
||
51 | printf(" devmajor = \"%.8s\"\n", t->th_buf.devmajor); |
||
52 | printf(" devminor = \"%.8s\"\n", t->th_buf.devminor); |
||
53 | printf(" prefix = \"%.155s\"\n", t->th_buf.prefix); |
||
54 | printf(" padding = \"%.12s\"\n", t->th_buf.padding); |
||
55 | printf(" gnu_longname = \"%s\"\n", |
||
56 | (t->th_buf.gnu_longname ? t->th_buf.gnu_longname : "[NULL]")); |
||
57 | printf(" gnu_longlink = \"%s\"\n", |
||
58 | (t->th_buf.gnu_longlink ? t->th_buf.gnu_longlink : "[NULL]")); |
||
59 | } |
||
60 | |||
61 | |||
62 | void |
||
63 | th_print_long_ls(TAR *t) |
||
64 | { |
||
65 | char modestring[12]; |
||
66 | struct passwd *pw; |
||
67 | struct group *gr; |
||
68 | uid_t uid; |
||
69 | gid_t gid; |
||
70 | char username[_POSIX_LOGIN_NAME_MAX]; |
||
71 | char groupname[_POSIX_LOGIN_NAME_MAX]; |
||
72 | time_t mtime; |
||
73 | struct tm *mtm; |
||
74 | char *pathname; |
||
75 | |||
76 | #ifdef HAVE_STRFTIME |
||
77 | char timebuf[18]; |
||
78 | #else |
||
79 | const char *months[] = { |
||
80 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
||
81 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
||
82 | }; |
||
83 | #endif |
||
84 | |||
85 | uid = th_get_uid(t); |
||
86 | pw = getpwuid(uid); |
||
87 | if (pw == NULL) |
||
88 | snprintf(username, sizeof(username), "%d", uid); |
||
89 | else |
||
90 | strlcpy(username, pw->pw_name, sizeof(username)); |
||
91 | |||
92 | gid = th_get_gid(t); |
||
93 | gr = getgrgid(gid); |
||
94 | if (gr == NULL) |
||
95 | snprintf(groupname, sizeof(groupname), "%d", gid); |
||
96 | else |
||
97 | strlcpy(groupname, gr->gr_name, sizeof(groupname)); |
||
98 | |||
99 | strmode(th_get_mode(t), modestring); |
||
100 | printf("%.10s %-8.8s %-8.8s ", modestring, username, groupname); |
||
101 | |||
102 | if (TH_ISCHR(t) || TH_ISBLK(t)) |
||
103 | printf(" %3d, %3d ", th_get_devmajor(t), th_get_devminor(t)); |
||
104 | else |
||
105 | printf("%9ld ", (long)th_get_size(t)); |
||
106 | |||
107 | mtime = th_get_mtime(t); |
||
108 | mtm = localtime(&mtime); |
||
109 | #ifdef HAVE_STRFTIME |
||
110 | strftime(timebuf, sizeof(timebuf), "%h %e %H:%M %Y", mtm); |
||
111 | printf("%s", timebuf); |
||
112 | #else |
||
113 | printf("%.3s %2d %2d:%02d %4d", |
||
114 | months[mtm->tm_mon], |
||
115 | mtm->tm_mday, mtm->tm_hour, mtm->tm_min, mtm->tm_year + 1900); |
||
116 | #endif |
||
117 | |||
118 | pathname = th_get_pathname(t); |
||
119 | printf(" %s", pathname); |
||
120 | free(pathname); |
||
121 | |||
122 | if (TH_ISSYM(t) || TH_ISLNK(t)) |
||
123 | { |
||
124 | if (TH_ISSYM(t)) |
||
125 | printf(" -> "); |
||
126 | else |
||
127 | printf(" link to "); |
||
128 | if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL) |
||
129 | printf("%s", t->th_buf.gnu_longlink); |
||
130 | else |
||
131 | printf("%.100s", t->th_buf.linkname); |
||
132 | } |
||
133 | |||
134 | putchar('\n'); |
||
135 | } |
||
136 | |||
137 |