1997-11-18 14:06:00 +00:00
|
|
|
/* util.h
|
1999-11-19 16:11:37 +00:00
|
|
|
* Copyright (C) 1998,1999 Free Software Foundation, Inc.
|
1997-11-18 14:06:00 +00:00
|
|
|
*
|
1998-06-16 15:13:28 +00:00
|
|
|
* This file is part of GNUPG.
|
1997-11-18 14:06:00 +00:00
|
|
|
*
|
1998-06-16 15:13:28 +00:00
|
|
|
* GNUPG is free software; you can redistribute it and/or modify
|
1997-11-18 14:06:00 +00:00
|
|
|
* 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.
|
|
|
|
*
|
1998-06-16 15:13:28 +00:00
|
|
|
* GNUPG is distributed in the hope that it will be useful,
|
1997-11-18 14:06:00 +00:00
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
2000-01-27 16:50:45 +00:00
|
|
|
#ifndef GPG_UTIL_H
|
|
|
|
#define GPG_UTIL_H
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1999-11-19 16:11:37 +00:00
|
|
|
#ifdef _GCRYPT_IN_LIBGCRYPT
|
|
|
|
#error This header should not be used internally by libgcrypt
|
|
|
|
#endif
|
|
|
|
|
1999-12-08 21:03:03 +00:00
|
|
|
#include <stdio.h>
|
1997-12-23 17:30:18 +00:00
|
|
|
#include "types.h"
|
1997-11-18 14:06:00 +00:00
|
|
|
#include "errors.h"
|
2000-01-24 11:55:49 +00:00
|
|
|
#include "../jnlib/mischelp.h"
|
|
|
|
#include "../jnlib/stringhelp.h"
|
|
|
|
#include "../jnlib/argparse.h"
|
|
|
|
#include "../jnlib/dotlock.h"
|
1999-12-08 21:03:03 +00:00
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- logger.c --*/
|
1999-05-22 20:54:54 +00:00
|
|
|
void log_set_logfile( const char *name, int fd );
|
|
|
|
FILE *log_stream(void);
|
2000-01-27 16:50:45 +00:00
|
|
|
void gpg_log_print_prefix(const char *text);
|
1998-02-13 20:58:50 +00:00
|
|
|
void log_set_name( const char *name );
|
|
|
|
const char *log_get_name(void);
|
1998-01-02 20:40:10 +00:00
|
|
|
void log_set_pid( int pid );
|
2000-07-14 17:34:53 +00:00
|
|
|
void log_inc_errorcount(void);
|
1998-01-02 20:40:10 +00:00
|
|
|
int log_get_errorcount( int clear );
|
2000-01-27 16:50:45 +00:00
|
|
|
void gpg_log_hexdump( const char *text, const char *buf, size_t len );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1998-01-16 21:15:24 +00:00
|
|
|
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
|
2000-01-27 16:50:45 +00:00
|
|
|
void gpg_log_bug( const char *fmt, ... )
|
1998-01-16 21:15:24 +00:00
|
|
|
__attribute__ ((noreturn, format (printf,1,2)));
|
2000-01-27 16:50:45 +00:00
|
|
|
void gpg_log_bug0( const char *, int, const char * ) __attribute__ ((noreturn));
|
|
|
|
void gpg_log_fatal( const char *fmt, ... )
|
1998-01-16 21:15:24 +00:00
|
|
|
__attribute__ ((noreturn, format (printf,1,2)));
|
2000-01-27 16:50:45 +00:00
|
|
|
void gpg_log_error( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
|
|
|
|
void gpg_log_info( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
|
|
|
|
void gpg_log_debug( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
|
|
|
|
void gpg_log_fatal_f( const char *fname, const char *fmt, ... )
|
1998-07-08 09:29:43 +00:00
|
|
|
__attribute__ ((noreturn, format (printf,2,3)));
|
2000-01-27 16:50:45 +00:00
|
|
|
void gpg_log_error_f( const char *fname, const char *fmt, ... )
|
1998-07-08 09:29:43 +00:00
|
|
|
__attribute__ ((format (printf,2,3)));
|
2000-01-27 16:50:45 +00:00
|
|
|
void gpg_log_info_f( const char *fname, const char *fmt, ... )
|
1998-07-08 09:29:43 +00:00
|
|
|
__attribute__ ((format (printf,2,3)));
|
2000-01-27 16:50:45 +00:00
|
|
|
void gpg_log_debug_f( const char *fname, const char *fmt, ... )
|
1998-07-08 09:29:43 +00:00
|
|
|
__attribute__ ((format (printf,2,3)));
|
2000-01-27 16:50:45 +00:00
|
|
|
#define BUG() gpg_log_bug0( __FILE__ , __LINE__, __FUNCTION__ )
|
1998-01-16 21:15:24 +00:00
|
|
|
#else
|
2000-01-27 16:50:45 +00:00
|
|
|
void gpg_log_bug( const char *fmt, ... );
|
|
|
|
void gpg_log_bug0( const char *, int );
|
|
|
|
void gpg_log_fatal( const char *fmt, ... );
|
|
|
|
void gpg_log_error( const char *fmt, ... );
|
|
|
|
void gpg_log_info( const char *fmt, ... );
|
|
|
|
void gpg_log_debug( const char *fmt, ... );
|
|
|
|
void gpg_log_fatal_f( const char *fname, const char *fmt, ... );
|
|
|
|
void gpg_log_error_f( const char *fname, const char *fmt, ... );
|
|
|
|
void gpg_log_info_f( const char *fname, const char *fmt, ... );
|
|
|
|
void gpg_log_debug_f( const char *fname, const char *fmt, ... );
|
|
|
|
#define BUG() gpg_log_bug0( __FILE__ , __LINE__ )
|
1998-01-16 21:15:24 +00:00
|
|
|
#endif
|
|
|
|
|
2000-01-27 16:50:45 +00:00
|
|
|
#define log_hexdump gpg_log_hexdump
|
|
|
|
#define log_bug gpg_log_bug
|
|
|
|
#define log_bug0 gpg_log_bug0
|
|
|
|
#define log_fatal gpg_log_fatal
|
|
|
|
#define log_error gpg_log_error
|
|
|
|
#define log_info gpg_log_info
|
|
|
|
#define log_debug gpg_log_debug
|
|
|
|
#define log_fatal_f gpg_log_fatal_f
|
|
|
|
#define log_error_f gpg_log_error_f
|
|
|
|
#define log_info_f gpg_log_info_f
|
|
|
|
#define log_debug_f gpg_log_debug_f
|
1998-06-16 15:13:28 +00:00
|
|
|
|
1998-01-16 21:15:24 +00:00
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
/*-- errors.c --*/
|
2000-01-27 16:50:45 +00:00
|
|
|
const char * gpg_errstr( int no );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
|
1998-11-27 20:40:56 +00:00
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
/*-- fileutil.c --*/
|
1998-10-25 19:00:01 +00:00
|
|
|
char * make_basename(const char *filepath);
|
|
|
|
char * make_dirname(const char *filepath);
|
1997-12-12 12:03:58 +00:00
|
|
|
char *make_filename( const char *first_part, ... );
|
1998-06-11 07:16:50 +00:00
|
|
|
int compare_filenames( const char *a, const char *b );
|
1998-03-09 21:44:06 +00:00
|
|
|
const char *print_fname_stdin( const char *s );
|
|
|
|
const char *print_fname_stdout( const char *s );
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- miscutil.c --*/
|
|
|
|
u32 make_timestamp(void);
|
1999-07-07 11:28:26 +00:00
|
|
|
u32 scan_isodatestr( const char *string );
|
1998-04-30 14:06:01 +00:00
|
|
|
u32 add_days_to_timestamp( u32 stamp, u16 days );
|
1998-11-20 17:42:18 +00:00
|
|
|
const char *strtimevalue( u32 stamp );
|
1998-09-15 19:56:30 +00:00
|
|
|
const char *strtimestamp( u32 stamp ); /* GMT */
|
|
|
|
const char *asctimestamp( u32 stamp ); /* localized */
|
1999-05-25 17:56:15 +00:00
|
|
|
void print_string( FILE *fp, const byte *p, size_t n, int delim );
|
1999-08-31 15:30:12 +00:00
|
|
|
void print_utf8_string( FILE *fp, const byte *p, size_t n );
|
1999-07-01 10:53:35 +00:00
|
|
|
char *make_printable_string( const byte *p, size_t n, int delim );
|
1997-12-20 17:23:29 +00:00
|
|
|
int answer_is_yes( const char *s );
|
1999-05-27 07:45:46 +00:00
|
|
|
int answer_is_yes_no_quit( const char *s );
|
1997-11-18 14:06:00 +00:00
|
|
|
|
|
|
|
/*-- strgutil.c --*/
|
|
|
|
void free_strlist( STRLIST sl );
|
|
|
|
#define FREE_STRLIST(a) do { free_strlist((a)); (a) = NULL ; } while(0)
|
1998-07-06 10:23:57 +00:00
|
|
|
STRLIST add_to_strlist( STRLIST *list, const char *string );
|
1999-07-01 10:53:35 +00:00
|
|
|
STRLIST add_to_strlist2( STRLIST *list, const char *string, int is_utf8 );
|
1998-07-06 10:23:57 +00:00
|
|
|
STRLIST append_to_strlist( STRLIST *list, const char *string );
|
1999-07-01 10:53:35 +00:00
|
|
|
STRLIST append_to_strlist2( STRLIST *list, const char *string, int is_utf8 );
|
1998-02-11 23:22:09 +00:00
|
|
|
STRLIST strlist_prev( STRLIST head, STRLIST node );
|
|
|
|
STRLIST strlist_last( STRLIST node );
|
1998-01-07 20:47:46 +00:00
|
|
|
int string_count_chr( const char *string, int c );
|
1998-11-13 19:41:41 +00:00
|
|
|
int set_native_charset( const char *newset );
|
1999-03-02 15:48:37 +00:00
|
|
|
const char* get_native_charset(void);
|
1998-11-03 19:38:58 +00:00
|
|
|
char *native_to_utf8( const char *string );
|
1999-08-31 15:30:12 +00:00
|
|
|
char *utf8_to_native( const char *string, size_t length );
|
1998-11-13 19:41:41 +00:00
|
|
|
int check_utf8_string( const char *string );
|
1998-01-07 20:47:46 +00:00
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
|
1998-09-14 15:49:56 +00:00
|
|
|
/**** other missing stuff ****/
|
|
|
|
#ifndef HAVE_ATEXIT /* For SunOS */
|
|
|
|
#define atexit(a) (on_exit((a),0))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_RAISE
|
|
|
|
#define raise(a) kill(getpid(), (a))
|
|
|
|
#endif
|
|
|
|
|
1997-11-18 14:06:00 +00:00
|
|
|
/******** some macros ************/
|
|
|
|
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
|
|
|
|
#define DIMof(type,member) DIM(((type *)0)->member)
|
|
|
|
|
2000-01-27 16:50:45 +00:00
|
|
|
#endif /*GPG_UTIL_H*/
|