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.
- data/README.txt +99 -0
- data/ext/extconf.rb +19 -0
- data/ext/libtar/COPYRIGHT +35 -0
- data/ext/libtar/ChangeLog +243 -0
- data/ext/libtar/ChangeLog-1.0.x +141 -0
- data/ext/libtar/INSTALL +183 -0
- data/ext/libtar/Makefile.in +51 -0
- data/ext/libtar/README +121 -0
- data/ext/libtar/TODO +10 -0
- data/ext/libtar/autoconf/ac_path_generic.m4 +136 -0
- data/ext/libtar/autoconf/aclocal.m4 +199 -0
- data/ext/libtar/autoconf/encap.m4 +133 -0
- data/ext/libtar/autoconf/install-sh +251 -0
- data/ext/libtar/autom4te.cache/output.0 +8102 -0
- data/ext/libtar/autom4te.cache/requests +112 -0
- data/ext/libtar/autom4te.cache/traces.0 +382 -0
- data/ext/libtar/compat/ChangeLog +31 -0
- data/ext/libtar/compat/README +12 -0
- data/ext/libtar/compat/TODO +4 -0
- data/ext/libtar/compat/basename.c +91 -0
- data/ext/libtar/compat/compat.h +260 -0
- data/ext/libtar/compat/dirname.c +96 -0
- data/ext/libtar/compat/fnmatch.c +237 -0
- data/ext/libtar/compat/gethostbyname_r.c +41 -0
- data/ext/libtar/compat/gethostname.c +36 -0
- data/ext/libtar/compat/getservbyname_r.c +41 -0
- data/ext/libtar/compat/glob.c +898 -0
- data/ext/libtar/compat/inet_aton.c +27 -0
- data/ext/libtar/compat/module.ac +591 -0
- data/ext/libtar/compat/snprintf.c +788 -0
- data/ext/libtar/compat/strdup.c +62 -0
- data/ext/libtar/compat/strlcat.c +72 -0
- data/ext/libtar/compat/strlcpy.c +68 -0
- data/ext/libtar/compat/strmode.c +199 -0
- data/ext/libtar/compat/strrstr.c +40 -0
- data/ext/libtar/compat/strsep.c +87 -0
- data/ext/libtar/config.h.in +187 -0
- data/ext/libtar/configure +8102 -0
- data/ext/libtar/configure.ac +114 -0
- data/ext/libtar/doc/Makefile.in +152 -0
- data/ext/libtar/doc/tar_append_file.3 +50 -0
- data/ext/libtar/doc/tar_block_read.3 +24 -0
- data/ext/libtar/doc/tar_extract_all.3 +43 -0
- data/ext/libtar/doc/tar_extract_file.3 +84 -0
- data/ext/libtar/doc/tar_open.3 +97 -0
- data/ext/libtar/doc/th_get_pathname.3 +63 -0
- data/ext/libtar/doc/th_print_long_ls.3 +22 -0
- data/ext/libtar/doc/th_read.3 +34 -0
- data/ext/libtar/doc/th_set_from_stat.3 +45 -0
- data/ext/libtar/lib/Makefile.in +92 -0
- data/ext/libtar/lib/append.c +272 -0
- data/ext/libtar/lib/block.c +384 -0
- data/ext/libtar/lib/decode.c +130 -0
- data/ext/libtar/lib/encode.c +237 -0
- data/ext/libtar/lib/extract.c +656 -0
- data/ext/libtar/lib/handle.c +150 -0
- data/ext/libtar/lib/internal.h +46 -0
- data/ext/libtar/lib/libtar.h +311 -0
- data/ext/libtar/lib/output.c +146 -0
- data/ext/libtar/lib/util.c +153 -0
- data/ext/libtar/lib/wrapper.c +175 -0
- data/ext/libtar/libtar/Makefile.in +73 -0
- data/ext/libtar/libtar/libtar.c +363 -0
- data/ext/libtar/listhash/ChangeLog +15 -0
- data/ext/libtar/listhash/TODO +21 -0
- data/ext/libtar/listhash/hash.c.in +344 -0
- data/ext/libtar/listhash/hash_new.3.in +74 -0
- data/ext/libtar/listhash/list.c.in +458 -0
- data/ext/libtar/listhash/list_new.3.in +86 -0
- data/ext/libtar/listhash/listhash.h.in +196 -0
- data/ext/libtar/listhash/module.ac +21 -0
- data/ext/libtar/win32/config.h +190 -0
- data/ext/libtar/win32/dirent.c +115 -0
- data/ext/libtar/win32/dirent.h +24 -0
- data/ext/libtar/win32/grp.h +4 -0
- data/ext/libtar/win32/listhash/libtar_hash.c +344 -0
- data/ext/libtar/win32/listhash/libtar_list.c +458 -0
- data/ext/libtar/win32/listhash/libtar_listhash.h +196 -0
- data/ext/libtar/win32/pwd.h +4 -0
- data/ext/libtar/win32/sys/param.h +8 -0
- data/ext/libtar/win32/tar.h +35 -0
- data/ext/libtar/win32/utime.h +6 -0
- data/ext/libtar/win32/win32/types.h +10 -0
- data/ext/tarruby.c +648 -0
- metadata +150 -0
@@ -0,0 +1,150 @@
|
|
1
|
+
/*
|
2
|
+
** Copyright 1998-2003 University of Illinois Board of Trustees
|
3
|
+
** Copyright 1998-2003 Mark D. Roth
|
4
|
+
** All rights reserved.
|
5
|
+
**
|
6
|
+
** handle.c - libtar code for initializing a TAR handle
|
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 <fcntl.h>
|
17
|
+
#include <errno.h>
|
18
|
+
|
19
|
+
#ifdef HAVE_UNISTD_H
|
20
|
+
# include <unistd.h>
|
21
|
+
#endif
|
22
|
+
|
23
|
+
#ifdef STDC_HEADERS
|
24
|
+
# include <stdlib.h>
|
25
|
+
#endif
|
26
|
+
|
27
|
+
|
28
|
+
const char libtar_version[] = PACKAGE_VERSION;
|
29
|
+
|
30
|
+
static long libtar_open(const char *pathname, int oflags, int mode) {
|
31
|
+
return open(pathname, oflags, mode);
|
32
|
+
}
|
33
|
+
|
34
|
+
static long libtar_close(long fd) {
|
35
|
+
return close((int) fd);
|
36
|
+
}
|
37
|
+
|
38
|
+
static ssize_t libtar_read(long fd, void *buf, size_t len) {
|
39
|
+
return read((int) fd, buf, len);
|
40
|
+
}
|
41
|
+
|
42
|
+
static ssize_t libtar_write(long fd, const void *buf, size_t len) {
|
43
|
+
return write((int) fd, buf, len);
|
44
|
+
}
|
45
|
+
|
46
|
+
static tartype_t default_type = {
|
47
|
+
libtar_open,
|
48
|
+
libtar_close,
|
49
|
+
libtar_read,
|
50
|
+
libtar_write
|
51
|
+
};
|
52
|
+
|
53
|
+
|
54
|
+
static int
|
55
|
+
tar_init(TAR **t, char *pathname, tartype_t *type,
|
56
|
+
int oflags, int mode, int options)
|
57
|
+
{
|
58
|
+
if ((oflags & O_ACCMODE) == O_RDWR)
|
59
|
+
{
|
60
|
+
errno = EINVAL;
|
61
|
+
return -1;
|
62
|
+
}
|
63
|
+
|
64
|
+
*t = (TAR *)calloc(1, sizeof(TAR));
|
65
|
+
if (*t == NULL)
|
66
|
+
return -1;
|
67
|
+
|
68
|
+
(*t)->pathname = pathname;
|
69
|
+
(*t)->options = options;
|
70
|
+
(*t)->type = (type ? type : &default_type);
|
71
|
+
(*t)->oflags = oflags;
|
72
|
+
|
73
|
+
if ((oflags & O_ACCMODE) == O_RDONLY)
|
74
|
+
(*t)->h = libtar_hash_new(256,
|
75
|
+
(libtar_hashfunc_t)path_hashfunc);
|
76
|
+
else
|
77
|
+
(*t)->h = libtar_hash_new(16, (libtar_hashfunc_t)dev_hash);
|
78
|
+
if ((*t)->h == NULL)
|
79
|
+
{
|
80
|
+
free(*t);
|
81
|
+
return -1;
|
82
|
+
}
|
83
|
+
|
84
|
+
return 0;
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
/* open a new tarfile handle */
|
89
|
+
int
|
90
|
+
tar_open(TAR **t, char *pathname, tartype_t *type,
|
91
|
+
int oflags, int mode, int options)
|
92
|
+
{
|
93
|
+
if (tar_init(t, pathname, type, oflags, mode, options) == -1)
|
94
|
+
return -1;
|
95
|
+
|
96
|
+
if ((options & TAR_NOOVERWRITE) && (oflags & O_CREAT))
|
97
|
+
oflags |= O_EXCL;
|
98
|
+
|
99
|
+
#ifdef O_BINARY
|
100
|
+
oflags |= O_BINARY;
|
101
|
+
#endif
|
102
|
+
|
103
|
+
(*t)->fd = (*((*t)->type->openfunc))(pathname, oflags, mode);
|
104
|
+
if ((*t)->fd == -1)
|
105
|
+
{
|
106
|
+
free(*t);
|
107
|
+
return -1;
|
108
|
+
}
|
109
|
+
|
110
|
+
return 0;
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
int
|
115
|
+
tar_fdopen(TAR **t, int fd, char *pathname, tartype_t *type,
|
116
|
+
int oflags, int mode, int options)
|
117
|
+
{
|
118
|
+
if (tar_init(t, pathname, type, oflags, mode, options) == -1)
|
119
|
+
return -1;
|
120
|
+
|
121
|
+
(*t)->fd = fd;
|
122
|
+
return 0;
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
int
|
127
|
+
tar_fd(TAR *t)
|
128
|
+
{
|
129
|
+
return t->fd;
|
130
|
+
}
|
131
|
+
|
132
|
+
|
133
|
+
/* close tarfile handle */
|
134
|
+
int
|
135
|
+
tar_close(TAR *t)
|
136
|
+
{
|
137
|
+
int i;
|
138
|
+
|
139
|
+
i = (*(t->type->closefunc))(t->fd);
|
140
|
+
|
141
|
+
if (t->h != NULL)
|
142
|
+
libtar_hash_free(t->h, ((t->oflags & O_ACCMODE) == O_RDONLY
|
143
|
+
? free
|
144
|
+
: (libtar_freefunc_t)tar_dev_free));
|
145
|
+
free(t);
|
146
|
+
|
147
|
+
return i;
|
148
|
+
}
|
149
|
+
|
150
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/*
|
2
|
+
** Copyright 2002-2003 University of Illinois Board of Trustees
|
3
|
+
** Copyright 2002-2003 Mark D. Roth
|
4
|
+
** All rights reserved.
|
5
|
+
**
|
6
|
+
** internal.h - internal header file for libtar
|
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 <config.h>
|
14
|
+
#include <compat.h>
|
15
|
+
|
16
|
+
#include <libtar.h>
|
17
|
+
|
18
|
+
// modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
19
|
+
#ifdef _WIN32
|
20
|
+
|
21
|
+
#include <direct.h>
|
22
|
+
#include <io.h>
|
23
|
+
#include <string.h>
|
24
|
+
#include <sys/types.h>
|
25
|
+
#include <sys/stat.h>
|
26
|
+
|
27
|
+
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
|
28
|
+
|
29
|
+
#define S_ISREG(m) (((m) & (_S_IFMT)) == (_S_IFREG))
|
30
|
+
#define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
|
31
|
+
#define S_ISCHR(m) (((m) & (_S_IFMT)) == (_S_IFCHR))
|
32
|
+
#define S_ISBLK(m) (0)
|
33
|
+
#define S_ISFIFO(m) (((m) & (_S_IFMT)) == (_S_IFIFO))
|
34
|
+
#define S_ISLNK(m) (0)
|
35
|
+
#define S_ISSOCK(m) (0)
|
36
|
+
|
37
|
+
#define chown(p, o, g) (0)
|
38
|
+
#define geteuid() (0)
|
39
|
+
#define lstat(p, b) stat((p), (b))
|
40
|
+
#define makedev(maj, min) (0)
|
41
|
+
#define mkdir(d, m) _mkdir(d)
|
42
|
+
#define mkfifo(p, m) (0)
|
43
|
+
#define mknod(p, m, d) (0)
|
44
|
+
#define snprintf(s, n, f, ...) do { _snprintf((s), (n), (f), __VA_ARGS__); (s)[(n) - 1] = '\0'; } while(0)
|
45
|
+
|
46
|
+
#endif
|
@@ -0,0 +1,311 @@
|
|
1
|
+
/*
|
2
|
+
** Copyright 1998-2003 University of Illinois Board of Trustees
|
3
|
+
** Copyright 1998-2003 Mark D. Roth
|
4
|
+
** All rights reserved.
|
5
|
+
**
|
6
|
+
** libtar.h - header file for libtar library
|
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
|
+
#ifndef LIBTAR_H
|
14
|
+
#define LIBTAR_H
|
15
|
+
|
16
|
+
#include <sys/types.h>
|
17
|
+
#include <sys/stat.h>
|
18
|
+
#include <tar.h>
|
19
|
+
|
20
|
+
#include <libtar_listhash.h>
|
21
|
+
|
22
|
+
// modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
23
|
+
#ifdef _WIN32
|
24
|
+
#include "win32/types.h"
|
25
|
+
#define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
|
26
|
+
#define S_ISCHR(m) (((m) & (_S_IFMT)) == (_S_IFCHR))
|
27
|
+
#define S_ISLNK(m) (0)
|
28
|
+
#define S_ISBLK(m) (0)
|
29
|
+
#define S_ISFIFO(m) (((m) & (_S_IFMT)) == (_S_IFIFO))
|
30
|
+
#endif
|
31
|
+
|
32
|
+
#ifdef __cplusplus
|
33
|
+
extern "C"
|
34
|
+
{
|
35
|
+
#endif
|
36
|
+
|
37
|
+
|
38
|
+
/* useful constants */
|
39
|
+
#define T_BLOCKSIZE 512
|
40
|
+
#define T_NAMELEN 100
|
41
|
+
#define T_PREFIXLEN 155
|
42
|
+
#define T_MAXPATHLEN (T_NAMELEN + T_PREFIXLEN)
|
43
|
+
|
44
|
+
/* GNU extensions for typeflag */
|
45
|
+
#define GNU_LONGNAME_TYPE 'L'
|
46
|
+
#define GNU_LONGLINK_TYPE 'K'
|
47
|
+
|
48
|
+
/* our version of the tar header structure */
|
49
|
+
struct tar_header
|
50
|
+
{
|
51
|
+
char name[100];
|
52
|
+
char mode[8];
|
53
|
+
char uid[8];
|
54
|
+
char gid[8];
|
55
|
+
char size[12];
|
56
|
+
char mtime[12];
|
57
|
+
char chksum[8];
|
58
|
+
char typeflag;
|
59
|
+
char linkname[100];
|
60
|
+
char magic[6];
|
61
|
+
char version[2];
|
62
|
+
char uname[32];
|
63
|
+
char gname[32];
|
64
|
+
char devmajor[8];
|
65
|
+
char devminor[8];
|
66
|
+
char prefix[155];
|
67
|
+
char padding[12];
|
68
|
+
char *gnu_longname;
|
69
|
+
char *gnu_longlink;
|
70
|
+
};
|
71
|
+
|
72
|
+
|
73
|
+
/***** handle.c ************************************************************/
|
74
|
+
|
75
|
+
typedef long (*openfunc_t)(const char *, int, int);
|
76
|
+
typedef int (*closefunc_t)(long);
|
77
|
+
typedef ssize_t (*readfunc_t)(long, void *, size_t);
|
78
|
+
typedef ssize_t (*writefunc_t)(long, const void *, size_t);
|
79
|
+
|
80
|
+
typedef struct
|
81
|
+
{
|
82
|
+
openfunc_t openfunc;
|
83
|
+
closefunc_t closefunc;
|
84
|
+
readfunc_t readfunc;
|
85
|
+
writefunc_t writefunc;
|
86
|
+
}
|
87
|
+
tartype_t;
|
88
|
+
|
89
|
+
typedef struct
|
90
|
+
{
|
91
|
+
tartype_t *type;
|
92
|
+
char *pathname;
|
93
|
+
long fd;
|
94
|
+
int oflags;
|
95
|
+
int options;
|
96
|
+
struct tar_header th_buf;
|
97
|
+
libtar_hash_t *h;
|
98
|
+
}
|
99
|
+
TAR;
|
100
|
+
|
101
|
+
/* constant values for the TAR options field */
|
102
|
+
#define TAR_GNU 1 /* use GNU extensions */
|
103
|
+
#define TAR_VERBOSE 2 /* output file info to stdout */
|
104
|
+
#define TAR_NOOVERWRITE 4 /* don't overwrite existing files */
|
105
|
+
#define TAR_IGNORE_EOT 8 /* ignore double zero blocks as EOF */
|
106
|
+
#define TAR_CHECK_MAGIC 16 /* check magic in file header */
|
107
|
+
#define TAR_CHECK_VERSION 32 /* check version in file header */
|
108
|
+
#define TAR_IGNORE_CRC 64 /* ignore CRC in file header */
|
109
|
+
|
110
|
+
/* this is obsolete - it's here for backwards-compatibility only */
|
111
|
+
#define TAR_IGNORE_MAGIC 0
|
112
|
+
|
113
|
+
extern const char libtar_version[];
|
114
|
+
|
115
|
+
|
116
|
+
/* open a new tarfile handle */
|
117
|
+
int tar_open(TAR **t, char *pathname, tartype_t *type,
|
118
|
+
int oflags, int mode, int options);
|
119
|
+
|
120
|
+
/* make a tarfile handle out of a previously-opened descriptor */
|
121
|
+
int tar_fdopen(TAR **t, int fd, char *pathname, tartype_t *type,
|
122
|
+
int oflags, int mode, int options);
|
123
|
+
|
124
|
+
/* returns the descriptor associated with t */
|
125
|
+
int tar_fd(TAR *t);
|
126
|
+
|
127
|
+
/* close tarfile handle */
|
128
|
+
int tar_close(TAR *t);
|
129
|
+
|
130
|
+
|
131
|
+
/***** append.c ************************************************************/
|
132
|
+
|
133
|
+
/* forward declaration to appease the compiler */
|
134
|
+
struct tar_dev;
|
135
|
+
|
136
|
+
/* cleanup function */
|
137
|
+
void tar_dev_free(struct tar_dev *tdp);
|
138
|
+
|
139
|
+
/* Appends a file to the tar archive.
|
140
|
+
* Arguments:
|
141
|
+
* t = TAR handle to append to
|
142
|
+
* realname = path of file to append
|
143
|
+
* savename = name to save the file under in the archive
|
144
|
+
*/
|
145
|
+
int tar_append_file(TAR *t, char *realname, char *savename);
|
146
|
+
|
147
|
+
/* write EOF indicator */
|
148
|
+
int tar_append_eof(TAR *t);
|
149
|
+
|
150
|
+
/* add file contents to a tarchive */
|
151
|
+
int tar_append_regfile(TAR *t, char *realname);
|
152
|
+
|
153
|
+
|
154
|
+
/***** block.c *************************************************************/
|
155
|
+
|
156
|
+
/* macros for reading/writing tarchive blocks */
|
157
|
+
#define tar_block_read(t, buf) \
|
158
|
+
(*((t)->type->readfunc))((t)->fd, (char *)(buf), T_BLOCKSIZE)
|
159
|
+
#define tar_block_write(t, buf) \
|
160
|
+
(*((t)->type->writefunc))((t)->fd, (char *)(buf), T_BLOCKSIZE)
|
161
|
+
|
162
|
+
/* read/write a header block */
|
163
|
+
int th_read(TAR *t);
|
164
|
+
int th_write(TAR *t);
|
165
|
+
|
166
|
+
|
167
|
+
/***** decode.c ************************************************************/
|
168
|
+
|
169
|
+
/* determine file type */
|
170
|
+
#define TH_ISREG(t) ((t)->th_buf.typeflag == REGTYPE \
|
171
|
+
|| (t)->th_buf.typeflag == AREGTYPE \
|
172
|
+
|| (t)->th_buf.typeflag == CONTTYPE \
|
173
|
+
|| (S_ISREG((mode_t)oct_to_int((t)->th_buf.mode)) \
|
174
|
+
&& (t)->th_buf.typeflag != LNKTYPE))
|
175
|
+
#define TH_ISLNK(t) ((t)->th_buf.typeflag == LNKTYPE)
|
176
|
+
#define TH_ISSYM(t) ((t)->th_buf.typeflag == SYMTYPE \
|
177
|
+
|| S_ISLNK((mode_t)oct_to_int((t)->th_buf.mode)))
|
178
|
+
#define TH_ISCHR(t) ((t)->th_buf.typeflag == CHRTYPE \
|
179
|
+
|| S_ISCHR((mode_t)oct_to_int((t)->th_buf.mode)))
|
180
|
+
#define TH_ISBLK(t) ((t)->th_buf.typeflag == BLKTYPE \
|
181
|
+
|| S_ISBLK((mode_t)oct_to_int((t)->th_buf.mode)))
|
182
|
+
#define TH_ISDIR(t) ((t)->th_buf.typeflag == DIRTYPE \
|
183
|
+
|| S_ISDIR((mode_t)oct_to_int((t)->th_buf.mode)) \
|
184
|
+
|| ((t)->th_buf.typeflag == AREGTYPE \
|
185
|
+
&& ((t)->th_buf.name[strlen((t)->th_buf.name) - 1] == '/')))
|
186
|
+
#define TH_ISFIFO(t) ((t)->th_buf.typeflag == FIFOTYPE \
|
187
|
+
|| S_ISFIFO((mode_t)oct_to_int((t)->th_buf.mode)))
|
188
|
+
#define TH_ISLONGNAME(t) ((t)->th_buf.typeflag == GNU_LONGNAME_TYPE)
|
189
|
+
#define TH_ISLONGLINK(t) ((t)->th_buf.typeflag == GNU_LONGLINK_TYPE)
|
190
|
+
|
191
|
+
/* decode tar header info */
|
192
|
+
#define th_get_crc(t) oct_to_int((t)->th_buf.chksum)
|
193
|
+
#define th_get_size(t) oct_to_int((t)->th_buf.size)
|
194
|
+
#define th_get_mtime(t) oct_to_int((t)->th_buf.mtime)
|
195
|
+
#define th_get_devmajor(t) oct_to_int((t)->th_buf.devmajor)
|
196
|
+
#define th_get_devminor(t) oct_to_int((t)->th_buf.devminor)
|
197
|
+
#define th_get_linkname(t) ((t)->th_buf.gnu_longlink \
|
198
|
+
? (t)->th_buf.gnu_longlink \
|
199
|
+
: (t)->th_buf.linkname)
|
200
|
+
char *th_get_pathname(TAR *t);
|
201
|
+
mode_t th_get_mode(TAR *t);
|
202
|
+
uid_t th_get_uid(TAR *t);
|
203
|
+
gid_t th_get_gid(TAR *t);
|
204
|
+
|
205
|
+
|
206
|
+
/***** encode.c ************************************************************/
|
207
|
+
|
208
|
+
/* encode file info in th_header */
|
209
|
+
void th_set_type(TAR *t, mode_t mode);
|
210
|
+
void th_set_path(TAR *t, char *pathname);
|
211
|
+
void th_set_link(TAR *t, char *linkname);
|
212
|
+
void th_set_device(TAR *t, dev_t device);
|
213
|
+
void th_set_user(TAR *t, uid_t uid);
|
214
|
+
void th_set_group(TAR *t, gid_t gid);
|
215
|
+
void th_set_mode(TAR *t, mode_t fmode);
|
216
|
+
#define th_set_mtime(t, fmtime) \
|
217
|
+
int_to_oct_nonull((fmtime), (t)->th_buf.mtime, 12)
|
218
|
+
#define th_set_size(t, fsize) \
|
219
|
+
int_to_oct_nonull((fsize), (t)->th_buf.size, 12)
|
220
|
+
|
221
|
+
/* encode everything at once (except the pathname and linkname) */
|
222
|
+
void th_set_from_stat(TAR *t, struct stat *s);
|
223
|
+
|
224
|
+
/* encode magic, version, and crc - must be done after everything else is set */
|
225
|
+
void th_finish(TAR *t);
|
226
|
+
|
227
|
+
|
228
|
+
/***** extract.c ***********************************************************/
|
229
|
+
|
230
|
+
/* sequentially extract next file from t */
|
231
|
+
int tar_extract_file(TAR *t, char *realname);
|
232
|
+
|
233
|
+
// modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
234
|
+
int tar_extract_function(TAR *t, void *data, int (*f)(char *b, int l, void *d));
|
235
|
+
|
236
|
+
/* extract different file types */
|
237
|
+
int tar_extract_dir(TAR *t, char *realname);
|
238
|
+
int tar_extract_hardlink(TAR *t, char *realname);
|
239
|
+
int tar_extract_symlink(TAR *t, char *realname);
|
240
|
+
int tar_extract_chardev(TAR *t, char *realname);
|
241
|
+
int tar_extract_blockdev(TAR *t, char *realname);
|
242
|
+
int tar_extract_fifo(TAR *t, char *realname);
|
243
|
+
|
244
|
+
/* for regfiles, we need to extract the content blocks as well */
|
245
|
+
int tar_extract_regfile(TAR *t, char *realname);
|
246
|
+
int tar_skip_regfile(TAR *t);
|
247
|
+
|
248
|
+
|
249
|
+
/***** output.c ************************************************************/
|
250
|
+
|
251
|
+
/* print the tar header */
|
252
|
+
void th_print(TAR *t);
|
253
|
+
|
254
|
+
/* print "ls -l"-like output for the file described by th */
|
255
|
+
void th_print_long_ls(TAR *t);
|
256
|
+
|
257
|
+
|
258
|
+
/***** util.c *************************************************************/
|
259
|
+
|
260
|
+
/* hashing function for pathnames */
|
261
|
+
int path_hashfunc(char *key, int numbuckets);
|
262
|
+
|
263
|
+
/* matching function for dev_t's */
|
264
|
+
int dev_match(dev_t *dev1, dev_t *dev2);
|
265
|
+
|
266
|
+
/* matching function for ino_t's */
|
267
|
+
int ino_match(ino_t *ino1, ino_t *ino2);
|
268
|
+
|
269
|
+
/* hashing function for dev_t's */
|
270
|
+
int dev_hash(dev_t *dev);
|
271
|
+
|
272
|
+
/* hashing function for ino_t's */
|
273
|
+
int ino_hash(ino_t *inode);
|
274
|
+
|
275
|
+
/* create any necessary dirs */
|
276
|
+
int mkdirhier(char *path);
|
277
|
+
|
278
|
+
/* calculate header checksum */
|
279
|
+
int th_crc_calc(TAR *t);
|
280
|
+
#define th_crc_ok(t) (th_get_crc(t) == th_crc_calc(t))
|
281
|
+
|
282
|
+
/* string-octal to integer conversion */
|
283
|
+
int oct_to_int(char *oct);
|
284
|
+
|
285
|
+
/* integer to NULL-terminated string-octal conversion */
|
286
|
+
// modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
287
|
+
//#define int_to_oct(num, oct, octlen) \
|
288
|
+
// snprintf((oct), (octlen), "%*lo ", (octlen) - 2, (unsigned long)(num))
|
289
|
+
#define int_to_oct(num, oct, octlen) \
|
290
|
+
snprintf((oct), (octlen), "%0*lo", (octlen) - 1, (unsigned long)(num))
|
291
|
+
|
292
|
+
/* integer to string-octal conversion, no NULL */
|
293
|
+
void int_to_oct_nonull(int num, char *oct, size_t octlen);
|
294
|
+
|
295
|
+
|
296
|
+
/***** wrapper.c **********************************************************/
|
297
|
+
|
298
|
+
/* extract groups of files */
|
299
|
+
int tar_extract_glob(TAR *t, char *globname, char *prefix);
|
300
|
+
int tar_extract_all(TAR *t, char *prefix);
|
301
|
+
|
302
|
+
/* add a whole tree of files */
|
303
|
+
int tar_append_tree(TAR *t, char *realdir, char *savedir);
|
304
|
+
|
305
|
+
|
306
|
+
#ifdef __cplusplus
|
307
|
+
}
|
308
|
+
#endif
|
309
|
+
|
310
|
+
#endif /* ! LIBTAR_H */
|
311
|
+
|
@@ -0,0 +1,146 @@
|
|
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 *filename;
|
66
|
+
char modestring[12];
|
67
|
+
#ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
68
|
+
struct passwd *pw;
|
69
|
+
struct group *gr;
|
70
|
+
#endif
|
71
|
+
uid_t uid;
|
72
|
+
gid_t gid;
|
73
|
+
char username[_POSIX_LOGIN_NAME_MAX];
|
74
|
+
char groupname[_POSIX_LOGIN_NAME_MAX];
|
75
|
+
time_t mtime;
|
76
|
+
struct tm *mtm;
|
77
|
+
|
78
|
+
#ifdef HAVE_STRFTIME
|
79
|
+
char timebuf[18];
|
80
|
+
#else
|
81
|
+
const char *months[] = {
|
82
|
+
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
83
|
+
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
84
|
+
};
|
85
|
+
#endif
|
86
|
+
|
87
|
+
uid = th_get_uid(t);
|
88
|
+
#ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
89
|
+
pw = getpwuid(uid);
|
90
|
+
if (pw == NULL)
|
91
|
+
snprintf(username, sizeof(username), "%d", uid);
|
92
|
+
else
|
93
|
+
strlcpy(username, pw->pw_name, sizeof(username));
|
94
|
+
#else
|
95
|
+
snprintf(username, sizeof(username), "%d", uid);
|
96
|
+
#endif
|
97
|
+
|
98
|
+
gid = th_get_gid(t);
|
99
|
+
#ifndef _WIN32 // modified by SUGAWARA Genki <sgwr_dts@yahoo.co.jp>
|
100
|
+
gr = getgrgid(gid);
|
101
|
+
if (gr == NULL)
|
102
|
+
snprintf(groupname, sizeof(groupname), "%d", gid);
|
103
|
+
else
|
104
|
+
strlcpy(groupname, gr->gr_name, sizeof(groupname));
|
105
|
+
#else
|
106
|
+
snprintf(groupname, sizeof(groupname), "%d", gid);
|
107
|
+
#endif
|
108
|
+
strmode(th_get_mode(t), modestring);
|
109
|
+
printf("%.10s %-8.8s %-8.8s ", modestring, username, groupname);
|
110
|
+
|
111
|
+
if (TH_ISCHR(t) || TH_ISBLK(t))
|
112
|
+
printf(" %3d, %3d ", th_get_devmajor(t), th_get_devminor(t));
|
113
|
+
else
|
114
|
+
printf("%9ld ", (long)th_get_size(t));
|
115
|
+
|
116
|
+
mtime = th_get_mtime(t);
|
117
|
+
mtm = localtime(&mtime);
|
118
|
+
#ifdef HAVE_STRFTIME
|
119
|
+
strftime(timebuf, sizeof(timebuf), "%h %e %H:%M %Y", mtm);
|
120
|
+
printf("%s", timebuf);
|
121
|
+
#else
|
122
|
+
printf("%.3s %2d %2d:%02d %4d",
|
123
|
+
months[mtm->tm_mon],
|
124
|
+
mtm->tm_mday, mtm->tm_hour, mtm->tm_min, mtm->tm_year + 1900);
|
125
|
+
#endif
|
126
|
+
|
127
|
+
filename = th_get_pathname(t);
|
128
|
+
printf(" %s", filename);
|
129
|
+
free(filename);
|
130
|
+
|
131
|
+
if (TH_ISSYM(t) || TH_ISLNK(t))
|
132
|
+
{
|
133
|
+
if (TH_ISSYM(t))
|
134
|
+
printf(" -> ");
|
135
|
+
else
|
136
|
+
printf(" link to ");
|
137
|
+
if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL)
|
138
|
+
printf("%s", t->th_buf.gnu_longlink);
|
139
|
+
else
|
140
|
+
printf("%.100s", t->th_buf.linkname);
|
141
|
+
}
|
142
|
+
|
143
|
+
putchar('\n');
|
144
|
+
}
|
145
|
+
|
146
|
+
|