changeset 271:3477050e8d10 noffle

[svn] * src/client.c,src/fetch.c,src/lock.c.src/protocol.c,src/util.h,src/util.c: Define our own SignalHandler type rather than use the rather Linux-specific (and potentially glibc version specific) sig_t. * src/client.c,src/database.h,src/database.c,src/over.h,src/over.c, src/pseudo.c,src/server.c: Ensure format string specifiers and passed data types match. As part of this, change some uses of size_t as a general data type to an appropriate base C type. Database status changes from int to unsigned.
author bears
date Sun, 10 Nov 2002 11:32:17 +0000
parents d6fedc09b052
children f3b44be9e4ab
files src/client.c src/database.c src/database.h src/fetch.c src/lock.c src/over.c src/over.h src/protocol.c src/pseudo.c src/server.c src/util.c src/util.h
diffstat 12 files changed, 67 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/src/client.c	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/client.c	Sun Nov 10 11:32:17 2002 +0000
@@ -1,7 +1,7 @@
 /*
   client.c
 
-  $Id: client.c 400 2002-10-08 13:52:52Z bears $
+  $Id: client.c 403 2002-11-10 11:32:17Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -226,11 +226,11 @@
 connectWithTimeout( int sock, const struct sockaddr *servAddr,
                     socklen_t addrLen )
 {
-    sig_t oldHandler;
+    SignalHandler oldHandler;
     int r, to;
 
     oldHandler = Utl_installSignalHandler( SIGALRM, connectAlarm );
-    if ( oldHandler == SIG_ERR )
+    if ( oldHandler == (SignalHandler) SIG_ERR )
     {
         Log_err( "client.c:connectWithTimeout: signal failed." );
         return FALSE;
@@ -293,14 +293,14 @@
     {
         *pColon = '\0';
         strcpy( host, pStart );
-        if ( sscanf( pColon + 1, "%hi", &port ) != 1 )
+        if ( sscanf( pColon + 1, "%hu", &port ) != 1 )
         {
             Log_err( "Syntax error in server name: '%s'", serv );
             return FALSE;;
         }
         if ( port <= 0 || port > 65535 )
         {
-            Log_err( "Invalid port number %hi. Must be in [1, 65535]", port );
+            Log_err( "Invalid port number %hu. Must be in [1, 65535]", port );
             return FALSE;;
         }
     }
@@ -701,7 +701,7 @@
 static const char *
 readField( Str result, const char *p )
 {
-    size_t len;
+    int len;
     char *r;
 
     if ( ! p )
@@ -731,7 +731,8 @@
 
 static Bool
 parseOvLn( Str line, int *numb, Str subj, Str from,
-           Str date, Str msgId, Str ref, size_t *bytes, size_t *lines )
+           Str date, Str msgId, Str ref,
+	   unsigned long *bytes, unsigned long *lines )
 {
     const char *p;
     Str t;
@@ -747,10 +748,10 @@
     p = readField( t, p );
     *bytes = 0;
     *lines = 0;
-    if ( sscanf( t, "%d", bytes ) != 1 )
+    if ( sscanf( t, "%lu", bytes ) != 1 )
         return TRUE;
     p = readField( t, p );
-    if ( sscanf( t, "%d", lines ) != 1 )
+    if ( sscanf( t, "%lu", lines ) != 1 )
         return TRUE;
     return TRUE;
 }
@@ -789,7 +790,7 @@
 {
     Bool interesting, result;
     const char *msgId;
-    int status;
+    unsigned status;
     time_t lastAccess, nowTime;
     double threadFollowTime, maxTime, timeSinceLastAccess;
     ItemList *itl;
@@ -888,7 +889,7 @@
 int
 Client_getOver( const char *grp, int rmtFirst, int rmtLast, FetchMode mode )
 {
-    size_t nbytes, nlines;
+    unsigned long nbytes, nlines;
     int rmtNumb, groupsNumb, oldLast, cntMarked;
     Over *ov;
     Str line, subj, from, date, msgId, ref, groups;
@@ -1024,7 +1025,7 @@
 static void
 retrievingFailed( const char* msgId, const char *reason )
 {
-    int status;
+    unsigned status;
 
     ASSERT( ! Lock_gotLock() );
     Log_err( "Retrieving of %s failed: %s", msgId, reason );
--- a/src/database.c	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/database.c	Sun Nov 10 11:32:17 2002 +0000
@@ -1,7 +1,7 @@
 /*
   database.c
 
-  $Id: database.c 389 2002-06-26 13:28:35Z bears $
+  $Id: database.c 403 2002-11-10 11:32:17Z bears $
 
   Uses GNU gdbm library. Using Berkeley db (included in libc6) was
   cumbersome. It is based on Berkeley db 1.85, which has severe bugs
@@ -44,7 +44,7 @@
     Str msgId;
 
     /* Status of loaded article */
-    int status; /* Flags */
+    unsigned status; /* Flags */
     time_t lastAccess;
 
     /* Overview of loaded article */
@@ -317,7 +317,7 @@
 }
 
 void
-Db_setStatus( const char *msgId, int status )
+Db_setStatus( const char *msgId, unsigned status )
 {
     if ( loadArt( msgId ) )
     {
@@ -418,7 +418,7 @@
     static DynStr *s = NULL;
 
     Str date, t;
-    int status;
+    unsigned status;
     const char *p;
 
     if ( s == NULL )
@@ -473,7 +473,7 @@
     return ( p + 2 );
 }
 
-int
+unsigned
 Db_status( const char *msgId )
 {
     if ( ! loadArt( msgId ) )
--- a/src/database.h	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/database.h	Sun Nov 10 11:32:17 2002 +0000
@@ -3,7 +3,7 @@
 
   Article database.
 
-  $Id: database.h 387 2002-06-26 13:15:44Z bears $
+  $Id: database.h 403 2002-11-10 11:32:17Z bears $
 */
 
 #ifndef DB_H
@@ -29,9 +29,9 @@
 #include "over.h"
 
 /* Article status flags: */
-#define DB_INTERESTING       0x01  /* Was article ever tried to read? */
-#define DB_NOT_DOWNLOADED    0x02  /* Not fully downloaded */
-#define DB_RETRIEVING_FAILED 0x04  /* Retrieving of article failed */
+#define DB_INTERESTING       0x01u  /* Was article ever tried to read? */
+#define DB_NOT_DOWNLOADED    0x02u  /* Not fully downloaded */
+#define DB_RETRIEVING_FAILED 0x04u  /* Retrieving of article failed */
 
 /* Open database for r/w. Locking must be done by the caller! */
 Bool
@@ -52,7 +52,7 @@
 Db_storeArt( const char *msgId, const char *artTxt );
 
 void
-Db_setStatus( const char *msgId, int status );
+Db_setStatus( const char *msgId, unsigned status );
 
 void
 Db_updateLastAccess( const char *msgId );
@@ -67,7 +67,7 @@
 const char *
 Db_body( const char *msgId );
 
-int
+unsigned
 Db_status( const char *msgId );
 
 /* Get last modification time of entry. Returns -1, if msgId non-existing. */
--- a/src/fetch.c	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/fetch.c	Sun Nov 10 11:32:17 2002 +0000
@@ -1,7 +1,7 @@
 /*
   fetch.c
 
-  $Id: fetch.c 381 2002-05-14 14:25:45Z mirkol $
+  $Id: fetch.c 403 2002-11-10 11:32:17Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -302,7 +302,7 @@
     int ret;
     Str cmd;
     FILE *f;
-    sig_t lastHandler;
+    SignalHandler lastHandler;
 
     Log_err( "Return article to '%s' by mail", sender );
     snprintf( cmd, MAXCHAR, "%s -t -oi", SENDMAILPROG);
--- a/src/lock.c	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/lock.c	Sun Nov 10 11:32:17 2002 +0000
@@ -1,7 +1,7 @@
 /*
   lock.c
 
-  $Id: lock.c 316 2001-10-31 11:44:53Z bears $
+  $Id: lock.c 403 2002-11-10 11:32:17Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -52,7 +52,7 @@
 static struct Lock globalLock = { "global", -1, "", TRUE, FALSE, FALSE };
 static struct Lock fetchLock = { "fetch", -1, "", FALSE, FALSE, FALSE };
 
-static sig_t oldHandler = NULL;
+static SignalHandler oldHandler = NULL;
 
 /* Block/unblock SIGUSR1. */
 static Bool
@@ -116,7 +116,7 @@
     l.l_len = 0;
     if ( wait == LOCK_WAIT )
     {
-	sig_t oldAlarmHandler;
+	SignalHandler oldAlarmHandler;
 	unsigned oldAlarm;
 
 	oldAlarmHandler = Utl_installSignalHandler( SIGALRM, lockWaitAlarm );
--- a/src/over.c	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/over.c	Sun Nov 10 11:32:17 2002 +0000
@@ -1,7 +1,7 @@
 /*
   over.c
 
-  $Id: over.c 367 2002-02-14 17:14:06Z bears $
+  $Id: over.c 403 2002-11-10 11:32:17Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -65,7 +65,7 @@
 Over *
 new_Over( const char *subj, const char *from,
           const char *date, const char *msgId, const char *ref,
-          size_t bytes, size_t lines )
+          unsigned long bytes, unsigned long lines )
 {
     Over *ov;
 
@@ -139,13 +139,13 @@
     return self->ref;
 }
 
-size_t
+unsigned long
 Ov_bytes( const Over *self )
 {
     return self->bytes;
 }
 
-size_t
+unsigned long
 Ov_lines( const Over *self )
 {
     return self->lines;
@@ -175,7 +175,7 @@
 static const char *
 readField( Str result, const char *p )
 {
-    size_t len;
+    int len;
     char *r;
 
     if ( ! p )
@@ -204,7 +204,7 @@
 Over *
 Ov_read( char *line )
 {
-    size_t bytes, lines;
+    unsigned long bytes, lines;
     const char *p;
     Over *result;
     int numb;
@@ -219,10 +219,10 @@
     p = readField( msgId, p );
     p = readField( ref, p );
     p = readField( t, p );
-    if ( sscanf( t, "%d", &bytes ) != 1 )
+    if ( sscanf( t, "%lu", &bytes ) != 1 )
         return NULL;
     p = readField( t, p );
-    if ( sscanf( t, "%d", &lines ) != 1 )
+    if ( sscanf( t, "%lu", &lines ) != 1 )
         return NULL;
     result = new_Over( subj, from, date, msgId, ref, bytes, lines );
     Ov_setNumb( result, numb );
--- a/src/over.h	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/over.h	Sun Nov 10 11:32:17 2002 +0000
@@ -5,7 +5,7 @@
   content.c. An article overview contains important article properties,
   such as date, from, subject.
 
-  $Id: over.h 79 2000-05-13 15:35:17Z bears $ 
+  $Id: over.h 403 2002-11-10 11:32:17Z bears $ 
 */
 
 #ifndef OVER_H
@@ -37,7 +37,8 @@
 */
 Over *
 new_Over( const char *subj, const char *from, const char *date,
-          const char *msgId, const char *ref, size_t bytes, size_t lines );
+          const char *msgId, const char *ref,
+	  unsigned long bytes, unsigned long lines );
 
 
 /* free memory */
@@ -72,10 +73,10 @@
 const char *
 Ov_ref( const Over *self );
 
-size_t
+unsigned long
 Ov_bytes( const Over *self );
 
-size_t
+unsigned long
 Ov_lines( const Over *self );
 
 void
--- a/src/protocol.c	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/protocol.c	Sun Nov 10 11:32:17 2002 +0000
@@ -1,7 +1,7 @@
 /*
   protocol.c
 
-  $Id: protocol.c 383 2002-06-26 13:13:26Z bears $
+  $Id: protocol.c 403 2002-11-10 11:32:17Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -36,7 +36,7 @@
 {
     size_t len;
     char *ret;
-    sig_t oldHandler = NULL;
+    SignalHandler oldHandler = NULL;
     int line_too_long;
 
     if ( timeoutSeconds >= 0 )
--- a/src/pseudo.c	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/pseudo.c	Sun Nov 10 11:32:17 2002 +0000
@@ -1,7 +1,7 @@
 /*
   pseudo.c
   
-  $Id: pseudo.c 371 2002-02-26 17:13:31Z bears $
+  $Id: pseudo.c 403 2002-11-10 11:32:17Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -83,8 +83,8 @@
                   "Subject: %s\n"
                   "From: %s\n"
                   "Date: %s\n"
-                  "Bytes: %u\n"
-                  "Lines: %u\n",
+                  "Bytes: %lu\n"
+                  "Lines: %lu\n",
                   Ov_msgId( ov ),
                   Ov_subj( ov ),
                   Ov_from( ov ),
--- a/src/server.c	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/server.c	Sun Nov 10 11:32:17 2002 +0000
@@ -1,7 +1,7 @@
 /*
   server.c
 
-  $Id: server.c 401 2002-10-25 11:04:57Z bears $
+  $Id: server.c 403 2002-11-10 11:32:17Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -505,7 +505,7 @@
 static void
 touchArticle( const char *msgId )
 {
-    int status = Db_status( msgId );
+    unsigned status = Db_status( msgId );
     status |= DB_INTERESTING;
     Db_setStatus( msgId, status );
     Db_updateLastAccess( msgId );
@@ -543,12 +543,12 @@
 updateArt( const char *msgId )
 /* retrieve Article if in online mode */
 {
-    int stat;
+    unsigned status;
 
     touchArticle( msgId );
     touchReferences( msgId );
-    stat = Db_status( msgId );
-    if ( Online_true() && ( stat & DB_NOT_DOWNLOADED ) )
+    status = Db_status( msgId );
+    if ( Online_true() && ( status & DB_NOT_DOWNLOADED ) )
     {
         retrieveArt( msgId );
     }
@@ -557,16 +557,16 @@
 static void
 doBodyInDb( const char *msgId )
 {
-    int stat;
+    unsigned status;
     Str srv;
 
-    stat = Db_status( msgId );
-    if ( stat & DB_RETRIEVING_FAILED )
+    status = Db_status( msgId );
+    if ( status & DB_RETRIEVING_FAILED )
     {
-        Db_setStatus( msgId, stat & ~DB_RETRIEVING_FAILED );
+        Db_setStatus( msgId, status & ~DB_RETRIEVING_FAILED );
         putTxtBuf( Db_body( msgId ) );
     }
-    else if ( stat & DB_NOT_DOWNLOADED )
+    else if ( status & DB_NOT_DOWNLOADED )
     {
         findServer( msgId, srv );
         if ( Req_contains( srv, msgId ) )
@@ -1195,10 +1195,10 @@
 	Utl_cpyStr( res, Ov_ref( ov ) );
 	break;
     case BYTES:
-	snprintf( res, MAXCHAR, "%d", Ov_bytes( ov ) );
+	snprintf( res, MAXCHAR, "%ld", Ov_bytes( ov ) );
 	break;
     case LINES:
-	snprintf( res, MAXCHAR, "%d", Ov_lines( ov ) );
+	snprintf( res, MAXCHAR, "%ld", Ov_lines( ov ) );
 	break;
     case XREF:
 	msgId = Ov_msgId( ov );
--- a/src/util.c	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/util.c	Sun Nov 10 11:32:17 2002 +0000
@@ -1,7 +1,7 @@
 /*
   util.c
 
-  $Id: util.c 391 2002-06-26 13:30:26Z bears $
+  $Id: util.c 403 2002-11-10 11:32:17Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -516,8 +516,8 @@
     memcpy( *dst, src, (size_t)len + 1 );
 }
 
-sig_t
-Utl_installSignalHandler( int sig, sig_t handler )
+SignalHandler
+Utl_installSignalHandler( int sig, SignalHandler handler )
 {
     struct sigaction act, oldAct;
 
--- a/src/util.h	Sun Nov 10 11:30:40 2002 +0000
+++ b/src/util.h	Sun Nov 10 11:32:17 2002 +0000
@@ -3,7 +3,7 @@
 
   Miscellaneous helper functions.
 
-  $Id: util.h 391 2002-06-26 13:30:26Z bears $
+  $Id: util.h 403 2002-11-10 11:32:17Z bears $
 */
 
 #ifndef UTL_H
@@ -28,6 +28,8 @@
 
 #include "common.h"
 
+typedef void (*SignalHandler)( int );
+
 /*
   Find first non-whitespace character after <token> tokens in string <line>.
   Return pointer to end of string, if parsing failed.
@@ -107,8 +109,8 @@
 Utl_allocAndCpy( char **dst, const char *src );
 
 /* Install signal handler. */
-sig_t
-Utl_installSignalHandler( int sig, sig_t handler );
+SignalHandler
+Utl_installSignalHandler( int sig, SignalHandler handler );
 
 /* Obtain this system FQDN. */
 Bool