~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-updates

« back to all changes in this revision

Viewing changes to common/estream.h

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* estream.h - Extended stream I/O/ Library
2
 
   Copyright (C) 2004 g10 Code GmbH
3
 
 
4
 
   This file is part of Libestream.
5
 
 
6
 
   Libestream is free software; you can redistribute it and/or modify
7
 
   it under the terms of the GNU General Public License as published
8
 
   by the Free Software Foundation; either version 2 of the License,
9
 
   or (at your option) any later version.
10
 
 
11
 
   Libestream is distributed in the hope that it will be useful, but
12
 
   WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
   Lesser General Public License for more details.
15
 
 
16
 
   You should have received a copy of the GNU General Public License
17
 
   along with Libestream; if not, write to the Free Software
18
 
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19
 
   02111-1307, USA.  */
 
1
/* estream.h - Extended stream I/O Library
 
2
 * Copyright (C) 2004, 2005, 2006, 2007 g10 Code GmbH
 
3
 *
 
4
 * This file is part of Libestream.
 
5
 *
 
6
 * Libestream is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published
 
8
 * by the Free Software Foundation; either version 2 of the License,
 
9
 * or (at your option) any later version.
 
10
 *
 
11
 * Libestream is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with Libestream; if not, see <http://www.gnu.org/licenses/>.
 
18
 */
20
19
 
21
20
#ifndef ESTREAM_H
22
21
#define ESTREAM_H
25
24
#include <stdarg.h>
26
25
#include <stdio.h>
27
26
 
28
 
 
 
27
/* To use this file with libraries the following macro is useful:
 
28
 
 
29
     #define _ESTREAM_EXT_SYM_PREFIX _foo_
 
30
 
 
31
       This prefixes all external symbols with "_foo_".
 
32
 
 
33
 */
 
34
 
 
35
 
 
36
#ifdef _ESTREAM_EXT_SYM_PREFIX
 
37
#ifndef _ESTREAM_PREFIX
 
38
#define _ESTREAM_PREFIX1(x,y)  x ## y
 
39
#define _ESTREAM_PREFIX2(x,y) _ESTREAM_PREFIX1(x,y)
 
40
#define _ESTREAM_PREFIX(x)    _ESTREAM_PREFIX2(_ESTREAM_EXT_SYM_PREFIX,x)
 
41
#endif /*_ESTREAM_PREFIX*/
 
42
#define es_fopen              _ESTREAM_PREFIX(es_fopen)
 
43
#define es_mopen              _ESTREAM_PREFIX(es_mopen)
 
44
#define es_fopenmem           _ESTREAM_PREFIX(es_fopenmem)
 
45
#define es_fdopen             _ESTREAM_PREFIX(es_fdopen)
 
46
#define es_fdopen_nc          _ESTREAM_PREFIX(es_fdopen_nc)
 
47
#define es_fpopen             _ESTREAM_PREFIX(es_fpopen)
 
48
#define es_fpopen_nc          _ESTREAM_PREFIX(es_fpopen_nc)
 
49
#define es_freopen            _ESTREAM_PREFIX(es_freopen)
 
50
#define es_fopencookie        _ESTREAM_PREFIX(es_fopencookie)
 
51
#define es_fclose             _ESTREAM_PREFIX(es_fclose)
 
52
#define es_fileno             _ESTREAM_PREFIX(es_fileno)
 
53
#define es_fileno_unlocked    _ESTREAM_PREFIX(es_fileno_unlocked)
 
54
#define es_flockfile          _ESTREAM_PREFIX(es_flockfile)
 
55
#define es_ftrylockfile       _ESTREAM_PREFIX(es_ftrylockfile)
 
56
#define es_funlockfile        _ESTREAM_PREFIX(es_funlockfile)
 
57
#define es_feof               _ESTREAM_PREFIX(es_feof)
 
58
#define es_feof_unlocked      _ESTREAM_PREFIX(es_feof_unlocked)
 
59
#define es_ferror             _ESTREAM_PREFIX(es_ferror)
 
60
#define es_ferror_unlocked    _ESTREAM_PREFIX(es_ferror_unlocked)
 
61
#define es_clearerr           _ESTREAM_PREFIX(es_clearerr)
 
62
#define es_clearerr_unlocked  _ESTREAM_PREFIX(es_clearerr_unlocked)
 
63
#define es_fflush             _ESTREAM_PREFIX(es_fflush)
 
64
#define es_fseek              _ESTREAM_PREFIX(es_fseek)
 
65
#define es_fseeko             _ESTREAM_PREFIX(es_fseeko)
 
66
#define es_ftell              _ESTREAM_PREFIX(es_ftell)
 
67
#define es_ftello             _ESTREAM_PREFIX(es_ftello)
 
68
#define es_rewind             _ESTREAM_PREFIX(es_rewind)
 
69
#define es_fgetc              _ESTREAM_PREFIX(es_fgetc)
 
70
#define es_fputc              _ESTREAM_PREFIX(es_fputc)
 
71
#define _es_getc_underflow    _ESTREAM_PREFIX(_es_getc_underflow)
 
72
#define _es_putc_overflow     _ESTREAM_PREFIX(_es_putc_overflow)
 
73
#define es_ungetc             _ESTREAM_PREFIX(es_ungetc)
 
74
#define es_read               _ESTREAM_PREFIX(es_read)
 
75
#define es_write              _ESTREAM_PREFIX(es_write)
 
76
#define es_write_sanitized    _ESTREAM_PREFIX(es_write_sanitized)
 
77
#define es_write_hexstring    _ESTREAM_PREFIX(es_write_hexstring)
 
78
#define es_fread              _ESTREAM_PREFIX(es_fread)
 
79
#define es_fwrite             _ESTREAM_PREFIX(es_fwrite)
 
80
#define es_fgets              _ESTREAM_PREFIX(es_fgets)
 
81
#define es_fputs              _ESTREAM_PREFIX(es_fputs)
 
82
#define es_getline            _ESTREAM_PREFIX(es_getline)
 
83
#define es_read_line          _ESTREAM_PREFIX(es_read_line)
 
84
#define es_free               _ESTREAM_PREFIX(es_free)
 
85
#define es_fprf               _ESTREAM_PREFIX(es_fprf)
 
86
#define es_vfprf              _ESTREAM_PREFIX(es_vfprf)
 
87
#define es_setvbuf            _ESTREAM_PREFIX(es_setvbuf)
 
88
#define es_setbuf             _ESTREAM_PREFIX(es_setbuf)
 
89
#define es_tmpfile            _ESTREAM_PREFIX(es_tmpfile)
 
90
#define es_opaque_set         _ESTREAM_PREFIX(es_opaque_set)
 
91
#define es_opaque_get         _ESTREAM_PREFIX(es_opaque_get)
 
92
#define es_write_sanitized_utf8_buffer  \
 
93
              _ESTREAM_PREFIX(es_write_sanitized_utf8_buffer)
 
94
#endif /*_ESTREAM_EXT_SYM_PREFIX*/
 
95
 
 
96
 
 
97
#ifdef __cplusplus
 
98
extern "C"
 
99
{
 
100
#if 0
 
101
}
 
102
#endif
 
103
#endif
 
104
 
 
105
 
29
106
/* Forward declaration for the (opaque) internal type.  */
30
107
struct estream_internal;
31
108
 
60
137
  size_t unread_data_len;
61
138
 
62
139
  /* Various flags.  */
63
 
#define ES__FLAG_WRITING        (1 << 0)
64
 
  unsigned int flags;
 
140
  struct {
 
141
    unsigned int writing: 1;
 
142
    unsigned int reserved: 7;
 
143
  } flags;
65
144
 
66
145
  /* A pointer to our internal data for this stream.  */
67
146
  struct estream_internal *intern;
89
168
} es_cookie_io_functions_t;
90
169
 
91
170
 
 
171
#ifndef _ESTREAM_GCC_A_PRINTF
 
172
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
 
173
# define _ESTREAM_GCC_A_PRINTF( f, a )  __attribute__ ((format (printf,f,a)))
 
174
#else
 
175
# define _ESTREAM_GCC_A_PRINTF( f, a )
 
176
#endif
 
177
#endif /*_ESTREAM_GCC_A_PRINTF*/
 
178
 
 
179
 
92
180
#ifndef ES__RESTRICT
93
181
#  if defined __GNUC__ && defined __GNUC_MINOR__
94
182
#    if  (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 92))
110
198
                    void *(*func_realloc) (void *mem, size_t size),
111
199
                    void (*func_free) (void *mem),
112
200
                    const char *ES__RESTRICT mode);
113
 
estream_t es_open_memstream (char **ptr, size_t *size);
 
201
estream_t es_fopenmem (size_t memlimit, const char *ES__RESTRICT mode);
114
202
estream_t es_fdopen (int filedes, const char *mode);
 
203
estream_t es_fdopen_nc (int filedes, const char *mode);
 
204
estream_t es_fpopen (FILE *fp, const char *mode);
 
205
estream_t es_fpopen_nc (FILE *fp, const char *mode);
115
206
estream_t es_freopen (const char *ES__RESTRICT path,
116
207
                      const char *ES__RESTRICT mode,
117
208
                      estream_t ES__RESTRICT stream);
147
238
int _es_putc_overflow (int c, estream_t stream);
148
239
 
149
240
#define es_getc_unlocked(stream)                                \
150
 
  (((! ((stream)->flags & 1))                                   \
 
241
  (((!(stream)->flags.writing)                                  \
151
242
    && ((stream)->data_offset < (stream)->data_len)             \
152
243
    && (! (stream)->unread_data_len))                           \
153
244
  ? ((int) (stream)->buffer[((stream)->data_offset)++])         \
154
245
  : _es_getc_underflow ((stream)))
155
246
 
156
247
#define es_putc_unlocked(c, stream)                             \
157
 
  ((((stream)->flags & 1)                                       \
 
248
  (((stream)->flags.writing                                     \
158
249
    && ((stream)->data_offset < (stream)->buffer_size)          \
159
250
    && (c != '\n'))                                             \
160
251
  ? ((int) ((stream)->buffer[((stream)->data_offset)++] = (c))) \
171
262
int es_write (estream_t ES__RESTRICT stream,
172
263
              const void *ES__RESTRICT buffer, size_t bytes_to_write,
173
264
              size_t *ES__RESTRICT bytes_written);
 
265
int es_write_sanitized (estream_t ES__RESTRICT stream,
 
266
                        const void *ES__RESTRICT buffer, size_t length,
 
267
                        const char *delimiters,
 
268
                        size_t *ES__RESTRICT bytes_written);
 
269
int es_write_hexstring (estream_t ES__RESTRICT stream,
 
270
                        const void *ES__RESTRICT buffer, size_t length,
 
271
                        int reserved, size_t *ES__RESTRICT bytes_written);
174
272
 
175
273
size_t es_fread (void *ES__RESTRICT ptr, size_t size, size_t nitems,
176
274
                 estream_t ES__RESTRICT stream);
183
281
ssize_t es_getline (char *ES__RESTRICT *ES__RESTRICT lineptr,
184
282
                    size_t *ES__RESTRICT n,
185
283
                    estream_t stream);
 
284
ssize_t es_read_line (estream_t stream,
 
285
                      char **addr_of_buffer, size_t *length_of_buffer,
 
286
                      size_t *max_length);
 
287
void es_free (void *a);
186
288
 
187
289
int es_fprintf (estream_t ES__RESTRICT stream,
188
 
                const char *ES__RESTRICT format, ...);
 
290
                const char *ES__RESTRICT format, ...)
 
291
     _ESTREAM_GCC_A_PRINTF(2,3);
189
292
int es_vfprintf (estream_t ES__RESTRICT stream,
190
 
                 const char *ES__RESTRICT format, va_list ap);
191
 
 
 
293
                 const char *ES__RESTRICT format, va_list ap)
 
294
     _ESTREAM_GCC_A_PRINTF(2,0);
192
295
int es_setvbuf (estream_t ES__RESTRICT stream,
193
296
                char *ES__RESTRICT buf, int mode, size_t size);
194
297
void es_setbuf (estream_t ES__RESTRICT stream, char *ES__RESTRICT buf);
198
301
void es_opaque_set (estream_t ES__RESTRICT stream, void *ES__RESTRICT opaque);
199
302
void *es_opaque_get (estream_t stream);
200
303
 
 
304
 
 
305
#ifdef GNUPG_MAJOR_VERSION
 
306
int es_write_sanitized_utf8_buffer (estream_t stream,
 
307
                                    const void *buffer, size_t length,
 
308
                                    const char *delimiters,
 
309
                                    size_t *bytes_written);
 
310
#endif /*GNUPG_MAJOR_VERSION*/
 
311
 
 
312
 
 
313
#ifdef __cplusplus
 
314
}
 
315
#endif
201
316
#endif /*ESTREAM_H*/
202