From c84fdfbe620ed3e9d4d3f6c03b3fcea8a1685c72 Mon Sep 17 00:00:00 2001 From: David Shaw Date: Sat, 24 May 2003 16:53:14 +0000 Subject: [PATCH] * argparse.c, dotlock.c, fileutil.c, iobuf.c, miscutil.c, simple-gettext.c, errors.c, http.c, memory.c, secmem.c, ttyio.c: Edit all preprocessor instructions to remove whitespace before the '#'. This is not required by C89, but there are some compilers out there that don't like it. --- util/ChangeLog | 8 +++ util/argparse.c | 4 +- util/dotlock.c | 39 ++++++------ util/errors.c | 5 +- util/fileutil.c | 12 ++-- util/http.c | 38 +++++------ util/iobuf.c | 144 +++++++++++++++++++++--------------------- util/memory.c | 121 ++++++++++++++++++----------------- util/miscutil.c | 18 +++--- util/secmem.c | 97 ++++++++++++++-------------- util/simple-gettext.c | 4 +- util/ttyio.c | 67 ++++++++++---------- 12 files changed, 278 insertions(+), 279 deletions(-) diff --git a/util/ChangeLog b/util/ChangeLog index 4c395ff6d..e968256da 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,11 @@ +2003-05-24 David Shaw + + * argparse.c, dotlock.c, fileutil.c, iobuf.c, miscutil.c, + simple-gettext.c, errors.c, http.c, memory.c, secmem.c, ttyio.c: + Edit all preprocessor instructions to remove whitespace before the + '#'. This is not required by C89, but there are some compilers + out there that don't like it. + 2003-05-21 Werner Koch * fileutil.c (is_file_compressed): Fixed checking for "-" filename. diff --git a/util/argparse.c b/util/argparse.c index 7169f0e98..3e772d9a7 100644 --- a/util/argparse.c +++ b/util/argparse.c @@ -441,7 +441,7 @@ find_long_option( ARGPARSE_ARGS *arg, for(i=0; opts[i].short_opt; i++ ) if( opts[i].long_opt && !strcmp( opts[i].long_opt, keyword) ) return i; - #if 0 +#if 0 { ALIAS_DEF a; /* see whether it is an alias */ @@ -453,7 +453,7 @@ find_long_option( ARGPARSE_ARGS *arg, } } } - #endif +#endif /* not found, see whether it is an abbreviation */ /* aliases may not be abbreviated */ n = strlen( keyword ); diff --git a/util/dotlock.c b/util/dotlock.c index 42d06c7b4..571262674 100644 --- a/util/dotlock.c +++ b/util/dotlock.c @@ -80,9 +80,9 @@ create_dotlock( const char *file_to_lock ) DOTLOCK h; int fd = -1; char pidstr[16]; - #if !defined (HAVE_DOSISH_SYSTEM) +#if !defined (HAVE_DOSISH_SYSTEM) struct utsname utsbuf; - #endif +#endif const char *nodename; const char *dirpart; int dirpartlen; @@ -97,9 +97,9 @@ create_dotlock( const char *file_to_lock ) h = m_alloc_clear( sizeof *h ); if( never_lock ) { h->disable = 1; - #ifdef _REENTRANT +#ifdef _REENTRANT /* fixme: aquire mutex on all_lockfiles */ - #endif +#endif h->next = all_lockfiles; all_lockfiles = h; return h; @@ -134,9 +134,9 @@ create_dotlock( const char *file_to_lock ) dirpart = file_to_lock; } - #ifdef _REENTRANT +#ifdef _REENTRANT /* fixme: aquire mutex on all_lockfiles */ - #endif +#endif h->next = all_lockfiles; all_lockfiles = h; @@ -164,9 +164,9 @@ create_dotlock( const char *file_to_lock ) } if( write(fd, pidstr, 11 ) != 11 ) { all_lockfiles = h->next; - #ifdef _REENTRANT +#ifdef _REENTRANT /* release mutex */ - #endif +#endif log_fatal( "error writing to `%s': %s\n", h->tname, strerror(errno) ); close(fd); unlink(h->tname); @@ -176,9 +176,9 @@ create_dotlock( const char *file_to_lock ) } if( close(fd) ) { all_lockfiles = h->next; - #ifdef _REENTRANT +#ifdef _REENTRANT /* release mutex */ - #endif +#endif log_error( "error closing `%s': %s\n", h->tname, strerror(errno)); unlink(h->tname); m_free(h->tname); @@ -186,9 +186,9 @@ create_dotlock( const char *file_to_lock ) return NULL; } - #ifdef _REENTRANT +#ifdef _REENTRANT /* release mutex */ - #endif +#endif #endif h->lockname = m_alloc( strlen(file_to_lock) + 6 ); strcpy(stpcpy(h->lockname, file_to_lock), EXTSEP_S "lock"); @@ -271,10 +271,10 @@ make_dotlock( DOTLOCK h, long timeout ) else if( kill(pid, 0) && errno == ESRCH ) { #ifndef __riscos__ maybe_dead = " - probably dead"; - #if 0 /* we should not do this without checking the permissions */ +#if 0 /* we should not do this without checking the permissions */ /* and the hostname */ log_info( "removing stale lockfile (created by %d)", pid ); - #endif +#endif #else /* __riscos__ */ /* we are *pretty* sure that the other task is dead and therefore we remove the other lock file */ @@ -359,9 +359,9 @@ release_dotlock( DOTLOCK h ) static int read_lockfile( const char *name ) { - #if defined (HAVE_DOSISH_SYSTEM) +#if defined (HAVE_DOSISH_SYSTEM) return 0; - #else +#else int fd, pid; char pidstr[16]; @@ -390,14 +390,14 @@ read_lockfile( const char *name ) return -1; } return pid; - #endif +#endif } void remove_lockfiles() { - #if !defined (HAVE_DOSISH_SYSTEM) +#if !defined (HAVE_DOSISH_SYSTEM) DOTLOCK h, h2; h = all_lockfiles; @@ -415,6 +415,5 @@ remove_lockfiles() m_free(h); h = h2; } - #endif +#endif } - diff --git a/util/errors.c b/util/errors.c index 25d5a088a..10956a4e2 100644 --- a/util/errors.c +++ b/util/errors.c @@ -47,7 +47,7 @@ g10_errstr( int err ) static char buf[50]; const char *p; - #define X(n,s) case G10ERR_##n : p = s; break; +#define X(n,s) case G10ERR_##n : p = s; break; switch( err ) { case -1: p = "eof"; break; case 0: p = "okay"; break; @@ -107,7 +107,6 @@ g10_errstr( int err ) X(KEYSERVER ,N_("keyserver error")) default: p = buf; sprintf(buf, "g10err=%d", err); break; } - #undef X +#undef X return _(p); } - diff --git a/util/fileutil.c b/util/fileutil.c index 4a609138a..c36488640 100644 --- a/util/fileutil.c +++ b/util/fileutil.c @@ -71,10 +71,10 @@ make_dirname(const char *filepath) char *p; if ( !(p=strrchr(filepath, DIRSEP_C)) ) - #ifdef HAVE_DRIVE_LETTERS +#ifdef HAVE_DRIVE_LETTERS if ( !(p=strrchr(filepath, '\\')) ) if ( !(p=strrchr(filepath, ':')) ) - #endif +#endif { return m_strdup(EXTSEP_S); } @@ -138,11 +138,11 @@ compare_filenames( const char *a, const char *b ) * resolve symlinks? */ #ifndef __riscos__ - #ifdef HAVE_DRIVE_LETTERS +#ifdef HAVE_DRIVE_LETTERS return ascii_strcasecmp(a,b); - #else +#else return strcmp(a,b); - #endif +#endif #else /* __riscos__ */ int c = 0; char *abuf, *bbuf; @@ -231,5 +231,3 @@ leave: iobuf_close( a ); return rc; } - - diff --git a/util/http.c b/util/http.c index 4cc31e3c0..a328fbd0d 100644 --- a/util/http.c +++ b/util/http.c @@ -27,16 +27,16 @@ #include #ifdef __MINGW32__ - #include +#include #else - #include - #include - #include - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include +#include +#include #endif #include "util.h" @@ -46,11 +46,11 @@ #include "srv.h" #ifdef __riscos__ - #define HTTP_PROXY_ENV "GnuPG$HttpProxy" - #define HTTP_PROXY_ENV_PRINTABLE "" +#define HTTP_PROXY_ENV "GnuPG$HttpProxy" +#define HTTP_PROXY_ENV_PRINTABLE "" #else - #define HTTP_PROXY_ENV "http_proxy" - #define HTTP_PROXY_ENV_PRINTABLE "$http_proxy" +#define HTTP_PROXY_ENV "http_proxy" +#define HTTP_PROXY_ENV_PRINTABLE "$http_proxy" #endif #ifdef __MINGW32__ @@ -66,7 +66,7 @@ "!\"#$%&'()*+,-./:;<=>?[\\]^_{|}~" #ifndef EAGAIN - #define EAGAIN EWOULDBLOCK +#define EAGAIN EWOULDBLOCK #endif static int parse_uri( PARSED_URI *ret_uri, const char *uri ); @@ -172,11 +172,11 @@ http_wait_response( HTTP_HD hd, unsigned int *ret_status ) http_start_data( hd ); /* make sure that we are in the data */ - #if 0 +#if 0 hd->sock = dup( hd->sock ); if( hd->sock == -1 ) return G10ERR_GENERAL; - #endif +#endif iobuf_ioctl (hd->fp_write, 1, 1, NULL); /* keep the socket open */ iobuf_close (hd->fp_write); hd->fp_write = NULL; @@ -843,7 +843,7 @@ write_server( int sock, const char *data, size_t length ) nleft = length; while( nleft > 0 ) { - #ifdef __MINGW32__ +#ifdef __MINGW32__ int nwritten; nwritten = send (sock, data, nleft, 0); @@ -851,7 +851,7 @@ write_server( int sock, const char *data, size_t length ) log_info ("write failed: ec=%d\n", (int)WSAGetLastError ()); return G10ERR_NETWORK; } - #else +#else int nwritten = write( sock, data, nleft ); if( nwritten == -1 ) { if( errno == EINTR ) @@ -867,7 +867,7 @@ write_server( int sock, const char *data, size_t length ) log_info("write failed: %s\n", strerror(errno)); return G10ERR_NETWORK; } - #endif +#endif nleft -=nwritten; data += nwritten; } diff --git a/util/iobuf.c b/util/iobuf.c index 415fc6d20..4d866c1e4 100644 --- a/util/iobuf.c +++ b/util/iobuf.c @@ -30,7 +30,7 @@ #include #include #ifdef HAVE_DOSISH_SYSTEM - #include +#include #endif #ifdef __riscos__ #include @@ -44,18 +44,18 @@ #undef FILE_FILTER_USES_STDIO #ifdef HAVE_DOSISH_SYSTEM - #define USE_SETMODE 1 +#define USE_SETMODE 1 #endif #ifdef FILE_FILTER_USES_STDIO - #define my_fileno(a) fileno ((a)) - #define my_fopen_ro(a,b) fopen ((a),(b)) - #define my_fopen(a,b) fopen ((a),(b)) - typedef FILE *FILEP_OR_FD; - #define INVALID_FP NULL - #define FILEP_OR_FD_FOR_STDIN (stdin) - #define FILEP_OR_FD_FOR_STDOUT (stdout) - typedef struct { +#define my_fileno(a) fileno ((a)) +#define my_fopen_ro(a,b) fopen ((a),(b)) +#define my_fopen(a,b) fopen ((a),(b)) +typedef FILE *FILEP_OR_FD; +#define INVALID_FP NULL +#define FILEP_OR_FD_FOR_STDIN (stdin) +#define FILEP_OR_FD_FOR_STDOUT (stdout) +typedef struct { FILE *fp; /* open file handle */ int keep_open; int no_cache; @@ -63,22 +63,22 @@ char fname[1]; /* name of the file */ } file_filter_ctx_t ; #else - #define my_fileno(a) (a) - #define my_fopen_ro(a,b) fd_cache_open ((a),(b)) - #define my_fopen(a,b) direct_open ((a),(b)) - #ifdef HAVE_DOSISH_SYSTEM - typedef HANDLE FILEP_OR_FD; - #define INVALID_FP ((HANDLE)-1) - #define FILEP_OR_FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) - #define FILEP_OR_FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) - #undef USE_SETMODE - #else - typedef int FILEP_OR_FD; - #define INVALID_FP (-1) - #define FILEP_OR_FD_FOR_STDIN (0) - #define FILEP_OR_FD_FOR_STDOUT (1) - #endif - typedef struct { +#define my_fileno(a) (a) +#define my_fopen_ro(a,b) fd_cache_open ((a),(b)) +#define my_fopen(a,b) direct_open ((a),(b)) +#ifdef HAVE_DOSISH_SYSTEM +typedef HANDLE FILEP_OR_FD; +#define INVALID_FP ((HANDLE)-1) +#define FILEP_OR_FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) +#define FILEP_OR_FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) +#undef USE_SETMODE +#else +typedef int FILEP_OR_FD; +#define INVALID_FP (-1) +#define FILEP_OR_FD_FOR_STDIN (0) +#define FILEP_OR_FD_FOR_STDOUT (1) +#endif +typedef struct { FILEP_OR_FD fp; /* open file handle */ int keep_open; int no_cache; @@ -147,11 +147,11 @@ fd_cache_invalidate (const char *fname) if ( cc->fp != INVALID_FP && !strcmp (cc->fname, fname) ) { if( DBG_IOBUF ) log_debug (" did (%s)\n", cc->fname); - #ifdef HAVE_DOSISH_SYSTEM +#ifdef HAVE_DOSISH_SYSTEM CloseHandle (cc->fp); - #else +#else close(cc->fp); - #endif +#endif cc->fp = INVALID_FP; } } @@ -284,18 +284,18 @@ fd_cache_open (const char *fname, const char *mode) cc->fp = INVALID_FP; if( DBG_IOBUF ) log_debug ("fd_cache_open (%s) using cached fp\n", fname); - #ifdef HAVE_DOSISH_SYSTEM +#ifdef HAVE_DOSISH_SYSTEM if (SetFilePointer (fp, 0, NULL, FILE_BEGIN) == 0xffffffff ) { log_error ("rewind file failed on handle %p: ec=%d\n", fp, (int)GetLastError () ); fp = INVALID_FP; } - #else +#else if ( lseek (fp, 0, SEEK_SET) == (off_t)-1 ) { log_error("can't rewind fd %d: %s\n", fp, strerror(errno) ); fp = INVALID_FP; } - #endif +#endif return fp; } } @@ -398,7 +398,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) *ret_len = 0; } else { - #ifdef HAVE_DOSISH_SYSTEM +#ifdef HAVE_DOSISH_SYSTEM unsigned long nread; nbytes = 0; @@ -417,7 +417,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) nbytes = nread; } - #else +#else int n; @@ -439,13 +439,13 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) else { nbytes = n; } - #endif +#endif *ret_len = nbytes; } } else if( control == IOBUFCTRL_FLUSH ) { if( size ) { - #ifdef HAVE_DOSISH_SYSTEM +#ifdef HAVE_DOSISH_SYSTEM byte *p = buf; unsigned long n; @@ -461,7 +461,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) nbytes -= n; } while ( nbytes ); nbytes = p - buf; - #else +#else byte *p = buf; int n; @@ -480,7 +480,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) rc = G10ERR_WRITE_FILE; } nbytes = p - buf; - #endif +#endif } *ret_len = nbytes; } @@ -493,14 +493,14 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) *(char**)buf = "file_filter(fd)"; } else if ( control == IOBUFCTRL_FREE ) { - #ifdef HAVE_DOSISH_SYSTEM +#ifdef HAVE_DOSISH_SYSTEM if ( f != FILEP_OR_FD_FOR_STDIN && f != FILEP_OR_FD_FOR_STDOUT ) { if( DBG_IOBUF ) log_debug("%s: close handle %p\n", a->fname, f ); if (!a->keep_open) fd_cache_close (a->no_cache?NULL:a->fname, f); } - #else +#else if ( (int)f != 0 && (int)f != 1 ) { if( DBG_IOBUF ) log_debug("%s: close fd %d\n", a->fname, f ); @@ -508,7 +508,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) fd_cache_close (a->no_cache?NULL:a->fname, f); } f = INVALID_FP; - #endif +#endif m_free (a); /* we can free our context now */ } #endif /* !stdio implementation */ @@ -950,18 +950,18 @@ iobuf_cancel( IOBUF a ) const char *s; IOBUF a2; int rc; - #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) +#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) char *remove_name = NULL; - #endif +#endif if( a && a->use == 2 ) { s = iobuf_get_real_fname(a); if( s && *s ) { - #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) +#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) remove_name = m_strdup ( s ); - #else +#else remove(s); - #endif +#endif } } @@ -974,14 +974,14 @@ iobuf_cancel( IOBUF a ) } rc = iobuf_close(a); - #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) +#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) if ( remove_name ) { /* Argg, MSDOS does not allow to remove open files. So * we have to do it here */ remove ( remove_name ); m_free ( remove_name ); } - #endif +#endif return rc; } @@ -1056,9 +1056,9 @@ iobuf_open( const char *fname ) if( !fname || (*fname=='-' && !fname[1]) ) { fp = FILEP_OR_FD_FOR_STDIN; - #ifdef USE_SETMODE +#ifdef USE_SETMODE setmode ( my_fileno(fp) , O_BINARY ); - #endif +#endif fname = "[stdin]"; print_only = 1; } @@ -1159,9 +1159,9 @@ iobuf_create( const char *fname ) if( !fname || (*fname=='-' && !fname[1]) ) { fp = FILEP_OR_FD_FOR_STDOUT; - #ifdef USE_SETMODE +#ifdef USE_SETMODE setmode ( my_fileno(fp) , O_BINARY ); - #endif +#endif fname = "[stdout]"; print_only = 1; } @@ -1261,22 +1261,22 @@ iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval ) b->keep_open = intval; return 0; } - #ifdef __MINGW32__ +#ifdef __MINGW32__ else if( !a->chain && a->filter == sock_filter ) { sock_filter_ctx_t *b = a->filter_ov; b->keep_open = intval; return 0; } - #endif +#endif } else if ( cmd == 2 ) { /* invalidate cache */ if( DBG_IOBUF ) log_debug("iobuf-*.*: ioctl `%s' invalidate\n", ptrval? (char*)ptrval:"?"); if ( !a && !intval && ptrval ) { - #ifndef FILE_FILTER_USES_STDIO +#ifndef FILE_FILTER_USES_STDIO fd_cache_invalidate (ptrval); - #endif +#endif return 0; } } @@ -1290,13 +1290,13 @@ iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval ) b->no_cache = intval; return 0; } - #ifdef __MINGW32__ +#ifdef __MINGW32__ else if( !a->chain && a->filter == sock_filter ) { sock_filter_ctx_t *b = a->filter_ov; b->no_cache = intval; return 0; } - #endif +#endif } return -1; @@ -1857,18 +1857,18 @@ iobuf_get_filelength( IOBUF a ) file_filter_ctx_t *b = a->filter_ov; FILEP_OR_FD fp = b->fp; - #if defined(HAVE_DOSISH_SYSTEM) && !defined(FILE_FILTER_USES_STDIO) +#if defined(HAVE_DOSISH_SYSTEM) && !defined(FILE_FILTER_USES_STDIO) ulong size; if ( (size=GetFileSize (fp, NULL)) != 0xffffffff ) return size; log_error ("GetFileSize for handle %p failed: ec=%d\n", fp, (int)GetLastError () ); - #else +#else if( !fstat(my_fileno(fp), &st) ) return st.st_size; log_error("fstat() failed: %s\n", strerror(errno) ); - #endif +#endif break; } @@ -1946,18 +1946,18 @@ iobuf_seek( IOBUF a, off_t newpos ) return -1; } #else - #ifdef HAVE_DOSISH_SYSTEM +#ifdef HAVE_DOSISH_SYSTEM if (SetFilePointer (b->fp, newpos, NULL, FILE_BEGIN) == 0xffffffff ) { log_error ("SetFilePointer failed on handle %p: ec=%d\n", b->fp, (int)GetLastError () ); return -1; } - #else +#else if ( lseek (b->fp, newpos, SEEK_SET) == (off_t)-1 ) { log_error("can't lseek: %s\n", strerror(errno) ); return -1; } - #endif +#endif #endif } a->d.len = 0; /* discard buffer */ @@ -2141,7 +2141,7 @@ iobuf_read_line( IOBUF a, byte **addr_of_buffer, int iobuf_translate_file_handle ( int fd, int for_write ) { - #ifdef __MINGW32__ +#ifdef __MINGW32__ { int x; @@ -2157,17 +2157,17 @@ iobuf_translate_file_handle ( int fd, int for_write ) fd = x; } } - #endif +#endif return fd; } static int translate_file_handle ( int fd, int for_write ) { - #ifdef __MINGW32__ - #ifdef FILE_FILTER_USES_STDIO +#ifdef __MINGW32__ +#ifdef FILE_FILTER_USES_STDIO fd = iobuf_translate_file_handle (fd, for_write); - #else +#else { int x; @@ -2186,9 +2186,7 @@ translate_file_handle ( int fd, int for_write ) fd = x; } - #endif - #endif +#endif +#endif return fd; } - - diff --git a/util/memory.c b/util/memory.c index 9fab9ea3b..cb8a3b3e3 100644 --- a/util/memory.c +++ b/util/memory.c @@ -48,9 +48,9 @@ * replace this guard stuff with one provided by a modern malloc library */ #if SIZEOF_UNSIGNED_LONG == 8 - #define EXTRA_ALIGN 4 +#define EXTRA_ALIGN 4 #else - #define EXTRA_ALIGN 0 +#define EXTRA_ALIGN 0 #endif #if defined(M_DEBUG) || defined(M_GUARD) @@ -59,32 +59,32 @@ #ifdef M_DEBUG - #ifndef M_GUARD - #define M_GUARD 1 - #endif - #undef m_alloc - #undef m_alloc_clear - #undef m_alloc_secure - #undef m_alloc_secure_clear - #undef m_realloc - #undef m_free - #undef m_check - #undef m_strdup - #define FNAME(a) m_debug_ ##a - #define FNAMEPRT , const char *info - #define FNAMEARG , info - #ifndef __riscos__ - #define store_len(p,n,m) do { add_entry(p,n,m, \ +#ifndef M_GUARD +#define M_GUARD 1 +#endif +#undef m_alloc +#undef m_alloc_clear +#undef m_alloc_secure +#undef m_alloc_secure_clear +#undef m_realloc +#undef m_free +#undef m_check +#undef m_strdup +#define FNAME(a) m_debug_ ##a +#define FNAMEPRT , const char *info +#define FNAMEARG , info +#ifndef __riscos__ +#define store_len(p,n,m) do { add_entry(p,n,m, \ info, __FUNCTION__); } while(0) - #else - #define store_len(p,n,m) do { add_entry(p,n,m, \ - info, __func__ ); } while(0) - #endif #else - #define FNAME(a) m_ ##a - #define FNAMEPRT - #define FNAMEARG - #define store_len(p,n,m) do { ((byte*)p)[EXTRA_ALIGN+0] = n; \ +#define store_len(p,n,m) do { add_entry(p,n,m, \ + info, __func__ ); } while(0) +#endif +#else +#define FNAME(a) m_ ##a +#define FNAMEPRT +#define FNAMEARG +#define store_len(p,n,m) do { ((byte*)p)[EXTRA_ALIGN+0] = n; \ ((byte*)p)[EXTRA_ALIGN+1] = n >> 8 ; \ ((byte*)p)[EXTRA_ALIGN+2] = n >> 16 ; \ ((byte*)p)[EXTRA_ALIGN+3] = m? MAGIC_SEC_BYTE \ @@ -332,11 +332,11 @@ check_allmem( const char *info ) for( e = memtbl, n = 0; n < memtbl_len; n++, e++ ) { if( e->inuse ) { - #ifndef __riscos__ +#ifndef __riscos__ check_mem(e->user_p-4-EXTRA_ALIGN, info); - #else +#else check_mem((const byte *) e->user_p-4-EXTRA_ALIGN, info); - #endif +#endif } } } @@ -354,10 +354,10 @@ membug( const char *fmt, ... ) vfprintf(stderr,fmt,arg_ptr) ; va_end(arg_ptr); fflush(stderr); - #ifdef M_DEBUG +#ifdef M_DEBUG if( DBG_MEMSTAT ) dump_table(); - #endif +#endif abort(); } #endif @@ -365,7 +365,7 @@ membug( const char *fmt, ... ) void m_print_stats( const char *prefix ) { - #ifdef M_DEBUG +#ifdef M_DEBUG unsigned n; struct memtbl_entry *e; ulong sum = 0, chunks =0; @@ -379,19 +379,19 @@ m_print_stats( const char *prefix ) log_debug( "%s%smemstat: %8lu bytes in %ld chunks used\n", prefix? prefix:"", prefix? ": ":"", sum, chunks ); - #elif defined(M_GUARD) +#elif defined(M_GUARD) log_debug( "%s%smemstat: %8ld bytes\n", prefix? prefix:"", prefix? ": ":"", used_memory ); - #endif +#endif } void m_dump_table( const char *prefix ) { - #ifdef M_DEBUG +#ifdef M_DEBUG fprintf(stderr,"Memory-Table-Dump: %s\n", prefix); dump_table(); - #endif +#endif m_print_stats( prefix ); } @@ -418,7 +418,7 @@ FNAME(alloc)( size_t n FNAMEPRT ) { char *p; - #ifdef M_GUARD +#ifdef M_GUARD if(!n) out_of_core(n,0); /* should never happen */ if( !(p = malloc( n + EXTRA_ALIGN+5 )) ) @@ -427,7 +427,7 @@ FNAME(alloc)( size_t n FNAMEPRT ) used_memory += n; p[4+EXTRA_ALIGN+n] = MAGIC_END_BYTE; return p+EXTRA_ALIGN+4; - #else +#else /* mallocing zero bytes is undefined by ISO-C, so we better make sure that it won't happen */ if (!n) @@ -435,7 +435,7 @@ FNAME(alloc)( size_t n FNAMEPRT ) if( !(p = malloc( n )) ) out_of_core(n,0); return p; - #endif +#endif } /**************** @@ -447,7 +447,7 @@ FNAME(alloc_secure)( size_t n FNAMEPRT ) { char *p; - #ifdef M_GUARD +#ifdef M_GUARD if(!n) out_of_core(n,1); /* should never happen */ if( !(p = secmem_malloc( n +EXTRA_ALIGN+ 5 )) ) @@ -455,7 +455,7 @@ FNAME(alloc_secure)( size_t n FNAMEPRT ) store_len(p,n,1); p[4+EXTRA_ALIGN+n] = MAGIC_END_BYTE; return p+EXTRA_ALIGN+4; - #else +#else /* mallocing zero bytes is undefined by ISO-C, so we better make sure that it won't happen */ if (!n) @@ -463,7 +463,7 @@ FNAME(alloc_secure)( size_t n FNAMEPRT ) if( !(p = secmem_malloc( n )) ) out_of_core(n,1); return p; - #endif +#endif } void * @@ -493,7 +493,7 @@ FNAME(realloc)( void *a, size_t n FNAMEPRT ) { void *b; - #ifdef M_GUARD +#ifdef M_GUARD if( a ) { unsigned char *p = a; size_t len = m_size(a); @@ -510,7 +510,7 @@ FNAME(realloc)( void *a, size_t n FNAMEPRT ) } else b = FNAME(alloc)(n FNAMEARG); - #else +#else if( m_is_secure(a) ) { if( !(b = secmem_realloc( a, n )) ) out_of_core(n,1); @@ -519,7 +519,7 @@ FNAME(realloc)( void *a, size_t n FNAMEPRT ) if( !(b = realloc( a, n )) ) out_of_core(n,0); } - #endif +#endif return b; } @@ -536,9 +536,9 @@ FNAME(free)( void *a FNAMEPRT ) if( !p ) return; - #ifdef M_DEBUG +#ifdef M_DEBUG free_entry(p-EXTRA_ALIGN-4, info); - #elif defined M_GUARD +#elif defined M_GUARD m_check(p); if( m_is_secure(a) ) secmem_free(p-EXTRA_ALIGN-4); @@ -546,57 +546,57 @@ FNAME(free)( void *a FNAMEPRT ) used_memory -= m_size(a); free(p-EXTRA_ALIGN-4); } - #else +#else if( m_is_secure(a) ) secmem_free(p); else free(p); - #endif +#endif } void FNAME(check)( const void *a FNAMEPRT ) { - #ifdef M_GUARD +#ifdef M_GUARD const byte *p = a; - #ifdef M_DEBUG +#ifdef M_DEBUG if( p ) check_mem(p-EXTRA_ALIGN-4, info); else check_allmem(info); - #else +#else if( !p ) return; if( !(p[-1] == MAGIC_NOR_BYTE || p[-1] == MAGIC_SEC_BYTE) ) membug("memory at %p corrupted (underflow=%02x)\n", p, p[-1] ); else if( p[m_size(p)] != MAGIC_END_BYTE ) membug("memory at %p corrupted (overflow=%02x)\n", p, p[-1] ); - #endif - #endif +#endif +#endif } size_t m_size( const void *a ) { - #ifndef M_GUARD +#ifndef M_GUARD log_debug("dummy m_size called\n"); return 0; - #else +#else const byte *p = a; size_t n; - #ifdef M_DEBUG +#ifdef M_DEBUG n = check_mem(p-EXTRA_ALIGN-4, "m_size")->user_n; - #else +#else n = ((byte*)p)[-4]; n |= ((byte*)p)[-3] << 8; n |= ((byte*)p)[-2] << 16; - #endif +#endif return n; - #endif +#endif } @@ -631,4 +631,3 @@ FNAME(strdup)( const char *a FNAMEPRT ) strcpy(p, a); return p; } - diff --git a/util/miscutil.c b/util/miscutil.c index e1735cd59..42b2b3a88 100644 --- a/util/miscutil.c +++ b/util/miscutil.c @@ -25,7 +25,7 @@ #include #include #ifdef HAVE_LANGINFO_H - #include +#include #endif #include "types.h" #include "util.h" @@ -143,9 +143,9 @@ const char * asctimestamp( u32 stamp ) { static char buffer[50]; - #if defined (HAVE_STRFTIME) && defined (HAVE_NL_LANGINFO) +#if defined (HAVE_STRFTIME) && defined (HAVE_NL_LANGINFO) static char fmt[50]; - #endif +#endif struct tm *tp; time_t atime = stamp; @@ -155,23 +155,23 @@ asctimestamp( u32 stamp ) } tp = localtime( &atime ); - #ifdef HAVE_STRFTIME - #if defined(HAVE_NL_LANGINFO) +#ifdef HAVE_STRFTIME +#if defined(HAVE_NL_LANGINFO) mem2str( fmt, nl_langinfo(D_T_FMT), DIM(fmt)-3 ); if( strstr( fmt, "%Z" ) == NULL ) strcat( fmt, " %Z"); strftime( buffer, DIM(buffer)-1, fmt, tp ); - #else +#else /* fixme: we should check whether the locale appends a " %Z" * These locales from glibc don't put the " %Z": * fi_FI hr_HR ja_JP lt_LT lv_LV POSIX ru_RU ru_SU sv_FI sv_SE zh_CN */ strftime( buffer, DIM(buffer)-1, "%c %Z", tp ); - #endif +#endif buffer[DIM(buffer)-1] = 0; - #else +#else mem2str( buffer, asctime(tp), DIM(buffer) ); - #endif +#endif return buffer; } diff --git a/util/secmem.c b/util/secmem.c index 681329618..7dfa668c2 100644 --- a/util/secmem.c +++ b/util/secmem.c @@ -26,15 +26,15 @@ #include #include #if defined(HAVE_MLOCK) || defined(HAVE_MMAP) - #include - #include - #include - #ifdef USE_CAPABILITIES - #include - #endif - #ifdef HAVE_PLOCK - #include - #endif +#include +#include +#include +#ifdef USE_CAPABILITIES +#include +#endif +#ifdef HAVE_PLOCK +#include +#endif #endif #include "types.h" @@ -43,11 +43,11 @@ #include "i18n.h" #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) - #define MAP_ANONYMOUS MAP_ANON +#define MAP_ANONYMOUS MAP_ANON #endif /* It seems that Slackware 7.1 does not know about EPERM */ #if !defined(EPERM) && defined(ENOMEM) - #define EPERM ENOMEM +#define EPERM ENOMEM #endif @@ -97,7 +97,7 @@ print_warn(void) static void lock_pool( void *p, size_t n ) { - #if defined(USE_CAPABILITIES) && defined(HAVE_MLOCK) +#if defined(USE_CAPABILITIES) && defined(HAVE_MLOCK) int err; cap_set_proc( cap_from_text("cap_ipc_lock+ep") ); @@ -108,30 +108,30 @@ lock_pool( void *p, size_t n ) if( err ) { if( errno != EPERM - #ifdef EAGAIN /* OpenBSD returns this */ +#ifdef EAGAIN /* OpenBSD returns this */ && errno != EAGAIN - #endif - #ifdef ENOSYS /* Some SCOs return this (function not implemented) */ +#endif +#ifdef ENOSYS /* Some SCOs return this (function not implemented) */ && errno != ENOSYS - #endif - #ifdef ENOMEM /* Linux can return this */ +#endif +#ifdef ENOMEM /* Linux can return this */ && errno != ENOMEM - #endif +#endif ) log_error("can't lock memory: %s\n", strerror(err)); show_warning = 1; } - #elif defined(HAVE_MLOCK) +#elif defined(HAVE_MLOCK) uid_t uid; int err; uid = getuid(); - #ifdef HAVE_BROKEN_MLOCK +#ifdef HAVE_BROKEN_MLOCK /* ick. but at least we get secured memory. about to lock entire data segment. */ - #ifdef HAVE_PLOCK +#ifdef HAVE_PLOCK err = plock( DATLOCK ); if( err && errno ) err = errno; @@ -145,12 +145,12 @@ lock_pool( void *p, size_t n ) if( err && errno ) err = errno; } - #endif /*!HAVE_PLOCK*/ - #else +#endif /*!HAVE_PLOCK*/ +#else err = mlock( p, n ); if( err && errno ) err = errno; - #endif +#endif if( uid && !geteuid() ) { /* check that we really dropped the privs. @@ -161,38 +161,38 @@ lock_pool( void *p, size_t n ) if( err ) { if( errno != EPERM - #ifdef EAGAIN /* OpenBSD returns this */ +#ifdef EAGAIN /* OpenBSD returns this */ && errno != EAGAIN - #endif - #ifdef ENOSYS /* Some SCOs return this (function not implemented) */ +#endif +#ifdef ENOSYS /* Some SCOs return this (function not implemented) */ && errno != ENOSYS - #endif - #ifdef ENOMEM /* Linux can return this */ +#endif +#ifdef ENOMEM /* Linux can return this */ && errno != ENOMEM - #endif +#endif ) log_error("can't lock memory: %s\n", strerror(err)); show_warning = 1; } - #elif defined ( __QNX__ ) +#elif defined ( __QNX__ ) /* QNX does not page at all, so the whole secure memory stuff does * not make much sense. However it is still of use because it * wipes out the memory on a free(). * Therefore it is sufficient to suppress the warning */ - #elif defined (HAVE_DOSISH_SYSTEM) || defined (__CYGWIN__) +#elif defined (HAVE_DOSISH_SYSTEM) || defined (__CYGWIN__) /* It does not make sense to print such a warning, given the fact that * this whole Windows !@#$% and their user base are inherently insecure */ - #elif defined (__riscos__) +#elif defined (__riscos__) /* no virtual memory on RISC OS, so no pages are swapped to disc, * besides we don't have mmap, so we don't use it! ;-) * But don't complain, as explained above. */ - #else +#else log_info("Please note that you don't have secure memory on this system\n"); - #endif +#endif } @@ -206,18 +206,18 @@ init_pool( size_t n) if( disable_secmem ) log_bug("secure memory is disabled"); - #ifdef HAVE_GETPAGESIZE +#ifdef HAVE_GETPAGESIZE pgsize = getpagesize(); - #else +#else pgsize = 4096; - #endif +#endif - #ifdef HAVE_MMAP +#ifdef HAVE_MMAP poolsize = (poolsize + pgsize -1 ) & ~(pgsize-1); - #ifdef MAP_ANONYMOUS +#ifdef MAP_ANONYMOUS pool = mmap( 0, poolsize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - #else /* map /dev/zero instead */ +#else /* map /dev/zero instead */ { int fd; fd = open("/dev/zero", O_RDWR); @@ -230,7 +230,7 @@ init_pool( size_t n) MAP_PRIVATE, fd, 0); } } - #endif +#endif if( pool == (void*)-1 ) log_info("can't mmap pool of %u bytes: %s - using malloc\n", (unsigned)poolsize, strerror(errno)); @@ -239,7 +239,7 @@ init_pool( size_t n) pool_okay = 1; } - #endif +#endif if( !pool_okay ) { pool = malloc( poolsize ); if( !pool ) @@ -290,11 +290,11 @@ secmem_init( size_t n ) { if( !n ) { #ifndef __riscos__ - #ifdef USE_CAPABILITIES +#ifdef USE_CAPABILITIES /* drop all capabilities */ cap_set_proc( cap_from_text("all-eip") ); - #elif !defined(HAVE_DOSISH_SYSTEM) +#elif !defined(HAVE_DOSISH_SYSTEM) uid_t uid; disable_secmem=1; @@ -303,7 +303,7 @@ secmem_init( size_t n ) if( setuid( uid ) || getuid() != geteuid() || !setuid(0) ) log_fatal("failed to drop setuid\n" ); } - #endif +#endif #endif /* !__riscos__ */ } else { @@ -445,10 +445,10 @@ secmem_term() wipememory2( pool, 0xaa, poolsize); wipememory2( pool, 0x55, poolsize); wipememory2( pool, 0x00, poolsize); - #ifdef HAVE_MMAP +#ifdef HAVE_MMAP if( pool_is_mmapped ) munmap( pool, poolsize ); - #endif +#endif pool = NULL; pool_okay = 0; poolsize=0; @@ -467,4 +467,3 @@ secmem_dump_stats() cur_alloced, max_alloced, cur_blocks, max_blocks, (ulong)poollen, (ulong)poolsize ); } - diff --git a/util/simple-gettext.c b/util/simple-gettext.c index b5ee446cb..5d29804f1 100644 --- a/util/simple-gettext.c +++ b/util/simple-gettext.c @@ -235,11 +235,11 @@ set_gettext_file( const char *filename ) if( filename && *filename ) { if( filename[0] == '/' - #ifdef HAVE_DRIVE_LETTERS +#ifdef HAVE_DRIVE_LETTERS || ( isalpha(filename[0]) && filename[1] == ':' && (filename[2] == '/' || filename[2] == '\\') ) - #endif +#endif ) { /* absolute path - use it as is */ domain = load_domain( filename ); diff --git a/util/ttyio.c b/util/ttyio.c index e5b2b581a..955dd1b4c 100644 --- a/util/ttyio.c +++ b/util/ttyio.c @@ -25,23 +25,23 @@ #include #include #ifdef HAVE_TCGETATTR - #include +#include #else - #ifdef HAVE_TERMIO_H - /* simulate termios with termio */ - #include - #define termios termio - #define tcsetattr ioctl - #define TCSAFLUSH TCSETAF - #define tcgetattr(A,B) ioctl(A,TCGETA,B) - #define HAVE_TCGETATTR - #endif +#ifdef HAVE_TERMIO_H +/* simulate termios with termio */ +#include +#define termios termio +#define tcsetattr ioctl +#define TCSAFLUSH TCSETAF +#define tcgetattr(A,B) ioctl(A,TCGETA,B) +#define HAVE_TCGETATTR +#endif #endif #ifdef __MINGW32__ /* use the odd Win32 functions */ - #include - #ifdef HAVE_TCGETATTR - #error mingw32 and termios - #endif +#include +#ifdef HAVE_TCGETATTR +#error mingw32 and termios +#endif #endif #include #include @@ -192,7 +192,7 @@ tty_printf( const char *fmt, ... ) init_ttyfp(); va_start( arg_ptr, fmt ) ; - #ifdef __MINGW32__ +#ifdef __MINGW32__ { char *buf = NULL; int n; @@ -209,10 +209,10 @@ tty_printf( const char *fmt, ... ) last_prompt_len += n; m_free (buf); } - #else +#else last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ; fflush(ttyfp); - #endif +#endif va_end(arg_ptr); } @@ -229,7 +229,7 @@ tty_print_string( byte *p, size_t n ) if( !initialized ) init_ttyfp(); - #ifdef __MINGW32__ +#ifdef __MINGW32__ /* not so effective, change it if you want */ for( ; n; n--, p++ ) if( iscntrl( *p ) ) { @@ -242,7 +242,7 @@ tty_print_string( byte *p, size_t n ) } else tty_printf("%c", *p); - #else +#else for( ; n; n--, p++ ) if( iscntrl( *p ) ) { putc('\\', ttyfp); @@ -255,7 +255,7 @@ tty_print_string( byte *p, size_t n ) } else putc(*p, ttyfp); - #endif +#endif } void @@ -300,9 +300,9 @@ static char * do_get( const char *prompt, int hidden ) { char *buf; - #ifndef __riscos__ +#ifndef __riscos__ byte cbuf[1]; - #endif +#endif int c, n, i; if( batchmode ) { @@ -323,7 +323,7 @@ do_get( const char *prompt, int hidden ) buf = m_alloc(n=50); i = 0; - #ifdef __MINGW32__ /* windoze version */ +#ifdef __MINGW32__ /* windoze version */ if( hidden ) SetConsoleMode(con.in, HID_INPMODE ); @@ -357,7 +357,7 @@ do_get( const char *prompt, int hidden ) if( hidden ) SetConsoleMode(con.in, DEF_INPMODE ); - #elif defined(__riscos__) +#elif defined(__riscos__) do { c = riscos_getchar(); if (c == 0xa || c == 0xd) { /* Return || Enter */ @@ -397,9 +397,9 @@ do_get( const char *prompt, int hidden ) } } while (c != '\n'); i = (i>0) ? i-1 : 0; - #else /* unix version */ +#else /* unix version */ if( hidden ) { - #ifdef HAVE_TCGETATTR +#ifdef HAVE_TCGETATTR struct termios term; if( tcgetattr(fileno(ttyfp), &termsave) ) @@ -409,7 +409,7 @@ do_get( const char *prompt, int hidden ) term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); if( tcsetattr( fileno(ttyfp), TCSAFLUSH, &term ) ) log_fatal("tcsetattr() failed: %s\n", strerror(errno) ); - #endif +#endif } /* fixme: How can we avoid that the \n is echoed w/o disabling @@ -440,13 +440,13 @@ do_get( const char *prompt, int hidden ) if( hidden ) { - #ifdef HAVE_TCGETATTR +#ifdef HAVE_TCGETATTR if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) ) log_error("tcsetattr() failed: %s\n", strerror(errno) ); restore_termios = 0; - #endif +#endif } - #endif /* end unix version */ +#endif /* end unix version */ buf[i] = 0; return buf; } @@ -478,9 +478,9 @@ tty_kill_prompt() last_prompt_len = 0; if( !last_prompt_len ) return; - #ifdef __MINGW32__ +#ifdef __MINGW32__ tty_printf("\r%*s\r", last_prompt_len, ""); - #else +#else { int i; putc('\r', ttyfp); @@ -489,7 +489,7 @@ tty_kill_prompt() putc('\r', ttyfp); fflush(ttyfp); } - #endif +#endif last_prompt_len = 0; } @@ -504,4 +504,3 @@ tty_get_answer_is_yes( const char *prompt ) m_free(p); return yes; } -