Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add copy constructor in utility_time component.

  • Loading branch information...
commit 1d887dc43eec64574eb96daa60f1c5b2ec923b18 1 parent 1633dca
eus authored
Showing with 32 additions and 0 deletions.
  1. +27 −0 utility_time.h
  2. +5 −0 utility_time_test.c
27 utility_time.h
View
@@ -197,6 +197,8 @@ extern "C" {
/* IV */
/**
* @name Collection of conversion functions to internal representation.
+ * The utility_time object to store the result must always be
+ * initalized first.
* @{
*/
/**
@@ -368,6 +370,31 @@ extern "C" {
}
return internal_t;
}
+
+ /**
+ * Assign the internal representation of time from src to dst.
+ */
+ static inline void utility_time_to_utility_time(const utility_time *src,
+ utility_time *dst)
+ {
+ dst->t.tv_sec = src->t.tv_sec;
+ dst->t.tv_nsec = src->t.tv_nsec;
+ }
+ /**
+ * Work just like utility_time_to_utility_time() except that it
+ * returns the result as dynamic utility_time object subject to
+ * automatic garbage collection.
+ */
+ static inline utility_time *utility_time_to_utility_time_dyn(const
+ utility_time *
+ src)
+ {
+ utility_time *internal_t = utility_time_make_dyn();
+ if (internal_t != NULL) {
+ utility_time_to_utility_time(src, internal_t);
+ }
+ return internal_t;
+ }
/** @} End of collection of conversion functions to internal representation */
/* V */
5 utility_time_test.c
View
@@ -216,5 +216,10 @@ int main(int argc, char **argv, char **envp)
internal_t_dyn));
assert(endptr == &str[2]);
+ /* Testcase 28 */
+ to_utility_time(7777, ms, &internal_t);
+ to_timespec_gc(utility_time_to_utility_time_dyn(&internal_t), &t);
+ assert((t.tv_sec == 7) && (t.tv_nsec == 777000000));
+
return EXIT_SUCCESS;
}
Please sign in to comment.
Something went wrong with that request. Please try again.