]> cygwin.com Git - cygwin-apps/setup.git/blob - archive_tar.h
2002-04-27 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 String next_file_name ()
92 {
93 return NULL;
94 };
95 virtual int get_mtime ();
96 virtual size_t get_size () {return state.file_length;};
97 virtual int set_mtime (int)
98 {
99 return 1;
100 };
101 virtual ~ archive_tar_file ();
102 private:
103 tar_state & state;
104 };
105
106 class archive_tar:public archive
107 {
108 public:
109 archive_tar (io_stream * original);
110 virtual io_stream *extract_file ();
111 /* read data (duh!) */
112 virtual ssize_t read (void *buffer, size_t len);
113 /* provide data to (double duh!) */
114 virtual ssize_t write (const void *buffer, size_t len);
115 /* read data without removing it from the class's internal buffer */
116 virtual ssize_t peek (void *buffer, size_t len);
117 virtual long tell ();
118 virtual int seek (long where, io_stream_seek_t whence);
119 /* try guessing this one */
120 virtual int error ();
121 /* Find out the next stream name -
122 * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar
123 * for foobar that is an compress, next_file_name is the next
124 * extractable filename.
125 */
126 virtual String const next_file_name ();
127 virtual archive_file_t next_file_type ();
128 /* returns the mtime of the archive file, not of the current file */
129 virtual int get_mtime ();
130 /* nonsense for a tarball */
131 virtual size_t get_size () {return 0;};
132 /* only of use when we support writing to tar */
133 virtual int set_mtime (int)
134 {
135 return 1;
136 };
137 virtual String const linktarget ();
138 virtual int skip_file ();
139 /* if you are still needing these hints... give up now! */
140 virtual ~ archive_tar ();
141 archive_tar& operator= (const archive_tar &);
142 archive_tar (archive_tar const &);
143 private:
144 archive_tar ()
145 {
146 };
147 tar_state state;
148 unsigned int archive_children;
149 };
150
151 /* Only one tarfile may be open at a time. gzipped files handled
152 automatically */
153
154 /* returns zero on success, nonzero on failure */
155 //int tar_open (const char *pathname);
156
157 /* pass adjusted path, returns zero on success, nonzero on failure */
158 //int tar_read_file (char *path);
159
160
161 #if 0
162 /* pass path to tar file and from/to pairs for path prefix (NULLs at
163 end , returns zero if completely successful, nonzero (counts
164 errors) on failure */
165 int tar_auto (char *pathname, char **map);
166 #endif
167
168
169 //int tar_mkdir_p (int isadir, char *path);
170
171 /*
172 extern int _tar_verbose;
173 extern FILE * _tar_vfile;
174 */
175
176 #endif
This page took 0.04289 seconds and 5 git commands to generate.