~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Utilities/cmtar/libtar.h

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2006-06-18 16:34:11 UTC
  • mfrom: (1.4.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060618163411-pi234s3v6jwlcmof
Tags: 2.4.2-1
* New upstream release (Closes: #338324)
* Put cmake .vim files into /usr/share/vim/addons/plugin/
  where they can be used. (Closes: #366663)
* Install cmake-mode.el so it can be used. (Closes: #366664)
* Ensure cmake FindKDE locates KDE libraries on Debian
  based distributions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <libtar/tar.h>
 
19
 
 
20
#include <libtar/libtar_listhash.h>
 
21
#include <libtar/compat.h>
 
22
#ifdef __cplusplus
 
23
extern "C" {
 
24
#endif
 
25
 
 
26
 
 
27
/* useful constants */
 
28
#define T_BLOCKSIZE    512
 
29
#define T_NAMELEN    100
 
30
#define T_PREFIXLEN    155
 
31
#define T_MAXPATHLEN    (T_NAMELEN + T_PREFIXLEN)
 
32
 
 
33
/* GNU extensions for typeflag */
 
34
#define GNU_LONGNAME_TYPE  'L'
 
35
#define GNU_LONGLINK_TYPE  'K'
 
36
 
 
37
/* our version of the tar header structure */
 
38
struct tar_header
 
39
{
 
40
  char name[100];
 
41
  char mode[8];
 
42
  char uid[8];
 
43
  char gid[8];
 
44
  char size[12];
 
45
  char mtime[12];
 
46
  char chksum[8];
 
47
  char typeflag;
 
48
  char linkname[100];
 
49
  char magic[6];
 
50
  char version[2];
 
51
  char uname[32];
 
52
  char gname[32];
 
53
  char devmajor[8];
 
54
  char devminor[8];
 
55
  char prefix[155];
 
56
  char padding[12];
 
57
  char *gnu_longname;
 
58
  char *gnu_longlink;
 
59
};
 
60
 
 
61
 
 
62
/***** handle.c ************************************************************/
 
63
 
 
64
typedef int (*openfunc_t)(void* call_data, const char *, int, mode_t);
 
65
typedef int (*closefunc_t)(void* call_data);
 
66
typedef ssize_t (*readfunc_t)(void* call_data, void *, size_t);
 
67
typedef ssize_t (*writefunc_t)(void* call_data, const void *, size_t);
 
68
 
 
69
typedef struct
 
70
{
 
71
  openfunc_t openfunc;
 
72
  closefunc_t closefunc;
 
73
  readfunc_t readfunc;
 
74
  writefunc_t writefunc;
 
75
  void* call_data;
 
76
}
 
77
tartype_t;
 
78
 
 
79
typedef struct
 
80
{
 
81
  tartype_t *type;
 
82
  char *pathname;
 
83
  int oflags;
 
84
  int options;
 
85
  struct tar_header th_buf;
 
86
  libtar_hash_t *h;
 
87
}
 
88
TAR;
 
89
 
 
90
/* constant values for the TAR options field */
 
91
#define TAR_GNU       1  /* use GNU extensions */
 
92
#define TAR_VERBOSE     2  /* output file info to stdout */
 
93
#define TAR_NOOVERWRITE     4  /* don't overwrite existing files */
 
94
#define TAR_IGNORE_EOT     8  /* ignore double zero blocks as EOF */
 
95
#define TAR_CHECK_MAGIC    16  /* check magic in file header */
 
96
#define TAR_CHECK_VERSION  32  /* check version in file header */
 
97
#define TAR_IGNORE_CRC    64  /* ignore CRC in file header */
 
98
 
 
99
/* this is obsolete - it's here for backwards-compatibility only */
 
100
#define TAR_IGNORE_MAGIC  0
 
101
 
 
102
extern const char libtar_version[];
 
103
 
 
104
/* open a new tarfile handle */
 
105
int tar_open(TAR **t, char *pathname, tartype_t *type,
 
106
       int oflags, int mode, int options);
 
107
 
 
108
/* make a tarfile handle out of a previously-opened descriptor */
 
109
int tar_fdopen(TAR **t, int fd, char *pathname, tartype_t *type,
 
110
         int oflags, int mode, int options);
 
111
 
 
112
/* close tarfile handle */
 
113
int tar_close(TAR *t);
 
114
 
 
115
 
 
116
/***** append.c ************************************************************/
 
117
 
 
118
/* forward declaration to appease the compiler */
 
119
struct tar_dev;
 
120
 
 
121
/* cleanup function */
 
122
void tar_dev_free(struct tar_dev *tdp);
 
123
 
 
124
/* Appends a file to the tar archive.
 
125
 * Arguments:
 
126
 *    t        = TAR handle to append to
 
127
 *    realname = path of file to append
 
128
 *    savename = name to save the file under in the archive
 
129
 */
 
130
int tar_append_file(TAR *t, char *realname, char *savename);
 
131
 
 
132
/* write EOF indicator */
 
133
int tar_append_eof(TAR *t);
 
134
 
 
135
/* add file contents to a tarchive */
 
136
int tar_append_regfile(TAR *t, char *realname);
 
137
 
 
138
 
 
139
/***** block.c *************************************************************/
 
140
 
 
141
/* macros for reading/writing tarchive blocks */
 
142
#define tar_block_read(t, buf) \
 
143
  (*((t)->type->readfunc))((t)->type->call_data, (char *)(buf), T_BLOCKSIZE)
 
144
#define tar_block_write(t, buf) \
 
145
  (*((t)->type->writefunc))((t)->type->call_data, (char *)(buf), T_BLOCKSIZE)
 
146
 
 
147
/* read/write a header block */
 
148
int th_read(TAR *t);
 
149
int th_write(TAR *t);
 
150
 
 
151
 
 
152
/***** decode.c ************************************************************/
 
153
 
 
154
/* determine file type */
 
155
#define TH_ISREG(t)  ((t)->th_buf.typeflag == REGTYPE \
 
156
       || (t)->th_buf.typeflag == AREGTYPE \
 
157
       || (t)->th_buf.typeflag == CONTTYPE \
 
158
       || (S_ISREG((mode_t)oct_to_int((t)->th_buf.mode)) \
 
159
           && (t)->th_buf.typeflag != LNKTYPE))
 
160
#define TH_ISLNK(t)  ((t)->th_buf.typeflag == LNKTYPE)
 
161
#define TH_ISSYM(t)  ((t)->th_buf.typeflag == SYMTYPE \
 
162
       || S_ISLNK((mode_t)oct_to_int((t)->th_buf.mode)))
 
163
#define TH_ISCHR(t)  ((t)->th_buf.typeflag == CHRTYPE \
 
164
       || S_ISCHR((mode_t)oct_to_int((t)->th_buf.mode)))
 
165
#define TH_ISBLK(t)  ((t)->th_buf.typeflag == BLKTYPE \
 
166
       || S_ISBLK((mode_t)oct_to_int((t)->th_buf.mode)))
 
167
#define TH_ISDIR(t)  ((t)->th_buf.typeflag == DIRTYPE \
 
168
       || S_ISDIR((mode_t)oct_to_int((t)->th_buf.mode)) \
 
169
       || ((t)->th_buf.typeflag == AREGTYPE \
 
170
           && ((t)->th_buf.name[strlen((t)->th_buf.name) - 1] == '/')))
 
171
#define TH_ISFIFO(t)  ((t)->th_buf.typeflag == FIFOTYPE \
 
172
       || S_ISFIFO((mode_t)oct_to_int((t)->th_buf.mode)))
 
173
#define TH_ISLONGNAME(t)  ((t)->th_buf.typeflag == GNU_LONGNAME_TYPE)
 
174
#define TH_ISLONGLINK(t)  ((t)->th_buf.typeflag == GNU_LONGLINK_TYPE)
 
175
 
 
176
/* decode tar header info */
 
177
#define th_get_crc(t) oct_to_int((t)->th_buf.chksum)
 
178
#define th_get_size(t) oct_to_int((t)->th_buf.size)
 
179
#define th_get_mtime(t) oct_to_int((t)->th_buf.mtime)
 
180
#define th_get_devmajor(t) oct_to_int((t)->th_buf.devmajor)
 
181
#define th_get_devminor(t) oct_to_int((t)->th_buf.devminor)
 
182
#define th_get_linkname(t) ((t)->th_buf.gnu_longlink \
 
183
                            ? (t)->th_buf.gnu_longlink \
 
184
                            : (t)->th_buf.linkname)
 
185
char *th_get_pathname(TAR *t);
 
186
mode_t th_get_mode(TAR *t);
 
187
uid_t th_get_uid(TAR *t);
 
188
gid_t th_get_gid(TAR *t);
 
189
 
 
190
 
 
191
/***** encode.c ************************************************************/
 
192
 
 
193
/* encode file info in th_header */
 
194
void th_set_type(TAR *t, mode_t mode);
 
195
void th_set_path(TAR *t, char *pathname);
 
196
void th_set_link(TAR *t, char *linkname);
 
197
void th_set_device(TAR *t, dev_t device);
 
198
void th_set_user(TAR *t, uid_t uid);
 
199
void th_set_group(TAR *t, gid_t gid);
 
200
void th_set_mode(TAR *t, mode_t fmode);
 
201
#define th_set_mtime(t, fmtime) \
 
202
  int_to_oct_nonull((int)(fmtime), (t)->th_buf.mtime, 12)
 
203
#define th_set_size(t, fsize) \
 
204
  int_to_oct_nonull((int)(fsize), (t)->th_buf.size, 12)
 
205
 
 
206
/* encode everything at once (except the pathname and linkname) */
 
207
void th_set_from_stat(TAR *t, struct stat *s);
 
208
 
 
209
/* encode magic, version, and crc - must be done after everything else is set */
 
210
void th_finish(TAR *t);
 
211
 
 
212
 
 
213
/***** extract.c ***********************************************************/
 
214
 
 
215
/* sequentially extract next file from t */
 
216
int tar_extract_file(TAR *t, char *realname);
 
217
 
 
218
/* extract different file types */
 
219
int tar_extract_dir(TAR *t, char *realname);
 
220
int tar_extract_hardlink(TAR *t, char *realname);
 
221
int tar_extract_symlink(TAR *t, char *realname);
 
222
int tar_extract_chardev(TAR *t, char *realname);
 
223
int tar_extract_blockdev(TAR *t, char *realname);
 
224
int tar_extract_fifo(TAR *t, char *realname);
 
225
 
 
226
/* for regfiles, we need to extract the content blocks as well */
 
227
int tar_extract_regfile(TAR *t, char *realname);
 
228
int tar_skip_regfile(TAR *t);
 
229
 
 
230
 
 
231
/***** output.c ************************************************************/
 
232
 
 
233
/* print the tar header */
 
234
void th_print(TAR *t);
 
235
 
 
236
/* print "ls -l"-like output for the file described by th */
 
237
void th_print_long_ls(TAR *t);
 
238
 
 
239
 
 
240
/***** util.c *************************************************************/
 
241
 
 
242
/* hashing function for pathnames */
 
243
int path_hashfunc(char *key, int numbuckets);
 
244
 
 
245
/* matching function for dev_t's */
 
246
int dev_match(dev_t *dev1, dev_t *dev2);
 
247
 
 
248
/* matching function for ino_t's */
 
249
int ino_match(ino_t *ino1, ino_t *ino2);
 
250
 
 
251
/* hashing function for dev_t's */
 
252
int dev_hash(dev_t *dev);
 
253
 
 
254
/* hashing function for ino_t's */
 
255
int ino_hash(ino_t *inode);
 
256
 
 
257
/* create any necessary dirs */
 
258
int mkdirhier(char *path);
 
259
 
 
260
/* calculate header checksum */
 
261
int th_crc_calc(TAR *t);
 
262
#define th_crc_ok(t) (th_get_crc(t) == th_crc_calc(t))
 
263
 
 
264
/* string-octal to integer conversion */
 
265
int oct_to_int(char *oct);
 
266
 
 
267
/* integer to NULL-terminated string-octal conversion */
 
268
#define int_to_oct(num, oct, octlen) \
 
269
  snprintf((oct), (octlen), "%*lo ", (octlen) - 2, (unsigned long)(num))
 
270
 
 
271
/* integer to string-octal conversion, no NULL */
 
272
void int_to_oct_nonull(int num, char *oct, size_t octlen);
 
273
 
 
274
 
 
275
/***** wrapper.c **********************************************************/
 
276
 
 
277
/* extract groups of files */
 
278
int tar_extract_glob(TAR *t, char *globname, char *prefix);
 
279
int tar_extract_all(TAR *t, char *prefix);
 
280
 
 
281
/* add a whole tree of files */
 
282
int tar_append_tree(TAR *t, char *realdir, char *savedir);
 
283
 
 
284
 
 
285
#ifdef __cplusplus
 
286
}
 
287
#endif
 
288
 
 
289
#endif /* ! LIBTAR_H */
 
290