changeset 69:21e778b6c3e9 noffle

[svn] Rewrote getTimesInSeconds(): arguments ar now int and checked with assertions. Return value is time_t and must be checked for (time_t)-1.
author enz
date Sat, 13 May 2000 10:25:28 +0100
parents f76e8586fab6
children 38c86048fe2e
files src/server.c
diffstat 1 files changed, 35 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/server.c	Sat May 13 09:28:09 2000 +0100
+++ b/src/server.c	Sat May 13 10:25:28 2000 +0100
@@ -1,7 +1,7 @@
 /*
   server.c
 
-  $Id: server.c 70 2000-05-12 17:35:00Z enz $
+  $Id: server.c 75 2000-05-13 09:25:28Z enz $
 */
 
 #if HAVE_CONFIG_H
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include "server.h"
 #include <ctype.h>
+#include <errno.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <sys/types.h>
@@ -787,12 +788,24 @@
     return TRUE;
 }
 
-static unsigned long
-getTimeInSeconds( unsigned int year, unsigned int mon, unsigned int day,
-                  unsigned int hour, unsigned int min, unsigned int sec )
+/* Can return -1, if date is outside the range of time_t. */
+static time_t
+getTimeInSeconds( int year, int mon, int day, int hour, int min, int sec )
 {
     struct tm t;
+    time_t result;
 
+    ASSERT( year >= 1900 );
+    ASSERT( mon >= 1 );
+    ASSERT( mon <= 12 );
+    ASSERT( day >= 1 );
+    ASSERT( day <= 31 );
+    ASSERT( hour >= 0 );
+    ASSERT( hour <= 23 );
+    ASSERT( min >= 0 );
+    ASSERT( min <= 59 );
+    ASSERT( sec >= 0 );
+    ASSERT( sec <= 59 );
     memset( &t, 0, sizeof( t ) );
     t.tm_year = year - 1900;
     t.tm_mon = mon - 1;
@@ -800,15 +813,16 @@
     t.tm_hour = hour;
     t.tm_min = min;
     t.tm_sec = sec;
-    return mktime( &t );
+    result = mktime( &t );
+    return result;
 }
 
 
 static Bool
 doNewgrps( char *arg, const Cmd *cmd )
 {
-    time_t t, now, lastUpdate;
-    unsigned int year, mon, day, hour, min, sec, cent, len;
+    time_t t, now, lastUpdate, nextCentBegin;
+    int year, mon, day, hour, min, sec, cent, len;
     const char *g;
     Str date, timeofday, file;
 
@@ -821,19 +835,24 @@
     switch ( len )
     {
     case 6:
-        if ( sscanf( date, "%2u%2u%2u", &year, &mon, &day ) != 3 )
+        if ( sscanf( date, "%2d%2d%2d", &year, &mon, &day ) != 3 )
         {
             putSyntax( cmd );
             return TRUE;
         }
         now = time( NULL );
         cent = 1900;
-        while ( now > getTimeInSeconds( cent + 100, 1, 1, 0, 0, 0 ) )
+        nextCentBegin = getTimeInSeconds( cent + 100, 1, 1, 0, 0, 0 );
+        while ( nextCentBegin != (time_t)-1 && now != (time_t)-1 
+                && now > nextCentBegin )
+        {
             cent += 100;
+            nextCentBegin = getTimeInSeconds( cent + 100, 1, 1, 0, 0, 0 );
+        }
         year += cent;
         break;
     case 8:
-        if ( sscanf( date, "%4u%2u%2u", &year, &mon, &day ) != 3 )
+        if ( sscanf( date, "%4d%2d%2d", &year, &mon, &day ) != 3 )
         {
             putSyntax( cmd );
             return TRUE;
@@ -843,13 +862,14 @@
         putSyntax( cmd );
         return TRUE;
     }
-    if ( sscanf( timeofday, "%2u%2u%2u", &hour, &min, &sec ) != 3 )
+    if ( sscanf( timeofday, "%2d%2d%2d", &hour, &min, &sec ) != 3 )
     {
         putSyntax( cmd );
         return TRUE;
     }
-    if ( year < 1970 || mon == 0 || mon > 12 || day == 0 || day > 31
-         || hour > 23 || min > 59 || sec > 60 )
+    if ( year < 1970 || mon < 1 || mon > 12 || day < 1 || day > 31
+         || hour < 0 || hour > 23 || min < 0 || min > 59
+         || sec < 0 || sec > 60 )
     {
         putSyntax( cmd );
         return TRUE;
@@ -858,7 +878,8 @@
     t = getTimeInSeconds( year, mon, day, hour, min, sec );
     putStat( STAT_NEW_GRP_FOLLOW, "New groups since %s", arg );
 
-    if ( ! Utl_getStamp( &lastUpdate, file ) || t <= lastUpdate )
+    if ( ! Utl_getStamp( &lastUpdate, file )
+         || t == (time_t)-1 || t <= lastUpdate )
     {
         if ( Grp_firstGrp( &g ) )
             do