summaryrefslogtreecommitdiff
path: root/lib/tarfn.h
blob: 469d47699d5c40130041d884264d27e35df0adbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef	_TAR_FUNCTION_H_
#define	_TAR_FUNCTION_H_

/*
 * Functions for extracting tar archives.
 * Bruce Perens, April-May 1995
 * Copyright © 1995 Bruce Perens
 * This is free software under the GNU General Public License.
 */

#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

enum tar_format {
	tar_format_old,
	tar_format_gnu,
	tar_format_ustar,
	tar_format_pax,
};

enum TarFileType {
	NormalFile0 = '\0',	/* For compatibility with decades-old bug */
	NormalFile1 = '0',
	HardLink = '1',
	SymbolicLink = '2',
	CharacterDevice = '3',
	BlockDevice = '4',
	Directory = '5',
	FIFO = '6',
	GNU_LONGLINK = 'K',
	GNU_LONGNAME = 'L'
};
typedef enum TarFileType	TarFileType;

struct	TarInfo {
	enum tar_format	format;		/* Tar archive format. */
	void *		UserData;	/* User passed this in as argument */
	char *		Name;		/* File name */
	mode_t		Mode;		/* Unix mode, including device bits. */
	size_t		Size;		/* Size of file */
	time_t		ModTime;	/* Last-modified time */
	TarFileType	Type;		/* Regular, Directory, Special, Link */
	char *		LinkName;	/* Name for symbolic and hard links */
	dev_t		Device;		/* Special device for mknod() */
	uid_t		UserID;		/* Numeric UID */
	gid_t		GroupID;	/* Numeric GID */
};
typedef struct TarInfo	TarInfo;

typedef	int	(*TarReadFunction)(void * userData, char * buffer, int length);

typedef int	(*TarFunction)(TarInfo * h);

struct TarFunctions {
	TarReadFunction	Read;
	TarFunction	ExtractFile;
	TarFunction	MakeDirectory;
	TarFunction	MakeHardLink;
	TarFunction	MakeSymbolicLink;
	TarFunction	MakeSpecialFile;
};
typedef struct TarFunctions	TarFunctions;

extern int	TarExtractor(void * userData, const TarFunctions * functions);

#endif