util: virTimeFieldsThenRaw never returns negative

virTimeFieldsThenRaw will never return negative result, so I clean up
the related meaningless judgements to make it better.

Signed-off-by: James <james.wangyufei@huawei.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
James 2014-07-25 16:13:57 +08:00 committed by Martin Kletzander
parent ccdf708245
commit febfe83721
4 changed files with 11 additions and 35 deletions

View File

@ -2032,7 +2032,6 @@ virThreadPoolSendJob;
virTimeFieldsNow;
virTimeFieldsNowRaw;
virTimeFieldsThen;
virTimeFieldsThenRaw;
virTimeLocalOffsetFromUTC;
virTimeMillisNow;
virTimeMillisNowRaw;

View File

@ -94,7 +94,9 @@ int virTimeFieldsNowRaw(struct tm *fields)
if (virTimeMillisNowRaw(&now) < 0)
return -1;
return virTimeFieldsThenRaw(now, fields);
virTimeFieldsThen(now, fields);
return 0;
}
@ -114,16 +116,15 @@ const unsigned short int __mon_yday[2][13] = {
((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
/**
* virTimeFieldsThenRaw:
* virTimeFieldsThen:
* @when: the time to convert in milliseconds
* @fields: filled with time @when fields
*
* Converts the timestamp @when into broken-down field format.
* Time time is always in UTC
*
* Returns 0 on success, -1 on error with errno set
*/
int virTimeFieldsThenRaw(unsigned long long when, struct tm *fields)
void virTimeFieldsThen(unsigned long long when, struct tm *fields)
{
/* This code is taken from GLibC under terms of LGPLv2+ */
long int days, rem, y;
@ -171,7 +172,6 @@ int virTimeFieldsThenRaw(unsigned long long when, struct tm *fields)
days -= ip[y];
fields->tm_mon = y;
fields->tm_mday = days + 1;
return 0;
}
@ -209,8 +209,7 @@ int virTimeStringThenRaw(unsigned long long when, char *buf)
{
struct tm fields;
if (virTimeFieldsThenRaw(when, &fields) < 0)
return -1;
virTimeFieldsThen(when, &fields);
fields.tm_year += 1900;
fields.tm_mon += 1;
@ -264,27 +263,7 @@ int virTimeFieldsNow(struct tm *fields)
if (virTimeMillisNow(&now) < 0)
return -1;
return virTimeFieldsThen(now, fields);
}
/**
* virTimeFieldsThen:
* @when: the time to convert in milliseconds
* @fields: filled with time @when fields
*
* Converts the timestamp @when into broken-down field format.
* Time time is always in UTC
*
* Returns 0 on success, -1 on error with error reported
*/
int virTimeFieldsThen(unsigned long long when, struct tm *fields)
{
if (virTimeFieldsThenRaw(when, fields) < 0) {
virReportSystemError(errno, "%s",
_("Unable to break out time format"));
return -1;
}
virTimeFieldsThen(now, fields);
return 0;
}

View File

@ -37,14 +37,15 @@
(4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 3 + 5 + 1)
/* Yr Mon Day Hour Min Sec Ms TZ NULL */
void virTimeFieldsThen(unsigned long long when, struct tm *fields)
ATTRIBUTE_NONNULL(2);
/* These APIs are async signal safe and return -1, setting
* errno on failure */
int virTimeMillisNowRaw(unsigned long long *now)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virTimeFieldsNowRaw(struct tm *fields)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virTimeFieldsThenRaw(unsigned long long when, struct tm *fields)
ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int virTimeStringNowRaw(char *buf)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virTimeStringThenRaw(unsigned long long when, char *buf)
@ -57,8 +58,6 @@ int virTimeMillisNow(unsigned long long *now)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virTimeFieldsNow(struct tm *fields)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virTimeFieldsThen(unsigned long long when, struct tm *fields)
ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
char *virTimeStringNow(void);
char *virTimeStringThen(unsigned long long when);

View File

@ -44,8 +44,7 @@ static int testTimeFields(const void *args)
const struct testTimeFieldsData *data = args;
struct tm actual;
if (virTimeFieldsThen(data->when, &actual) < 0)
return -1;
virTimeFieldsThen(data->when, &actual);
#define COMPARE(field) \
do { \