Make iso8601_print() return a pointer to its output buffer. This breaks

the ABI.
This commit is contained in:
Laurence Withers 2007-07-23 14:47:49 +00:00
parent d08f81a6cf
commit f82859fa78
2 changed files with 10 additions and 9 deletions

View File

@ -43,12 +43,13 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
\param amt Number of bytes in \a str.
\param date Date to print.
\param details Formatting details (may be 0).
\returns Pointer to buffer (\a str).
Formats and prints an ISO8601 date, optionally using the details in \a details. Will always return
a null-terminated result, even if that means truncating the output to fit the buffer.
*/
void iso8601_print(char* str, int amt, const struct iso8601_date* date,
char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
const struct iso8601_details* details);

View File

@ -16,7 +16,7 @@ static const struct iso8601_details _default_details = {
void iso8601_print(char* str, int amt, const struct iso8601_date* date,
char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
const struct iso8601_details* details)
{
int y, m, d, ret = 0, extended;
@ -38,12 +38,12 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
case iso8601_prec_year:
if(y < 0) snprintf(str, amt, "%05d", y);
else snprintf(str, amt, "%04d", y);
return;
return str;
case iso8601_prec_month:
if(y < 0) snprintf(str, amt, "%05d-%02d", y, m);
else snprintf(str, amt, extended ? "%04d-%02d" : "%04d%02d", y, m);
return;
return str;
case iso8601_prec_day:
if(y < 0) ret = snprintf(str, amt, "%05d-%02d-%02d", y, m, d);
@ -61,7 +61,7 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
extended = y < 0 || y > 9999 || details->extended; // ISO year is different
if(y < 0) snprintf(str, amt, "%05d-W%02d", y, m);
else snprintf(str, amt, extended ? "%04d-W%02d" : "%04dW%02d", y, m);
return;
return str;
case iso8601_prec_wday:
iso8601_to_week(&y, &m, &d, &dttz);
@ -71,7 +71,7 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
break;
}
if(ret < 1 || ret >= amt) return;
if(ret < 1 || ret >= amt) return str;
str += ret;
amt -= ret;
@ -92,7 +92,7 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
switch(details->time_prec) {
case iso8601_prec_none:
return;
return str;
case iso8601_prec_hour:
ret = snprintf(str, amt, "T%02d", y);
@ -122,14 +122,14 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
break;
}
if(ret < 1 || ret >= amt) return;
if(ret < 1 || ret >= amt) return str;
str += ret;
amt -= ret;
if(details->tz_sec) {
if(!--amt) {
*str = 0;
return;
return str;
}
if(details->tz_sec < 0) {
*str++ = '-';