Fix MD5sum.str () formatting bug
[cygwin-setup.git] / archive_tar.h
blobcc0a46c2c11d2311a2bb7ad2464bc0921a782da6
1 /*
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
11 * http://www.gnu.org/
13 * Written by DJ Delorie <dj@cygnus.com>
14 * Made OOP by R Collins <rbtcollins@hotmail.com>
18 #ifndef SETUP_ARCHIVE_TAR_H
19 #define SETUP_ARCHIVE_TAR_H
21 #include "io_stream.h"
22 #include "archive.h"
23 #include "win32.h"
25 typedef struct
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 */
45 tar_header_type;
47 typedef struct tar_map_result_type_s
49 struct tar_map_result_type_s *next;
50 std::string stored_name;
51 std::string mapped_name;
53 tar_map_result_type;
55 class tar_state
57 public:
58 tar_state ():lasterr (0), eocf (0), have_longname ('\0'), file_offset (0),
59 file_length (0), header_read (0)
61 parent = NULL;
62 filename[0] = '\0';
63 tar_map_result = NULL;
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[CYG_PATH_MAX + 512];
75 tar_map_result_type *tar_map_result;
78 class archive_tar_file:public io_stream
80 private:
81 bool read_something;
82 public:
83 archive_tar_file (tar_state &);
84 virtual ssize_t read (void *buffer, size_t len);
85 /* provide data to (double duh!) */
86 virtual ssize_t write (const void *buffer, size_t len);
87 /* read data without removing it from the class's internal buffer */
88 virtual ssize_t peek (void *buffer, size_t len);
89 virtual long tell ();
90 virtual int seek (long where, io_stream_seek_t whence);
91 /* try guessing this one */
92 virtual int error ();
93 virtual time_t get_mtime ();
94 virtual mode_t get_mode ();
95 virtual size_t get_size () {return state.file_length;};
96 virtual int set_mtime (time_t) { return 1; };
97 virtual ~ archive_tar_file ();
98 private:
99 tar_state & state;
102 class archive_tar:public archive
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.
122 virtual const std::string 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 time_t get_mtime ();
126 virtual mode_t get_mode ();
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 (time_t) { return 1; };
131 virtual const std::string linktarget ();
132 virtual int skip_file ();
133 /* if you are still needing these hints... give up now! */
134 virtual ~ archive_tar ();
135 archive_tar& operator= (const archive_tar &);
136 archive_tar (archive_tar const &);
137 private:
138 archive_tar ()
141 tar_state state;
142 unsigned int archive_children;
145 /* Only one tarfile may be open at a time. gzipped files handled
146 automatically */
148 /* returns zero on success, nonzero on failure */
149 //int tar_open (const char *pathname);
151 /* pass adjusted path, returns zero on success, nonzero on failure */
152 //int tar_read_file (char *path);
155 #if 0
156 /* pass path to tar file and from/to pairs for path prefix (NULLs at
157 end , returns zero if completely successful, nonzero (counts
158 errors) on failure */
159 int tar_auto (char *pathname, char **map);
160 #endif
163 //int tar_mkdir_p (int isadir, char *path);
166 extern int _tar_verbose;
167 extern FILE * _tar_vfile;
170 #endif /* SETUP_ARCHIVE_TAR_H */