summaryrefslogtreecommitdiffstats
path: root/lib/dpkg/buffer.h
blob: e29766014478f63694652d61000053667df61658 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * libdpkg - Debian packaging suite library routines
 * buffer.h - buffer I/O handling routines
 *
 * Copyright © 1999, 2000 Wichert Akkerman <wakkerma@debian.org>
 * Copyright © 2000-2003 Adam Heath <doogie@debian.org>
 * Copyright © 2005 Scott James Remnant
 * Copyright © 2008-2011 Guillem Jover <guillem@debian.org>
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef LIBDPKG_BUFFER_H
#define LIBDPKG_BUFFER_H

#include <sys/types.h>

#include <dpkg/macros.h>
#include <dpkg/error.h>

DPKG_BEGIN_DECLS

/**
 * @defgroup buffer Buffer I/O
 * @ingroup dpkg-internal
 * @{
 */

#define DPKG_BUFFER_SIZE		(32 * 1024)

#define BUFFER_WRITE_VBUF		1
#define BUFFER_WRITE_FD			2
#define BUFFER_WRITE_NULL		3

#define BUFFER_DIGEST_NULL		4
#define BUFFER_DIGEST_MD5		5

#define BUFFER_READ_FD			0

struct buffer_data {
	union {
		void *ptr;
		int i;
	} arg;
	int type;
};

# define buffer_md5(buf, hash, limit) \
	buffer_digest(buf, hash, BUFFER_DIGEST_MD5, limit)

# define fd_md5(fd, hash, limit, err) \
	buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
	                   hash, BUFFER_DIGEST_MD5, \
	                   NULL, BUFFER_WRITE_NULL, \
	                   limit, err)
# define fd_fd_copy(fd1, fd2, limit, err) \
	buffer_copy_IntInt(fd1, BUFFER_READ_FD, \
	                   NULL, BUFFER_DIGEST_NULL, \
	                   fd2, BUFFER_WRITE_FD, \
	                   limit, err)
# define fd_fd_copy_and_md5(fd1, fd2, hash, limit, err) \
	buffer_copy_IntInt(fd1, BUFFER_READ_FD, \
	                   hash, BUFFER_DIGEST_MD5, \
	                   fd2, BUFFER_WRITE_FD, \
	                   limit, err)
# define fd_vbuf_copy(fd, buf, limit, err) \
	buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
	                   NULL, BUFFER_DIGEST_NULL, \
	                   buf, BUFFER_WRITE_VBUF, \
	                   limit, err)
# define fd_skip(fd, limit, err) \
	buffer_skip_Int(fd, BUFFER_READ_FD, limit, err)


off_t buffer_copy_IntPtr(int i, int typeIn,
                         void *f, int typeDigest,
                         void *p, int typeOut,
                         off_t limit, struct dpkg_error *err)
	DPKG_ATTR_REQRET;
off_t buffer_copy_IntInt(int i1, int typeIn,
                         void *f, int typeDigest,
                         int i2, int typeOut,
                         off_t limit, struct dpkg_error *err)
	DPKG_ATTR_REQRET;
off_t buffer_skip_Int(int I, int T, off_t limit, struct dpkg_error *err)
	DPKG_ATTR_REQRET;
off_t buffer_digest(const void *buf, void *hash, int typeDigest, off_t length);

/** @} */

DPKG_END_DECLS

#endif /* LIBDPKG_BUFFER_H */