tarruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. data/README.txt +99 -0
  2. data/ext/extconf.rb +19 -0
  3. data/ext/libtar/COPYRIGHT +35 -0
  4. data/ext/libtar/ChangeLog +243 -0
  5. data/ext/libtar/ChangeLog-1.0.x +141 -0
  6. data/ext/libtar/INSTALL +183 -0
  7. data/ext/libtar/Makefile.in +51 -0
  8. data/ext/libtar/README +121 -0
  9. data/ext/libtar/TODO +10 -0
  10. data/ext/libtar/autoconf/ac_path_generic.m4 +136 -0
  11. data/ext/libtar/autoconf/aclocal.m4 +199 -0
  12. data/ext/libtar/autoconf/encap.m4 +133 -0
  13. data/ext/libtar/autoconf/install-sh +251 -0
  14. data/ext/libtar/autom4te.cache/output.0 +8102 -0
  15. data/ext/libtar/autom4te.cache/requests +112 -0
  16. data/ext/libtar/autom4te.cache/traces.0 +382 -0
  17. data/ext/libtar/compat/ChangeLog +31 -0
  18. data/ext/libtar/compat/README +12 -0
  19. data/ext/libtar/compat/TODO +4 -0
  20. data/ext/libtar/compat/basename.c +91 -0
  21. data/ext/libtar/compat/compat.h +260 -0
  22. data/ext/libtar/compat/dirname.c +96 -0
  23. data/ext/libtar/compat/fnmatch.c +237 -0
  24. data/ext/libtar/compat/gethostbyname_r.c +41 -0
  25. data/ext/libtar/compat/gethostname.c +36 -0
  26. data/ext/libtar/compat/getservbyname_r.c +41 -0
  27. data/ext/libtar/compat/glob.c +898 -0
  28. data/ext/libtar/compat/inet_aton.c +27 -0
  29. data/ext/libtar/compat/module.ac +591 -0
  30. data/ext/libtar/compat/snprintf.c +788 -0
  31. data/ext/libtar/compat/strdup.c +62 -0
  32. data/ext/libtar/compat/strlcat.c +72 -0
  33. data/ext/libtar/compat/strlcpy.c +68 -0
  34. data/ext/libtar/compat/strmode.c +199 -0
  35. data/ext/libtar/compat/strrstr.c +40 -0
  36. data/ext/libtar/compat/strsep.c +87 -0
  37. data/ext/libtar/config.h.in +187 -0
  38. data/ext/libtar/configure +8102 -0
  39. data/ext/libtar/configure.ac +114 -0
  40. data/ext/libtar/doc/Makefile.in +152 -0
  41. data/ext/libtar/doc/tar_append_file.3 +50 -0
  42. data/ext/libtar/doc/tar_block_read.3 +24 -0
  43. data/ext/libtar/doc/tar_extract_all.3 +43 -0
  44. data/ext/libtar/doc/tar_extract_file.3 +84 -0
  45. data/ext/libtar/doc/tar_open.3 +97 -0
  46. data/ext/libtar/doc/th_get_pathname.3 +63 -0
  47. data/ext/libtar/doc/th_print_long_ls.3 +22 -0
  48. data/ext/libtar/doc/th_read.3 +34 -0
  49. data/ext/libtar/doc/th_set_from_stat.3 +45 -0
  50. data/ext/libtar/lib/Makefile.in +92 -0
  51. data/ext/libtar/lib/append.c +272 -0
  52. data/ext/libtar/lib/block.c +384 -0
  53. data/ext/libtar/lib/decode.c +130 -0
  54. data/ext/libtar/lib/encode.c +237 -0
  55. data/ext/libtar/lib/extract.c +656 -0
  56. data/ext/libtar/lib/handle.c +150 -0
  57. data/ext/libtar/lib/internal.h +46 -0
  58. data/ext/libtar/lib/libtar.h +311 -0
  59. data/ext/libtar/lib/output.c +146 -0
  60. data/ext/libtar/lib/util.c +153 -0
  61. data/ext/libtar/lib/wrapper.c +175 -0
  62. data/ext/libtar/libtar/Makefile.in +73 -0
  63. data/ext/libtar/libtar/libtar.c +363 -0
  64. data/ext/libtar/listhash/ChangeLog +15 -0
  65. data/ext/libtar/listhash/TODO +21 -0
  66. data/ext/libtar/listhash/hash.c.in +344 -0
  67. data/ext/libtar/listhash/hash_new.3.in +74 -0
  68. data/ext/libtar/listhash/list.c.in +458 -0
  69. data/ext/libtar/listhash/list_new.3.in +86 -0
  70. data/ext/libtar/listhash/listhash.h.in +196 -0
  71. data/ext/libtar/listhash/module.ac +21 -0
  72. data/ext/libtar/win32/config.h +190 -0
  73. data/ext/libtar/win32/dirent.c +115 -0
  74. data/ext/libtar/win32/dirent.h +24 -0
  75. data/ext/libtar/win32/grp.h +4 -0
  76. data/ext/libtar/win32/listhash/libtar_hash.c +344 -0
  77. data/ext/libtar/win32/listhash/libtar_list.c +458 -0
  78. data/ext/libtar/win32/listhash/libtar_listhash.h +196 -0
  79. data/ext/libtar/win32/pwd.h +4 -0
  80. data/ext/libtar/win32/sys/param.h +8 -0
  81. data/ext/libtar/win32/tar.h +35 -0
  82. data/ext/libtar/win32/utime.h +6 -0
  83. data/ext/libtar/win32/win32/types.h +10 -0
  84. data/ext/tarruby.c +648 -0
  85. metadata +150 -0
@@ -0,0 +1,237 @@
1
+ /*
2
+ ** Copyright 1998-2003 University of Illinois Board of Trustees
3
+ ** Copyright 1998-2003 Mark D. Roth
4
+ ** All rights reserved.
5
+ **
6
+ ** encode.c - libtar code to encode 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
+ // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
14
+ #ifdef _WIN32
15
+ #pragma warning(disable:4244)
16
+ #endif
17
+
18
+ #include <internal.h>
19
+
20
+ #include <stdio.h>
21
+ #include <pwd.h>
22
+ #include <grp.h>
23
+ #include <sys/types.h>
24
+
25
+ #ifdef STDC_HEADERS
26
+ # include <string.h>
27
+ # include <stdlib.h>
28
+ #endif
29
+
30
+
31
+ /* magic, version, and checksum */
32
+ void
33
+ th_finish(TAR *t)
34
+ {
35
+ int i, sum = 0;
36
+
37
+ if (t->options & TAR_GNU)
38
+ strncpy(t->th_buf.magic, "ustar ", 8);
39
+ else
40
+ {
41
+ strncpy(t->th_buf.version, TVERSION, TVERSLEN);
42
+ strncpy(t->th_buf.magic, TMAGIC, TMAGLEN);
43
+ }
44
+
45
+ // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
46
+ for (i = 0; i < T_BLOCKSIZE; i++) {
47
+ //sum += ((char *)(&(t->th_buf)))[i];
48
+ sum += ((unsigned char *)(&(t->th_buf)))[i];
49
+ }
50
+ for (i = 0; i < 8; i++)
51
+ sum += (' ' - t->th_buf.chksum[i]);
52
+ // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
53
+ //int_to_oct(sum, t->th_buf.chksum, 8);
54
+ snprintf(t->th_buf.chksum, 8, "%06lo", (unsigned long)(sum));
55
+ t->th_buf.chksum[6] = 0;
56
+ t->th_buf.chksum[7] = ' ';
57
+ }
58
+
59
+
60
+ /* map a file mode to a typeflag */
61
+ void
62
+ th_set_type(TAR *t, mode_t mode)
63
+ {
64
+ if (S_ISLNK(mode))
65
+ t->th_buf.typeflag = SYMTYPE;
66
+ if (S_ISREG(mode))
67
+ t->th_buf.typeflag = REGTYPE;
68
+ if (S_ISDIR(mode))
69
+ t->th_buf.typeflag = DIRTYPE;
70
+ if (S_ISCHR(mode))
71
+ t->th_buf.typeflag = CHRTYPE;
72
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
73
+ if (S_ISBLK(mode))
74
+ t->th_buf.typeflag = BLKTYPE;
75
+ #endif
76
+ if (S_ISFIFO(mode) || S_ISSOCK(mode))
77
+ t->th_buf.typeflag = FIFOTYPE;
78
+ }
79
+
80
+
81
+ /* encode file path */
82
+ void
83
+ th_set_path(TAR *t, char *pathname)
84
+ {
85
+ char suffix[2] = "";
86
+ char *tmp;
87
+
88
+ #ifdef DEBUG
89
+ printf("in th_set_path(th, pathname=\"%s\")\n", pathname);
90
+ #endif
91
+
92
+ if (t->th_buf.gnu_longname != NULL)
93
+ free(t->th_buf.gnu_longname);
94
+ t->th_buf.gnu_longname = NULL;
95
+
96
+ if (pathname[strlen(pathname) - 1] != '/' && TH_ISDIR(t))
97
+ strcpy(suffix, "/");
98
+
99
+ if (strlen(pathname) >= T_NAMELEN && (t->options & TAR_GNU))
100
+ {
101
+ /* GNU-style long name */
102
+ t->th_buf.gnu_longname = strdup(pathname);
103
+ strncpy(t->th_buf.name, t->th_buf.gnu_longname, T_NAMELEN);
104
+ }
105
+ else if (strlen(pathname) >= T_NAMELEN)
106
+ {
107
+ /* POSIX-style prefix field */
108
+ tmp = strchr(&(pathname[strlen(pathname) - T_NAMELEN - 1]), '/');
109
+ if (tmp == NULL)
110
+ {
111
+ printf("!!! '/' not found in \"%s\"\n", pathname);
112
+ return;
113
+ }
114
+ snprintf(t->th_buf.name, 100, "%s%s", &(tmp[1]), suffix);
115
+ snprintf(t->th_buf.prefix,
116
+ ((tmp - pathname + 1) <
117
+ 155 ? (tmp - pathname + 1) : 155), "%s", pathname);
118
+ }
119
+ else
120
+ /* classic tar format */
121
+ snprintf(t->th_buf.name, 100, "%s%s", pathname, suffix);
122
+
123
+ #ifdef DEBUG
124
+ puts("returning from th_set_path()...");
125
+ #endif
126
+ }
127
+
128
+
129
+ /* encode link path */
130
+ void
131
+ th_set_link(TAR *t, char *linkname)
132
+ {
133
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
134
+ #ifdef DEBUG
135
+ printf("==> th_set_link(th, linkname=\"%s\")\n", linkname);
136
+ #endif
137
+
138
+ if (strlen(linkname) > T_NAMELEN && (t->options & TAR_GNU))
139
+ {
140
+ /* GNU longlink format */
141
+ t->th_buf.gnu_longlink = strdup(linkname);
142
+ strcpy(t->th_buf.linkname, "././@LongLink");
143
+ }
144
+ else
145
+ {
146
+ /* classic tar format */
147
+ strlcpy(t->th_buf.linkname, linkname,
148
+ sizeof(t->th_buf.linkname));
149
+ if (t->th_buf.gnu_longlink != NULL)
150
+ free(t->th_buf.gnu_longlink);
151
+ t->th_buf.gnu_longlink = NULL;
152
+ }
153
+ #endif
154
+ }
155
+
156
+
157
+ /* encode device info */
158
+ void
159
+ th_set_device(TAR *t, dev_t device)
160
+ {
161
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
162
+ #ifdef DEBUG
163
+ printf("th_set_device(): major = %d, minor = %d\n",
164
+ major(device), minor(device));
165
+ #endif
166
+ int_to_oct(major(device), t->th_buf.devmajor, 8);
167
+ int_to_oct(minor(device), t->th_buf.devminor, 8);
168
+ #endif
169
+ }
170
+
171
+
172
+ /* encode user info */
173
+ void
174
+ th_set_user(TAR *t, uid_t uid)
175
+ {
176
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
177
+ struct passwd *pw;
178
+
179
+ pw = getpwuid(uid);
180
+ if (pw != NULL)
181
+ strlcpy(t->th_buf.uname, pw->pw_name, sizeof(t->th_buf.uname));
182
+ #endif
183
+
184
+ int_to_oct(uid, t->th_buf.uid, 8);
185
+ }
186
+
187
+
188
+ /* encode group info */
189
+ void
190
+ th_set_group(TAR *t, gid_t gid)
191
+ {
192
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
193
+ struct group *gr;
194
+
195
+ gr = getgrgid(gid);
196
+ if (gr != NULL)
197
+ strlcpy(t->th_buf.gname, gr->gr_name, sizeof(t->th_buf.gname));
198
+ #endif
199
+
200
+ int_to_oct(gid, t->th_buf.gid, 8);
201
+ }
202
+
203
+
204
+ /* encode file mode */
205
+ void
206
+ th_set_mode(TAR *t, mode_t fmode)
207
+ {
208
+ #ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
209
+ if (S_ISSOCK(fmode))
210
+ {
211
+ fmode &= ~S_IFSOCK;
212
+ fmode |= S_IFIFO;
213
+ }
214
+ #endif
215
+ // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
216
+ //int_to_oct(fmode, (t)->th_buf.mode, 8);
217
+ int_to_oct((fmode & 0xFFF), (t)->th_buf.mode, 8);
218
+ }
219
+
220
+
221
+ void
222
+ th_set_from_stat(TAR *t, struct stat *s)
223
+ {
224
+ th_set_type(t, s->st_mode);
225
+ if (S_ISCHR(s->st_mode) || S_ISBLK(s->st_mode))
226
+ th_set_device(t, s->st_rdev);
227
+ th_set_user(t, s->st_uid);
228
+ th_set_group(t, s->st_gid);
229
+ th_set_mode(t, s->st_mode);
230
+ th_set_mtime(t, s->st_mtime);
231
+ if (S_ISREG(s->st_mode))
232
+ th_set_size(t, s->st_size);
233
+ else
234
+ th_set_size(t, 0);
235
+ }
236
+
237
+