From: Pekka Riikonen Date: Sat, 21 Oct 2006 13:46:24 +0000 (+0000) Subject: Used the remaining 2 bits from SilcTime structure. X-Git-Tag: silc.client.1.1.beta1~245 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=f08f800950dc9ddcd842e79f7f132c8d9f7dc055;p=silc.git Used the remaining 2 bits from SilcTime structure. --- diff --git a/lib/silcutil/silctime.c b/lib/silcutil/silctime.c index 13575e57..da49445a 100644 --- a/lib/silcutil/silctime.c +++ b/lib/silcutil/silctime.c @@ -19,6 +19,39 @@ #include "silc.h" +/* Fills the SilcTime structure with correct values */ + +static SilcBool silc_time_fill(SilcTime time, + unsigned int year, + unsigned int month, + unsigned int day, + unsigned int hour, + unsigned int minute, + unsigned int second) +{ + if (year > (1 << 15)) + return FALSE; + if (month < 1 || month > 12) + return FALSE; + if (day < 1 || day > 31) + return FALSE; + if (hour > 23) + return FALSE; + if (minute > 60) + return FALSE; + if (second > 61) + return FALSE; + + time->year = year; + time->month = month; + time->day = day; + time->hour = hour; + time->minute = minute; + time->second = second; + + return TRUE; +} + /* Return time since Epoch */ SilcInt64 silc_time(void) @@ -62,14 +95,12 @@ SilcBool silc_time_value(SilcInt64 timeval, SilcTime ret_time) return FALSE; memset(ret_time, 0, sizeof(*ret_time)); - ret_time->year = time->tm_year + 1900; - ret_time->month = time->tm_mon + 1; - ret_time->day = time->tm_mday; - ret_time->hour = time->tm_hour; - ret_time->minute = time->tm_min; - ret_time->second = time->tm_sec; - ret_time->dst = time->tm_isdst ? 1 : 0; + if (!silc_time_fill(ret_time, time->tm_year + 1900, time->tm_mon + 1, + time->tm_mday, time->tm_hour, time->tm_min, + time->tm_sec)) + return FALSE; + ret_time->dst = time->tm_isdst ? 1 : 0; #ifdef SILC_WIN32 ret_time->utc_east = _timezone < 0 ? 1 : 0; ret_time->utc_hour = (ret_time->utc_east ? (-(_timezone)) / 3600 : @@ -89,39 +120,6 @@ SilcBool silc_time_value(SilcInt64 timeval, SilcTime ret_time) return TRUE; } -/* Fills the SilcTime structure with correct values */ - -static SilcBool silc_time_fill(SilcTime time, - unsigned int year, - unsigned int month, - unsigned int day, - unsigned int hour, - unsigned int minute, - unsigned int second) -{ - if (year > 8191) - return FALSE; - if (month < 1 || month > 12) - return FALSE; - if (day < 1 || day > 31) - return FALSE; - if (hour > 23) - return FALSE; - if (minute > 60) - return FALSE; - if (second > 61) - return FALSE; - - time->year = year; - time->month = month; - time->day = day; - time->hour = hour; - time->minute = minute; - time->second = second; - - return TRUE; -} - /* Returns time from universal time string into SilcTime */ SilcBool silc_time_universal(const char *universal_time, SilcTime ret_time) diff --git a/lib/silcutil/silctime.h b/lib/silcutil/silctime.h index 47890ee5..c5cfc8be 100644 --- a/lib/silcutil/silctime.h +++ b/lib/silcutil/silctime.h @@ -45,7 +45,7 @@ * ***/ typedef struct { - unsigned int year : 13; /* Year, 0 - 8191 */ + unsigned int year : 15; /* Year, 0 - 32768 */ unsigned int month : 4; /* Month, 1 - 12 */ unsigned int day : 5; /* Day, 1 - 31 */ unsigned int hour : 5; /* Hour, 0 - 23 */ @@ -56,7 +56,6 @@ typedef struct { unsigned int utc_minute : 6; /* Offset to Zulu (UTC) minutes */ unsigned int utc_east : 1; /* Offset, 1 east (+), 0 west (-) */ unsigned int dst : 1; /* Set if daylight saving time */ - /* 2 bits to spare */ } *SilcTime, SilcTimeStruct; /***/ @@ -110,7 +109,7 @@ SilcBool silc_time_value(SilcInt64 timeval, SilcTime ret_time); * SYNOPSIS * * SilcBool silc_time_universal(const char *universal_time, - * SilcTime ret_time); + * SilcTime ret_time); * * DESCRIPTION *