2 * Copyright (c) 2000, Red Hat, Inc.
3 * Copyright (c) 2002, Robert Collins.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * A copy of the GNU General Public License can be found at
13 * Written by DJ Delorie <dj@cygnus.com>
14 * Made OOP by R Collins <rbtcollins@hotmail.com>
21 #include "io_stream.h"
28 char name
[100]; /* 0 */
29 char mode
[8]; /* 100 */
30 char uid
[8]; /* 108 */
31 char gid
[8]; /* 116 */
32 char size
[12]; /* 124 */
33 char mtime
[12]; /* 136 */
34 char chksum
[8]; /* 148 */
35 char typeflag
; /* 156 */
36 char linkname
[100]; /* 157 */
37 char magic
[6]; /* 257 */
38 char version
[2]; /* 263 */
39 char uname
[32]; /* 265 */
40 char gname
[32]; /* 297 */
41 char devmajor
[8]; /* 329 */
42 char devminor
[8]; /* 337 */
43 char prefix
[155]; /* 345 */
44 char junk
[12]; /* 500 */
48 typedef struct tar_map_result_type_s
50 struct tar_map_result_type_s
*next
;
59 tar_state ():lasterr (0), eocf (0), have_longname ('\0'), file_offset (0),
60 file_length (0), header_read (0)
64 tar_map_result
= NULL
;
70 /* where in the current file are we? */
74 tar_header_type tar_header
;
75 char filename
[_MAX_PATH
+ 512];
76 tar_map_result_type
*tar_map_result
;
79 class archive_tar_file
:public io_stream
82 archive_tar_file (tar_state
&);
83 virtual ssize_t
read (void *buffer
, size_t len
);
84 /* provide data to (double duh!) */
85 virtual ssize_t
write (const void *buffer
, size_t len
);
86 /* read data without removing it from the class's internal buffer */
87 virtual ssize_t
peek (void *buffer
, size_t len
);
89 virtual int seek (long where
, io_stream_seek_t whence
);
90 /* try guessing this one */
92 virtual int get_mtime ();
93 virtual size_t get_size () {return state
.file_length
;};
94 virtual int set_mtime (int)
98 virtual ~ archive_tar_file ();
103 class archive_tar
:public archive
106 archive_tar (io_stream
* original
);
107 virtual io_stream
*extract_file ();
108 /* read data (duh!) */
109 virtual ssize_t
read (void *buffer
, size_t len
);
110 /* provide data to (double duh!) */
111 virtual ssize_t
write (const void *buffer
, size_t len
);
112 /* read data without removing it from the class's internal buffer */
113 virtual ssize_t
peek (void *buffer
, size_t len
);
114 virtual long tell ();
115 virtual int seek (long where
, io_stream_seek_t whence
);
116 /* try guessing this one */
117 virtual int error ();
118 /* Find out the next stream name -
119 * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar
120 * for foobar that is an compress, next_file_name is the next
121 * extractable filename.
123 virtual String
const next_file_name ();
124 virtual archive_file_t
next_file_type ();
125 /* returns the mtime of the archive file, not of the current file */
126 virtual int get_mtime ();
127 /* nonsense for a tarball */
128 virtual size_t get_size () {return 0;};
129 /* only of use when we support writing to tar */
130 virtual int set_mtime (int)
134 virtual String
const linktarget ();
135 virtual int skip_file ();
136 /* if you are still needing these hints... give up now! */
137 virtual ~ archive_tar ();
138 archive_tar
& operator= (const archive_tar
&);
139 archive_tar (archive_tar
const &);
145 unsigned int archive_children
;
148 /* Only one tarfile may be open at a time. gzipped files handled
151 /* returns zero on success, nonzero on failure */
152 //int tar_open (const char *pathname);
154 /* pass adjusted path, returns zero on success, nonzero on failure */
155 //int tar_read_file (char *path);
159 /* pass path to tar file and from/to pairs for path prefix (NULLs at
160 end , returns zero if completely successful, nonzero (counts
161 errors) on failure */
162 int tar_auto (char *pathname
, char **map
);
166 //int tar_mkdir_p (int isadir, char *path);
169 extern int _tar_verbose;
170 extern FILE * _tar_vfile;