aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>1999-05-22 20:54:54 +0000
committerWerner Koch <[email protected]>1999-05-22 20:54:54 +0000
commit9131432b4d17af907b9a235985864f1e88f571ff (patch)
tree64a60b3115ee1bfcba806c4b07919c6819e0c702 /util
parentSee ChangeLog: Thu May 20 14:04:08 CEST 1999 Werner Koch (diff)
downloadgnupg-9131432b4d17af907b9a235985864f1e88f571ff.tar.gz
gnupg-9131432b4d17af907b9a235985864f1e88f571ff.zip
See ChangeLog: Sat May 22 22:47:26 CEST 1999 Werner Koch
Diffstat (limited to 'util')
-rw-r--r--util/ChangeLog4
-rw-r--r--util/iobuf.c1
-rw-r--r--util/logger.c72
-rw-r--r--util/strgutil.c3
4 files changed, 63 insertions, 17 deletions
diff --git a/util/ChangeLog b/util/ChangeLog
index 417c7b402..25edc5afe 100644
--- a/util/ChangeLog
+++ b/util/ChangeLog
@@ -1,3 +1,7 @@
+Sat May 22 22:47:26 CEST 1999 Werner Koch <[email protected]>
+
+ * logger.c (log_set_logfile): New.
+
Thu May 20 14:04:08 CEST 1999 Werner Koch <[email protected]>
* memory.c (membug): Nanu, there was a const instead of a static.
diff --git a/util/iobuf.c b/util/iobuf.c
index bd7093a9e..03fb35319 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -428,6 +428,7 @@ int
iobuf_print_chain( IOBUF a )
{
print_chain(a);
+ return 0;
}
/****************
diff --git a/util/logger.c b/util/logger.c
index 6536802ee..2573f5b63 100644
--- a/util/logger.c
+++ b/util/logger.c
@@ -22,6 +22,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
#include "util.h"
#include "i18n.h"
@@ -29,6 +31,40 @@
static char pidstring[15];
static char *pgm_name;
static int errorcount;
+static FILE *logfp;
+
+/****************
+ * Set the logfile to use (not yet implemneted) or, if logfile is NULL,
+ * the Fd where logoutputs should go.
+ */
+void
+log_set_logfile( const char *name, int fd )
+{
+ if( name )
+ BUG();
+
+ if( logfp && logfp != stderr && logfp != stdout )
+ fclose( logfp );
+ if( fd == 1 )
+ logfp = stdout;
+ else if( fd == 2 )
+ logfp = stderr;
+ else
+ logfp = fdopen( fd, "a" );
+ if( !logfp ) {
+ logfp = stderr;
+ log_fatal("can't open fd %d for logging: %s\n", fd, strerror(errno));
+ }
+}
+
+FILE *
+log_stream()
+{
+ if( !logfp )
+ logfp = stderr;
+ return logfp;
+}
+
void
log_set_name( const char *name )
@@ -69,19 +105,23 @@ log_get_errorcount( int clear)
static void
print_prefix(const char *text)
{
+ if( !logfp )
+ logfp = stderr;
if( pgm_name )
- fprintf(stderr, "%s%s: %s", pgm_name, pidstring, text );
+ fprintf(logfp, "%s%s: %s", pgm_name, pidstring, text );
else
- fprintf(stderr, "?%s: %s", pidstring, text );
+ fprintf(logfp, "?%s: %s", pidstring, text );
}
static void
print_prefix_f(const char *text, const char *fname)
{
+ if( !logfp )
+ logfp = stderr;
if( pgm_name )
- fprintf(stderr, "%s%s:%s: %s", pgm_name, pidstring, fname, text );
+ fprintf(logfp, "%s%s:%s: %s", pgm_name, pidstring, fname, text );
else
- fprintf(stderr, "?%s:%s: %s", pidstring, fname, text );
+ fprintf(logfp, "?%s:%s: %s", pidstring, fname, text );
}
void
@@ -91,7 +131,7 @@ g10_log_info( const char *fmt, ... )
print_prefix("");
va_start( arg_ptr, fmt ) ;
- vfprintf(stderr,fmt,arg_ptr) ;
+ vfprintf(logfp,fmt,arg_ptr) ;
va_end(arg_ptr);
}
@@ -102,7 +142,7 @@ g10_log_info_f( const char *fname, const char *fmt, ... )
print_prefix_f("", fname);
va_start( arg_ptr, fmt ) ;
- vfprintf(stderr,fmt,arg_ptr) ;
+ vfprintf(logfp,fmt,arg_ptr) ;
va_end(arg_ptr);
}
@@ -113,7 +153,7 @@ g10_log_error( const char *fmt, ... )
print_prefix("");
va_start( arg_ptr, fmt ) ;
- vfprintf(stderr,fmt,arg_ptr) ;
+ vfprintf(logfp,fmt,arg_ptr) ;
va_end(arg_ptr);
errorcount++;
}
@@ -125,7 +165,7 @@ g10_log_error_f( const char *fname, const char *fmt, ... )
print_prefix_f("", fname);
va_start( arg_ptr, fmt ) ;
- vfprintf(stderr,fmt,arg_ptr) ;
+ vfprintf(logfp,fmt,arg_ptr) ;
va_end(arg_ptr);
errorcount++;
}
@@ -137,7 +177,7 @@ g10_log_fatal( const char *fmt, ... )
print_prefix("fatal: ");
va_start( arg_ptr, fmt ) ;
- vfprintf(stderr,fmt,arg_ptr) ;
+ vfprintf(logfp,fmt,arg_ptr) ;
va_end(arg_ptr);
secmem_dump_stats();
exit(2);
@@ -150,7 +190,7 @@ g10_log_fatal_f( const char *fname, const char *fmt, ... )
print_prefix_f("fatal: ", fname);
va_start( arg_ptr, fmt ) ;
- vfprintf(stderr,fmt,arg_ptr) ;
+ vfprintf(logfp,fmt,arg_ptr) ;
va_end(arg_ptr);
secmem_dump_stats();
exit(2);
@@ -192,7 +232,7 @@ g10_log_debug( const char *fmt, ... )
print_prefix("DBG: ");
va_start( arg_ptr, fmt ) ;
- vfprintf(stderr,fmt,arg_ptr) ;
+ vfprintf(logfp,fmt,arg_ptr) ;
va_end(arg_ptr);
}
@@ -203,7 +243,7 @@ g10_log_debug_f( const char *fname, const char *fmt, ... )
print_prefix_f("DBG: ", fname);
va_start( arg_ptr, fmt ) ;
- vfprintf(stderr,fmt,arg_ptr) ;
+ vfprintf(logfp,fmt,arg_ptr) ;
va_end(arg_ptr);
}
@@ -216,8 +256,8 @@ g10_log_hexdump( const char *text, const char *buf, size_t len )
print_prefix(text);
for(i=0; i < len; i++ )
- fprintf(stderr, " %02X", ((const byte*)buf)[i] );
- fputc('\n', stderr);
+ fprintf(logfp, " %02X", ((const byte*)buf)[i] );
+ fputc('\n', logfp);
}
@@ -225,7 +265,7 @@ void
g10_log_mpidump( const char *text, MPI a )
{
print_prefix(text);
- mpi_print(stderr, a, 1 );
- fputc('\n', stderr);
+ mpi_print(logfp, a, 1 );
+ fputc('\n', logfp);
}
diff --git a/util/strgutil.c b/util/strgutil.c
index ab0d2234a..11291766b 100644
--- a/util/strgutil.c
+++ b/util/strgutil.c
@@ -47,6 +47,7 @@ static ushort koi82unicode[128] = {
0x042c,0x042b,0x0417,0x0428,0x042d,0x0429,0x0427,0x042a
};
+#if 0
static ushort latin2_unicode[128] = {
0x0080,0x0081,0x0082,0x0083,0x0084,0x0085,0x0086,0x0087,
0x0088,0x0089,0x008A,0x008B,0x008C,0x008D,0x008E,0x008F,
@@ -65,7 +66,7 @@ static ushort latin2_unicode[128] = {
0x0111,0x0144,0x0148,0x00F3,0x00F4,0x0151,0x00F6,0x00F7,
0x0159,0x016F,0x00FA,0x0171,0x00FC,0x00FD,0x0163,0x02D9
};
-
+#endif
void