Fix missing prototype compiler warnings
[libtar.git] / lib / output.c
bloba5262ee62816c92c1be11178ad631e929fa6f36d
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
13 #include <internal.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <pwd.h>
18 #include <grp.h>
19 #include <time.h>
20 #include <limits.h>
21 #include <sys/param.h>
23 #ifdef STDC_HEADERS
24 # include <string.h>
25 #endif
28 #ifndef _POSIX_LOGIN_NAME_MAX
29 # define _POSIX_LOGIN_NAME_MAX 9
30 #endif
33 void
34 th_print(TAR *t)
36 puts("\nPrinting tar header:");
37 printf(" name = \"%.100s\"\n", t->th_buf.name);
38 printf(" mode = \"%.8s\"\n", t->th_buf.mode);
39 printf(" uid = \"%.8s\"\n", t->th_buf.uid);
40 printf(" gid = \"%.8s\"\n", t->th_buf.gid);
41 printf(" size = \"%.12s\"\n", t->th_buf.size);
42 printf(" mtime = \"%.12s\"\n", t->th_buf.mtime);
43 printf(" chksum = \"%.8s\"\n", t->th_buf.chksum);
44 printf(" typeflag = \'%c\'\n", t->th_buf.typeflag);
45 printf(" linkname = \"%.100s\"\n", t->th_buf.linkname);
46 printf(" magic = \"%.6s\"\n", t->th_buf.magic);
47 /*printf(" version = \"%.2s\"\n", t->th_buf.version); */
48 printf(" version[0] = \'%c\',version[1] = \'%c\'\n",
49 t->th_buf.version[0], t->th_buf.version[1]);
50 printf(" uname = \"%.32s\"\n", t->th_buf.uname);
51 printf(" gname = \"%.32s\"\n", t->th_buf.gname);
52 printf(" devmajor = \"%.8s\"\n", t->th_buf.devmajor);
53 printf(" devminor = \"%.8s\"\n", t->th_buf.devminor);
54 printf(" prefix = \"%.155s\"\n", t->th_buf.prefix);
55 printf(" padding = \"%.12s\"\n", t->th_buf.padding);
56 printf(" gnu_longname = \"%s\"\n",
57 (t->th_buf.gnu_longname ? t->th_buf.gnu_longname : "[NULL]"));
58 printf(" gnu_longlink = \"%s\"\n",
59 (t->th_buf.gnu_longlink ? t->th_buf.gnu_longlink : "[NULL]"));
63 void
64 th_print_long_ls(TAR *t)
66 char modestring[12];
67 struct passwd *pw;
68 struct group *gr;
69 uid_t uid;
70 gid_t gid;
71 char username[_POSIX_LOGIN_NAME_MAX];
72 char groupname[_POSIX_LOGIN_NAME_MAX];
73 time_t mtime;
74 struct tm *mtm;
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"
83 #endif
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));
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));
99 strmode(th_get_mode(t), modestring);
100 printf("%.10s %-8.8s %-8.8s ", modestring, username, groupname);
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));
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
118 printf(" %s", th_get_pathname(t));
120 if (TH_ISSYM(t) || TH_ISLNK(t))
122 if (TH_ISSYM(t))
123 printf(" -> ");
124 else
125 printf(" link to ");
126 if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL)
127 printf("%s", t->th_buf.gnu_longlink);
128 else
129 printf("%.100s", t->th_buf.linkname);
132 putchar('\n');