]> cygwin.com Git - cygwin-apps/setup.git/blob - archive_tar.h
2002-05-04 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / archive_tar.h
1 /*
2 * Copyright (c) 2000, Red Hat, Inc.
3 * Copyright (c) 2002, Robert Collins.
4 *
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.
9 *
10 * A copy of the GNU General Public License can be found at
11 * http://www.gnu.org/
12 *
13 * Written by DJ Delorie <dj@cygnus.com>
14 * Made OOP by R Collins <rbtcollins@hotmail.com>
15 *
16 */
17
18 #ifndef __TAR_H_
19 #define __TAR_H_
20
21 #include "io_stream.h"
22 #include "archive.h"
23 #include "String++.h"
24
25 typedef struct
26 {
27 char name[100]; /* 0 */
28 char mode[8]; /* 100 */
29 char uid[8]; /* 108 */
30 char gid[8]; /* 116 */
31 char size[12]; /* 124 */
32 char mtime[12]; /* 136 */
33 char chksum[8]; /* 148 */
34 char typeflag; /* 156 */
35 char linkname[100]; /* 157 */
36 char magic[6]; /* 257 */
37 char version[2]; /* 263 */
38 char uname[32]; /* 265 */
39 char gname[32]; /* 297 */
40 char devmajor[8]; /* 329 */
41 char devminor[8]; /* 337 */
42 char prefix[155]; /* 345 */
43 char junk[12]; /* 500 */
44 }
45 tar_header_type;
46
47 typedef struct tar_map_result_type_s
48 {
49 struct tar_map_result_type_s *next;
50 String stored_name;
51 String mapped_name;
52 }
53 tar_map_result_type;
54
55 class tar_state
56 {
57 public:
58 tar_state ():lasterr (0), eocf (0), have_longname ('\0'), file_offset (0),
59 file_length (0), header_read (0)
60 {
61 parent = NULL;
62 filename[0] = '\0';
63 tar_map_result = NULL;
64 };
65 io_stream *parent;
66 int lasterr;
67 int eocf;
68 char have_longname;
69 /* where in the current file are we? */
70 size_t file_offset;
71 size_t file_length;
72 int header_read;
73 tar_header_type tar_header;
74 char filename[_MAX_PATH + 512];
75 tar_map_result_type *tar_map_result;
76 };
77
78 class archive_tar_file:public io_stream
79 {
80 public:
81 archive_tar_file (tar_state &);
82 virtual ssize_t read (void *buffer, size_t len);
83 /* provide data to (double duh!) */
84 virtual ssize_t write (const void *buffer, size_t len);
85 /* read data without removing it from the class's internal buffer */
86 virtual ssize_t peek (void *buffer, size_t len);
87 virtual long tell ();
88 virtual int seek (long where, io_stream_seek_t whence);
89 /* try guessing this one */
90 virtual int error ();
91 virtual int get_mtime ();
92 virtual size_t get_size () {return state.file_length;};
93 virtual int set_mtime (int)
94 {
95 return 1;
96 };
97 virtual ~ archive_tar_file ();
98 private:
99 tar_state & state;
100 };
101
102 class archive_tar:public archive
103 {
104 public:
105 archive_tar (io_stream * original);
106 virtual io_stream *extract_file ();
107 /* read data (duh!) */
108 virtual ssize_t read (void *buffer, size_t len);
109 /* provide data to (double duh!) */
110 virtual ssize_t write (const void *buffer, size_t len);
111 /* read data without removing it from the class's internal buffer */
112 virtual ssize_t peek (void *buffer, size_t len);
113 virtual long tell ();
114 virtual int seek (long where, io_stream_seek_t whence);
115 /* try guessing this one */
116 virtual int error ();
117 /* Find out the next stream name -
118 * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar
119 * for foobar that is an compress, next_file_name is the next
120 * extractable filename.
121 */
122 virtual String const next_file_name ();
123 virtual archive_file_t next_file_type ();
124 /* returns the mtime of the archive file, not of the current file */
125 virtual int get_mtime ();
126 /* nonsense for a tarball */
127 virtual size_t get_size () {return 0;};
128 /* only of use when we support writing to tar */
129 virtual int set_mtime (int)
130 {
131 return 1;
132 };
133 virtual String const linktarget ();
134 virtual int skip_file ();
135 /* if you are still needing these hints... give up now! */
136 virtual ~ archive_tar ();
137 archive_tar& operator= (const archive_tar &);
138 archive_tar (archive_tar const &);
139 private:
140 archive_tar ()
141 {
142 };
143 tar_state state;
144 unsigned int archive_children;
145 };
146
147 /* Only one tarfile may be open at a time. gzipped files handled
148 automatically */
149
150 /* returns zero on success, nonzero on failure */
151 //int tar_open (const char *pathname);
152
153 /* pass adjusted path, returns zero on success, nonzero on failure */
154 //int tar_read_file (char *path);
155
156
157 #if 0
158 /* pass path to tar file and from/to pairs for path prefix (NULLs at
159 end , returns zero if completely successful, nonzero (counts
160 errors) on failure */
161 int tar_auto (char *pathname, char **map);
162 #endif
163
164
165 //int tar_mkdir_p (int isadir, char *path);
166
167 /*
168 extern int _tar_verbose;
169 extern FILE * _tar_vfile;
170 */
171
172 #endif
This page took 0.040205 seconds and 5 git commands to generate.