~ubuntu-branches/ubuntu/lucid/dpkg/lucid

« back to all changes in this revision

Viewing changes to lib/dpkg/buffer.h

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2009-09-18 13:39:36 UTC
  • mfrom: (1.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20090918133936-dj8kjtc2qz3yqj7i
Tags: 1.15.4ubuntu1
* Resynchronise with Debian (LP: #427854). Remaining changes:
  Ubuntu-specific adjustments (probably):
  - Use i686 for lpia in cputable and triplettable.
  - Hack Dpkg::Arch to return i686 for lpia.
  - Move various Conflicts to Breaks, since upgrades from stable Ubuntu
    releases support Breaks.

  Miscellaneous bug fixes:
  - Avoid duplicate attempts to [f]close in obscure error situations which
    might conceiveably close wrong fds.
  - Revert change to stop outputting a newline after a postinst is run
    (Debian #392317).
  - Use the two-arg form of open in Dpkg::Control so that "-" can be
    passed to parse stdin as a control file (Debian #465340).

  Launchpad integration:
  - Add Launchpad-Bugs-Fixed handling in a few more places.

  Build options:
  - Point to https://wiki.ubuntu.com/DistCompilerFlags from
    dpkg-buildpackage(1).
  - Set default LDFLAGS to -Wl,-Bsymbolic-functions. (We've already taken
    this hit in Ubuntu.)
  - Implement handling of hardening-wrapper options via DEB_BUILD_OPTIONS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libdpkg - Debian packaging suite library routines
 
3
 * buffer.h - buffer I/O handling routines
 
4
 *
 
5
 * Copyright © 1999, 2000 Wichert Akkerman <wakkerma@debian.org>
 
6
 * Copyright © 2000-2003 Adam Heath <doogie@debian.org>
 
7
 * Copyright © 2005 Scott James Remnant
 
8
 * Copyright © 2008, 2009 Guillem Jover <guillem@debian.org>
 
9
 *
 
10
 * This is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as
 
12
 * published by the Free Software Foundation; either version 2,
 
13
 * or (at your option) any later version.
 
14
 *
 
15
 * This is distributed in the hope that it will be useful, but
 
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public
 
21
 * License along with dpkg; if not, write to the Free Software
 
22
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
23
 */
 
24
 
 
25
#ifndef DPKG_BUFFER_H
 
26
#define DPKG_BUFFER_H
 
27
 
 
28
#include <sys/types.h>
 
29
 
 
30
#include <dpkg/macros.h>
 
31
 
 
32
DPKG_BEGIN_DECLS
 
33
 
 
34
#define BUFFER_WRITE_BUF                0
 
35
#define BUFFER_WRITE_VBUF               1
 
36
#define BUFFER_WRITE_FD                 2
 
37
#define BUFFER_WRITE_NULL               3
 
38
#define BUFFER_WRITE_STREAM             4
 
39
#define BUFFER_WRITE_MD5                5
 
40
 
 
41
#define BUFFER_READ_FD                  0
 
42
#define BUFFER_READ_STREAM              1
 
43
 
 
44
typedef struct buffer_data *buffer_data_t;
 
45
 
 
46
typedef union buffer_arg {
 
47
        void *ptr;
 
48
        int i;
 
49
} buffer_arg;
 
50
 
 
51
struct buffer_data {
 
52
        buffer_arg data;
 
53
        int type;
 
54
};
 
55
 
 
56
#if HAVE_C99
 
57
# define fd_md5(fd, hash, limit, ...) \
 
58
        buffer_copy_IntPtr(fd, BUFFER_READ_FD, hash, BUFFER_WRITE_MD5, \
 
59
                           limit, __VA_ARGS__)
 
60
# define stream_md5(file, hash, limit, ...) \
 
61
        buffer_copy_PtrPtr(file, BUFFER_READ_STREAM, hash, BUFFER_WRITE_MD5, \
 
62
                           limit, __VA_ARGS__)
 
63
# define fd_fd_copy(fd1, fd2, limit, ...) \
 
64
        buffer_copy_IntInt(fd1, BUFFER_READ_FD, fd2, BUFFER_WRITE_FD, \
 
65
                           limit, __VA_ARGS__)
 
66
# define fd_buf_copy(fd, buf, limit, ...) \
 
67
        buffer_copy_IntPtr(fd, BUFFER_READ_FD, buf, BUFFER_WRITE_BUF, \
 
68
                           limit, __VA_ARGS__)
 
69
# define fd_vbuf_copy(fd, buf, limit, ...) \
 
70
        buffer_copy_IntPtr(fd, BUFFER_READ_FD, buf, BUFFER_WRITE_VBUF, \
 
71
                           limit, __VA_ARGS__)
 
72
# define fd_null_copy(fd, limit, ...) \
 
73
        if (lseek(fd, limit, SEEK_CUR) == -1) { \
 
74
                if (errno != ESPIPE) \
 
75
                        ohshite(__VA_ARGS__); \
 
76
                buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
 
77
                                   NULL, BUFFER_WRITE_NULL, \
 
78
                                   limit, __VA_ARGS__); \
 
79
        }
 
80
# define stream_null_copy(file, limit, ...) \
 
81
        if (fseek(file, limit, SEEK_CUR) == -1) { \
 
82
                if (errno != EBADF) \
 
83
                        ohshite(__VA_ARGS__); \
 
84
                buffer_copy_PtrPtr(file, BUFFER_READ_STREAM, \
 
85
                                   NULL, BUFFER_WRITE_NULL, \
 
86
                                   limit, __VA_ARGS__); \
 
87
        }
 
88
# define stream_fd_copy(file, fd, limit, ...) \
 
89
        buffer_copy_PtrInt(file, BUFFER_READ_STREAM, fd, BUFFER_WRITE_FD, \
 
90
                           limit, __VA_ARGS__)
 
91
#else /* HAVE_C99 */
 
92
# define fd_md5(fd, hash, limit, desc...) \
 
93
        buffer_copy_IntPtr(fd, BUFFER_READ_FD, hash, BUFFER_WRITE_MD5, \
 
94
                           limit, desc)
 
95
# define stream_md5(file, hash, limit, desc...) \
 
96
        buffer_copy_PtrPtr(file, BUFFER_READ_STREAM, hash, BUFFER_WRITE_MD5, \
 
97
                           limit, desc)
 
98
# define fd_fd_copy(fd1, fd2, limit, desc...) \
 
99
        buffer_copy_IntInt(fd1, BUFFER_READ_FD, fd2, BUFFER_WRITE_FD, \
 
100
                           limit, desc)
 
101
# define fd_buf_copy(fd, buf, limit, desc...) \
 
102
        buffer_copy_IntPtr(fd, BUFFER_READ_FD, buf, BUFFER_WRITE_BUF, \
 
103
                           limit, desc)
 
104
# define fd_vbuf_copy(fd, buf, limit, desc...) \
 
105
        buffer_copy_IntPtr(fd, BUFFER_READ_FD, buf, BUFFER_WRITE_VBUF, \
 
106
                           limit, desc)
 
107
# define fd_null_copy(fd, limit, desc...) \
 
108
        if (lseek(fd, limit, SEEK_CUR) == -1) { \
 
109
                if (errno != ESPIPE) \
 
110
                        ohshite(desc); \
 
111
                buffer_copy_IntPtr(fd, BUFFER_READ_FD, \
 
112
                                   NULL, BUFFER_WRITE_NULL, \
 
113
                                   limit, desc); \
 
114
        }
 
115
# define stream_null_copy(file, limit, desc...) \
 
116
        if (fseek(file, limit, SEEK_CUR) == -1) { \
 
117
                if (errno != EBADF) \
 
118
                        ohshite(desc); \
 
119
                buffer_copy_PtrPtr(file, BUFFER_READ_STREAM, \
 
120
                                   NULL, BUFFER_WRITE_NULL, \
 
121
                                   limit, desc); \
 
122
        }
 
123
# define stream_fd_copy(file, fd, limit, desc...)\
 
124
        buffer_copy_PtrInt(file, BUFFER_READ_STREAM, fd, BUFFER_WRITE_FD, \
 
125
                           limit, desc)
 
126
#endif /* HAVE_C99 */
 
127
 
 
128
off_t buffer_copy_PtrInt(void *p, int typeIn, int i, int typeOut,
 
129
                         off_t limit, const char *desc,
 
130
                         ...) DPKG_ATTR_PRINTF(6);
 
131
off_t buffer_copy_PtrPtr(void *p1, int typeIn, void *p2, int typeOut,
 
132
                         off_t limit, const char *desc,
 
133
                         ...) DPKG_ATTR_PRINTF(6);
 
134
off_t buffer_copy_IntPtr(int i, int typeIn, void *p, int typeOut,
 
135
                         off_t limit, const char *desc,
 
136
                         ...) DPKG_ATTR_PRINTF(6);
 
137
off_t buffer_copy_IntInt(int i1, int typeIn, int i2, int typeOut,
 
138
                         off_t limit, const char *desc,
 
139
                         ...) DPKG_ATTR_PRINTF(6);
 
140
 
 
141
off_t buffer_write(buffer_data_t data, void *buf,
 
142
                   off_t length, const char *desc);
 
143
off_t buffer_read(buffer_data_t data, void *buf,
 
144
                  off_t length, const char *desc);
 
145
off_t buffer_init(buffer_data_t read_data, buffer_data_t write_data);
 
146
off_t buffer_done(buffer_data_t read_data, buffer_data_t write_data);
 
147
off_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data,
 
148
                  off_t limit, const char *desc);
 
149
 
 
150
DPKG_END_DECLS
 
151
 
 
152
#endif /* DPKG_BUFFER_H */