X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=date.c;h=44f5a99acd8bb509b8058c20c0b482d93ab61c2b;hp=102d688afc86e1d8791a191ce5b5eed558194f5c;hb=8ff934803cb2a0ca4f862aa5e0dd6f8908b78ffa;hpb=c777524834a805476d0dce81b42342dca4702893 diff --git a/date.c b/date.c index 102d688a..44f5a99a 100644 --- a/date.c +++ b/date.c @@ -27,6 +27,8 @@ #include +#include /* For g_ascii_strncasecmp only. */ + #ifndef FALSE #define FALSE 0 #endif @@ -77,7 +79,7 @@ static unsigned char gmime_datetok_table[256] = { /* hrm, is there a library for this stuff? */ static struct { - char *name; + const char *name; int offset; } tz_offsets [] = { { "UT", 0 }, @@ -97,12 +99,12 @@ static struct { { "Y", 1200 }, }; -static char *tm_months[] = { +static const char *tm_months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -static char *tm_days[] = { +static const char *tm_days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; @@ -115,8 +117,8 @@ typedef struct _date_token { size_t len; } date_token; -#define date_token_free(tok) g_slice_free (date_token, tok) -#define date_token_new() g_slice_new (date_token) +#define date_token_free(tok) free (tok) +#define date_token_new() malloc (sizeof (date_token)) static date_token * datetok (const char *date) @@ -363,6 +365,8 @@ get_tzone (date_token **token) return -1; } +#define HAVE_TIMEZONE + static time_t mktime_utc (struct tm *tm) { @@ -636,30 +640,20 @@ gmime_datetok_table_init (void) } #endif - -/** - * g_mime_utils_header_decode_date: - * @str: input date string - * @tz_offset: timezone offset - * - * Decodes the rfc822 date string and saves the GMT offset into - * @tz_offset if non-NULL. - * - * Returns: the time_t representation of the date string specified by - * @str or (time_t) %0 on error. If @tz_offset is non-NULL, the value - * of the timezone offset will be stored. - **/ time_t -g_mime_utils_header_decode_date (const char *str, int *tz_offset) +notmuch_parse_date (const char *str, int *tz_offset) { date_token *token, *tokens; time_t date; - + + if (str == NULL) + return 0; + if (!(tokens = datetok (str))) { if (tz_offset) *tz_offset = 0; - return (time_t) 0; + return 0; } if (!(date = parse_rfc822_date (tokens, tz_offset)))