~ubuntu-branches/ubuntu/precise/gnupg2/precise-proposed

« back to all changes in this revision

Viewing changes to include/util.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Mueller
  • Date: 2005-03-29 10:30:32 UTC
  • Revision ID: james.westby@ubuntu.com-20050329103032-sj42n2ain3ipx310
Tags: upstream-1.9.15
ImportĀ upstreamĀ versionĀ 1.9.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* util.h
 
2
 *      Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GNUPG.
 
5
 *
 
6
 * GNUPG is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * GNUPG is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
19
 */
 
20
#ifndef G10_UTIL_H
 
21
#define G10_UTIL_H
 
22
 
 
23
#warning oops, using old util.h
 
24
#if 0 /* Dont use it anymore */
 
25
 
 
26
#if defined (__MINGW32__) || defined (__CYGWIN32__)
 
27
#include <stdarg.h>
 
28
#endif
 
29
 
 
30
#include "types.h"
 
31
#include "errors.h"
 
32
#include "types.h"
 
33
#include "mpi.h"
 
34
 
 
35
 
 
36
typedef struct {
 
37
     int  *argc;            /* pointer to argc (value subject to change) */
 
38
     char ***argv;          /* pointer to argv (value subject to change) */
 
39
     unsigned flags;        /* Global flags (DO NOT CHANGE) */
 
40
     int err;               /* print error about last option */
 
41
                            /* 1 = warning, 2 = abort */
 
42
     int r_opt;             /* return option */
 
43
     int r_type;            /* type of return value (0 = no argument found)*/
 
44
     union {
 
45
         int   ret_int;
 
46
         long  ret_long;
 
47
         ulong ret_ulong;
 
48
         char *ret_str;
 
49
     } r;                   /* Return values */
 
50
     struct {
 
51
         int idx;
 
52
         int inarg;
 
53
         int stopped;
 
54
         const char *last;
 
55
         void *aliases;
 
56
         const void *cur_alias;
 
57
     } internal;            /* DO NOT CHANGE */
 
58
} ARGPARSE_ARGS;
 
59
 
 
60
typedef struct {
 
61
    int         short_opt;
 
62
    const char *long_opt;
 
63
    unsigned flags;
 
64
    const char *description; /* optional option description */
 
65
} ARGPARSE_OPTS;
 
66
 
 
67
/*-- logger.c --*/
 
68
void log_set_logfile( const char *name, int fd );
 
69
FILE *log_stream(void);
 
70
void g10_log_print_prefix(const char *text);
 
71
void log_set_name( const char *name );
 
72
const char *log_get_name(void);
 
73
void log_set_pid( int pid );
 
74
int  log_get_errorcount( int clear );
 
75
void log_inc_errorcount(void);
 
76
int log_set_strict(int val);
 
77
void g10_log_hexdump( const char *text, const char *buf, size_t len );
 
78
 
 
79
#if defined (__riscos__) \
 
80
    || (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ))
 
81
  void g10_log_bug( const char *fmt, ... )
 
82
                            __attribute__ ((noreturn, format (printf,1,2)));
 
83
  void g10_log_bug0( const char *, int, const char * ) __attribute__ ((noreturn));
 
84
  void g10_log_fatal( const char *fmt, ... )
 
85
                            __attribute__ ((noreturn, format (printf,1,2)));
 
86
  void g10_log_error( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
 
87
  void g10_log_info( const char *fmt, ... )  __attribute__ ((format (printf,1,2)));
 
88
  void g10_log_warning( const char *fmt, ... )  __attribute__ ((format (printf,1,2)));
 
89
  void g10_log_debug( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
 
90
  void g10_log_fatal_f( const char *fname, const char *fmt, ... )
 
91
                            __attribute__ ((noreturn, format (printf,2,3)));
 
92
  void g10_log_error_f( const char *fname, const char *fmt, ... )
 
93
                            __attribute__ ((format (printf,2,3)));
 
94
  void g10_log_info_f( const char *fname, const char *fmt, ... )
 
95
                            __attribute__ ((format (printf,2,3)));
 
96
  void g10_log_debug_f( const char *fname,  const char *fmt, ... )
 
97
                            __attribute__ ((format (printf,2,3)));
 
98
#ifndef __riscos__
 
99
#define BUG() g10_log_bug0(  __FILE__ , __LINE__, __FUNCTION__ )
 
100
#else
 
101
#define BUG() g10_log_bug0(  __FILE__ , __LINE__, __func__ )
 
102
#endif
 
103
#else
 
104
  void g10_log_bug( const char *fmt, ... );
 
105
  void g10_log_bug0( const char *, int );
 
106
  void g10_log_fatal( const char *fmt, ... );
 
107
  void g10_log_error( const char *fmt, ... );
 
108
  void g10_log_info( const char *fmt, ... );
 
109
  void g10_log_warning( const char *fmt, ... );
 
110
  void g10_log_debug( const char *fmt, ... );
 
111
  void g10_log_fatal_f( const char *fname, const char *fmt, ... );
 
112
  void g10_log_error_f( const char *fname, const char *fmt, ... );
 
113
  void g10_log_info_f( const char *fname, const char *fmt, ... );
 
114
  void g10_log_debug_f( const char *fname, const char *fmt, ... );
 
115
#define BUG() g10_log_bug0( __FILE__ , __LINE__ )
 
116
#endif
 
117
 
 
118
#define log_hexdump g10_log_hexdump
 
119
#define log_bug     g10_log_bug
 
120
#define log_bug0    g10_log_bug0
 
121
#define log_fatal   g10_log_fatal
 
122
#define log_error   g10_log_error
 
123
#define log_info    g10_log_info
 
124
#define log_warning g10_log_warning
 
125
#define log_debug   g10_log_debug
 
126
#define log_fatal_f g10_log_fatal_f
 
127
#define log_error_f g10_log_error_f
 
128
#define log_info_f  g10_log_info_f
 
129
#define log_debug_f g10_log_debug_f
 
130
 
 
131
 
 
132
/*-- argparse.c --*/
 
133
int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
 
134
int optfile_parse( FILE *fp, const char *filename, unsigned *lineno,
 
135
                   ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
 
136
void usage( int level );
 
137
const char *default_strusage( int level );
 
138
 
 
139
 
 
140
/*-- (main program) --*/
 
141
const char *strusage( int level );
 
142
 
 
143
 
 
144
/*-- dotlock.c --*/
 
145
struct dotlock_handle;
 
146
typedef struct dotlock_handle *DOTLOCK;
 
147
 
 
148
void disable_dotlock(void);
 
149
DOTLOCK create_dotlock( const char *file_to_lock );
 
150
int make_dotlock( DOTLOCK h, long timeout );
 
151
int release_dotlock( DOTLOCK h );
 
152
void remove_lockfiles (void);
 
153
 
 
154
/*-- fileutil.c --*/
 
155
char * make_basename(const char *filepath, const char *inputpath);
 
156
char * make_dirname(const char *filepath);
 
157
char *make_filename( const char *first_part, ... );
 
158
int compare_filenames( const char *a, const char *b );
 
159
const char *print_fname_stdin( const char *s );
 
160
const char *print_fname_stdout( const char *s );
 
161
int  is_file_compressed(const char *s, int *r_status);
 
162
 
 
163
 
 
164
/*-- miscutil.c --*/
 
165
u32 make_timestamp(void);
 
166
u32 scan_isodatestr( const char *string );
 
167
u32 add_days_to_timestamp( u32 stamp, u16 days );
 
168
const char *strtimevalue( u32 stamp );
 
169
const char *strtimestamp( u32 stamp ); /* GMT */
 
170
const char *asctimestamp( u32 stamp ); /* localized */
 
171
void print_string( FILE *fp, const byte *p, size_t n, int delim );
 
172
void  print_utf8_string( FILE *fp, const byte *p, size_t n );
 
173
void  print_utf8_string2( FILE *fp, const byte *p, size_t n, int delim);
 
174
char *make_printable_string( const byte *p, size_t n, int delim );
 
175
int answer_is_yes_no_default( const char *s, int def_answer );
 
176
int answer_is_yes( const char *s );
 
177
int answer_is_yes_no_quit( const char *s );
 
178
 
 
179
/*-- strgutil.c --*/
 
180
 
 
181
#include "../jnlib/strlist.h"
 
182
 
 
183
const char *memistr( const char *buf, size_t buflen, const char *sub );
 
184
const char *ascii_memistr( const char *buf, size_t buflen, const char *sub );
 
185
char *mem2str( char *, const void *, size_t);
 
186
char *trim_spaces( char *string );
 
187
unsigned int trim_trailing_chars( byte *line, unsigned int len,
 
188
                                  const char *trimchars);
 
189
unsigned int trim_trailing_ws( byte *line, unsigned len );
 
190
unsigned int check_trailing_chars( const byte *line, unsigned int len,
 
191
                                   const char *trimchars );
 
192
unsigned int check_trailing_ws( const byte *line, unsigned int len );
 
193
int string_count_chr( const char *string, int c );
 
194
int set_native_charset( const char *newset );
 
195
const char* get_native_charset(void);
 
196
char *native_to_utf8( const char *string );
 
197
char *utf8_to_native( const char *string, size_t length, int delim);
 
198
int  check_utf8_string( const char *string );
 
199
 
 
200
int ascii_isupper (int c);
 
201
int ascii_islower (int c);
 
202
int ascii_toupper (int c);
 
203
int ascii_tolower (int c);
 
204
int ascii_strcasecmp( const char *a, const char *b );
 
205
int ascii_strncasecmp( const char *a, const char *b, size_t n);
 
206
int ascii_memcasecmp( const char *a, const char *b, size_t n);
 
207
 
 
208
#ifndef HAVE_STPCPY
 
209
char *stpcpy(char *a,const char *b);
 
210
#endif
 
211
#ifndef HAVE_STRLWR
 
212
char *strlwr(char *a);
 
213
#endif
 
214
#ifndef HAVE_STRSEP
 
215
char *strsep (char **stringp, const char *delim);
 
216
#endif
 
217
#ifndef HAVE_STRCASECMP
 
218
int strcasecmp( const char *, const char *b);
 
219
#endif
 
220
#ifndef HAVE_STRNCASECMP
 
221
int strncasecmp (const char *, const char *b, size_t n);
 
222
#endif
 
223
#ifndef HAVE_STRTOUL
 
224
#define strtoul(a,b,c)  ((unsigned long)strtol((a),(b),(c)))
 
225
#endif
 
226
#ifndef HAVE_MEMMOVE
 
227
#define memmove(d, s, n) bcopy((s), (d), (n))
 
228
#endif
 
229
 
 
230
#if defined (__MINGW32__)
 
231
/*-- w32reg.c --*/
 
232
char *read_w32_registry_string( const char *root,
 
233
                                const char *dir, const char *name );
 
234
int write_w32_registry_string(const char *root, const char *dir,
 
235
                              const char *name, const char *value);
 
236
 
 
237
/*-- strgutil.c --*/
 
238
int vasprintf ( char **result, const char *format, va_list args);
 
239
#endif
 
240
 
 
241
/**** other missing stuff ****/
 
242
#ifndef HAVE_ATEXIT  /* For SunOS */
 
243
#define atexit(a)    (on_exit((a),0))
 
244
#endif
 
245
 
 
246
#ifndef HAVE_RAISE
 
247
#define raise(a) kill(getpid(), (a))
 
248
#endif
 
249
 
 
250
/******** some macros ************/
 
251
#ifndef STR
 
252
#define STR(v) #v
 
253
#endif
 
254
#define STR2(v) STR(v)
 
255
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
 
256
#define DIMof(type,member)   DIM(((type *)0)->member)
 
257
 
 
258
#define wipememory2(_ptr,_set,_len) do { volatile char *_vptr=(volatile char *)(_ptr); size_t _vlen=(_len); while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } } while(0)
 
259
#define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
 
260
 
 
261
/******* RISC OS stuff ***********/
 
262
#ifdef __riscos__
 
263
/* needed for strcasecmp() */
 
264
#include <strings.h>
 
265
/* needed for filename munging */
 
266
#include <unixlib/local.h>
 
267
/* needed for image file system feature */
 
268
#include <unixlib/features.h>
 
269
void riscos_global_defaults(void);
 
270
#define RISCOS_GLOBAL_STATICS(a) const char *__dynamic_da_name = (a);
 
271
int riscos_load_module(const char *name, const char * const path[], int fatal);
 
272
int riscos_get_filetype_from_string(const char *string, int len);
 
273
int riscos_get_filetype(const char *filename);
 
274
void riscos_set_filetype_by_number(const char *filename, int type);
 
275
void riscos_set_filetype_by_mimetype(const char *filename, const char *mimetype);
 
276
pid_t riscos_getpid(void);
 
277
int riscos_kill(pid_t pid, int sig);
 
278
int riscos_access(const char *path, int amode);
 
279
int riscos_getchar(void);
 
280
char *riscos_make_basename(const char *filepath, const char *inputpath);
 
281
int riscos_check_regexp(const char *exp, const char *string, int debug);
 
282
int riscos_fdopenfile(const char *filename, const int allow_write);
 
283
void riscos_close_fds(void);
 
284
int riscos_renamefile(const char *old, const char *new);
 
285
char *riscos_gstrans(const char *old);
 
286
void riscos_not_implemented(const char *feature);
 
287
#ifdef DEBUG
 
288
void riscos_dump_fdlist(void);
 
289
void riscos_list_openfiles(void);
 
290
#endif
 
291
#ifndef __RISCOS__C__
 
292
#define getpid riscos_getpid
 
293
#define kill(a,b) riscos_kill((a),(b))
 
294
#define access(a,b) riscos_access((a),(b))
 
295
#endif /* !__RISCOS__C__ */
 
296
#endif /* __riscos__ */
 
297
 
 
298
#endif
 
299
 
 
300
#endif /*G10_UTIL_H*/