[libvirt] [PATCH] util: virTimeFieldsThenRaw never return negative

Martin Kletzander mkletzan at redhat.com
Fri Jul 25 10:07:28 UTC 2014


On Fri, Jul 25, 2014 at 04:13:57PM +0800, James wrote:
>virTimeFieldsThenRaw will never return negative result, so I clean up
>the related meaningless judgements to make it better.
>
>Signed-off-by: James <james.wangyufei at huawei.com>
>---
> src/util/virtime.c  | 23 ++++++++---------------
> src/util/virtime.h  |  8 ++++----
> tests/virtimetest.c |  3 +--
> 3 files changed, 13 insertions(+), 21 deletions(-)
>
>diff --git a/src/util/virtime.c b/src/util/virtime.c
>index 2a91ea5..a49e287 100644
>--- a/src/util/virtime.c
>+++ b/src/util/virtime.c
>@@ -94,7 +94,8 @@ int virTimeFieldsNowRaw(struct tm *fields)
>     if (virTimeMillisNowRaw(&now) < 0)
>         return -1;
>
>-    return virTimeFieldsThenRaw(now, fields);
>+    virTimeFieldsThenRaw(now, fields);
>+    return 0;
> }
>
>
>@@ -121,9 +122,8 @@ const unsigned short int __mon_yday[2][13] = {
>  * 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 virTimeFieldsThenRaw(unsigned long long when, struct tm *fields)

Well, it doesn't need to be "Raw" since there is no other variant.

> {
>     /* This code is taken from GLibC under terms of LGPLv2+ */
>     long int days, rem, y;
>@@ -171,7 +171,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 +208,7 @@ int virTimeStringThenRaw(unsigned long long when, char *buf)
> {
>     struct tm fields;
>
>-    if (virTimeFieldsThenRaw(when, &fields) < 0)
>-        return -1;
>+    virTimeFieldsThenRaw(when, &fields);
>
>     fields.tm_year += 1900;
>     fields.tm_mon += 1;
>@@ -264,7 +262,8 @@ int virTimeFieldsNow(struct tm *fields)
>     if (virTimeMillisNow(&now) < 0)
>         return -1;
>
>-    return virTimeFieldsThen(now, fields);
>+    virTimeFieldsThen(now, fields);
>+    return 0;
> }
>
>
>@@ -276,16 +275,10 @@ int virTimeFieldsNow(struct tm *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)
>+void virTimeFieldsThen(unsigned long long when, struct tm *fields)
> {
>-    if (virTimeFieldsThenRaw(when, fields) < 0) {
>-        virReportSystemError(errno, "%s",
>-                             _("Unable to break out time format"));
>-        return -1;
>-    }
>-    return 0;
>+    virTimeFieldsThenRaw(when, fields);
> }
>
>
>diff --git a/src/util/virtime.h b/src/util/virtime.h
>index 25332db..f9432da 100644
>--- a/src/util/virtime.h
>+++ b/src/util/virtime.h
>@@ -43,8 +43,8 @@ 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;
>+void virTimeFieldsThenRaw(unsigned long long when, struct tm *fields)
>+    ATTRIBUTE_NONNULL(2);

And it doesn't really go with the comment above these (that's not
visible here).

> int virTimeStringNowRaw(char *buf)
>     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
> int virTimeStringThenRaw(unsigned long long when, char *buf)
>@@ -57,8 +57,8 @@ 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;
>+void virTimeFieldsThen(unsigned long long when, struct tm *fields)
>+    ATTRIBUTE_NONNULL(2);

Same for this one.

But these are just a tiny thing, so I fixed them up and pushed (with
the following diff:

diff --git i/src/libvirt_private.syms w/src/libvirt_private.syms
index 51504d1..b1fb7c9 100644
--- i/src/libvirt_private.syms
+++ w/src/libvirt_private.syms
@@ -2032,7 +2032,6 @@ virThreadPoolSendJob;
 virTimeFieldsNow;
 virTimeFieldsNowRaw;
 virTimeFieldsThen;
-virTimeFieldsThenRaw;
 virTimeLocalOffsetFromUTC;
 virTimeMillisNow;
 virTimeMillisNowRaw;
diff --git i/src/util/virtime.c w/src/util/virtime.c
index a49e287..9fefb67 100644
--- i/src/util/virtime.c
+++ w/src/util/virtime.c
@@ -94,7 +94,8 @@ int virTimeFieldsNowRaw(struct tm *fields)
     if (virTimeMillisNowRaw(&now) < 0)
         return -1;

-    virTimeFieldsThenRaw(now, fields);
+    virTimeFieldsThen(now, fields);
+
     return 0;
 }

@@ -115,7 +116,7 @@ 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
  *
@@ -123,7 +124,7 @@ const unsigned short int __mon_yday[2][13] = {
  * Time time is always in UTC
  *
  */
-void 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;
@@ -208,7 +209,7 @@ int virTimeStringThenRaw(unsigned long long when, char *buf)
 {
     struct tm fields;

-    virTimeFieldsThenRaw(when, &fields);
+    virTimeFieldsThen(when, &fields);

     fields.tm_year += 1900;
     fields.tm_mon += 1;
@@ -268,21 +269,6 @@ int virTimeFieldsNow(struct tm *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
- *
- */
-void virTimeFieldsThen(unsigned long long when, struct tm *fields)
-{
-    virTimeFieldsThenRaw(when, fields);
-}
-
-
-/**
  * virTimeStringNow:
  *
  * Creates a string containing a formatted timestamp
diff --git i/src/util/virtime.h w/src/util/virtime.h
index f9432da..8ebad38 100644
--- i/src/util/virtime.h
+++ w/src/util/virtime.h
@@ -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;
-void virTimeFieldsThenRaw(unsigned long long when, struct tm *fields)
-    ATTRIBUTE_NONNULL(2);
 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;
-void virTimeFieldsThen(unsigned long long when, struct tm *fields)
-    ATTRIBUTE_NONNULL(2);
 char *virTimeStringNow(void);
 char *virTimeStringThen(unsigned long long when);

--
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140725/510003de/attachment-0001.sig>


More information about the libvir-list mailing list