{"thread":{"id":"1867","subject":"Return proper error valud from \"parse_date()\"","startedAt":"2005-09-19T22:53:50Z","lastAt":"2005-09-19T22:53:50Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"8913","messageId":"Pine.LNX.4.58.0509191548180.2553@g5.osdl.org","threadId":"1867","inReplyTo":null,"subject":"Return proper error valud from \"parse_date()\"","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-09-19T22:53:50Z","receivedAt":"2005-09-19T22:53:50Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nRight now we don't return any error value at all from parse_date(), and if \nwe can't parse it, we just silently leave the result buffer unchanged. \n\nThat's fine for the current user, which will always default to the current \ndate, but it's a crappy interface, and we might well be better off with an \nerror message rather than just the default date.\n\nSo let's change the thing to return a negative value if an error occurs, \nand the length of the result otherwise (snprintf behaviour: if the buffer \nis too small, it returns how big it _would_ have been).\n\n[ I started looking at this in case we could support date-based revision \n  names. Looks ugly. Would have to parse relative dates.. ]\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\ndiff --git a/cache.h b/cache.h\n--- a/cache.h\n+++ b/cache.h\n@@ -241,7 +241,7 @@ extern void *read_object_with_reference(\n \t\t\t\t\tunsigned char *sha1_ret);\n \n const char *show_date(unsigned long time, int timezone);\n-void parse_date(const char *date, char *buf, int bufsize);\n+int parse_date(const char *date, char *buf, int bufsize);\n void datestamp(char *buf, int bufsize);\n \n extern int setup_ident(void);\ndiff --git a/date.c b/date.c\n--- a/date.c\n+++ b/date.c\n@@ -388,7 +388,7 @@ static int match_tz(const char *date, in\n \n /* Gr. strptime is crap for this; it doesn't have a way to require RFC2822\n    (i.e. English) day/month names, and it doesn't work correctly with %z. */\n-void parse_date(const char *date, char *result, int maxlen)\n+int parse_date(const char *date, char *result, int maxlen)\n {\n \tstruct tm tm;\n \tint offset, sign, tm_gmt;\n@@ -431,7 +431,7 @@ void parse_date(const char *date, char *\n \t\toffset = (then - mktime(&tm)) / 60;\n \n \tif (then == -1)\n-\t\treturn;\n+\t\treturn -1;\n \n \tif (!tm_gmt)\n \t\tthen -= offset * 60;\n@@ -442,7 +442,7 @@ void parse_date(const char *date, char *\n \t\tsign = '-';\n \t}\n \n-\tsnprintf(result, maxlen, \"%lu %c%02d%02d\", then, sign, offset/60, offset % 60);\n+\treturn snprintf(result, maxlen, \"%lu %c%02d%02d\", then, sign, offset/60, offset % 60);\n }\n \n void datestamp(char *buf, int bufsize)\n"}]}