Commit f9cb0a92 by Marcus Winter

base_c: fixed checks and documentation in time, duration and log

parent b9ca6dc9
...@@ -249,6 +249,8 @@ int embb_duration_as_seconds( ...@@ -249,6 +249,8 @@ int embb_duration_as_seconds(
/** /**
* Compares two durations. * Compares two durations.
* *
* \pre \c lhs and \c rhs are not NULL and properly initialized.
*
* \return -1 if \c lhs < \c rhs \n * \return -1 if \c lhs < \c rhs \n
* 0 if \c lhs == \c rhs \n * 0 if \c lhs == \c rhs \n
* 1 if \c lhs > \c rhs * 1 if \c lhs > \c rhs
......
...@@ -67,6 +67,7 @@ typedef void(*embb_log_function_t)(void * context, char const * message); ...@@ -67,6 +67,7 @@ typedef void(*embb_log_function_t)(void * context, char const * message);
/** /**
* Default logging function. * Default logging function.
* Writes to the given file (context needs to be a FILE*). * Writes to the given file (context needs to be a FILE*).
* \pre \c context is not NULL.
* \ingroup C_LOG * \ingroup C_LOG
* \threadsafe * \threadsafe
*/ */
......
...@@ -89,6 +89,8 @@ int embb_time_in( ...@@ -89,6 +89,8 @@ int embb_time_in(
/** /**
* Compares two time points. * Compares two time points.
* *
* \pre \c lhs and \c rhs are not NULL and properly initialized.
*
* \return -1 if \c lhs < \c rhs \n * \return -1 if \c lhs < \c rhs \n
* 0 if \c lhs == \c rhs \n * 0 if \c lhs == \c rhs \n
* 1 if \c lhs > \c rhs * 1 if \c lhs > \c rhs
......
...@@ -183,7 +183,6 @@ int embb_duration_as_seconds(const embb_duration_t* duration, ...@@ -183,7 +183,6 @@ int embb_duration_as_seconds(const embb_duration_t* duration,
if (duration->nanoseconds % 1000000000 > 0) { if (duration->nanoseconds % 1000000000 > 0) {
return EMBB_UNDERFLOW; return EMBB_UNDERFLOW;
} }
assert(duration->nanoseconds % 1000000000 == 0);
if (duration->seconds > ULLONG_MAX) { if (duration->seconds > ULLONG_MAX) {
return EMBB_OVERFLOW; return EMBB_OVERFLOW;
} }
...@@ -193,12 +192,8 @@ int embb_duration_as_seconds(const embb_duration_t* duration, ...@@ -193,12 +192,8 @@ int embb_duration_as_seconds(const embb_duration_t* duration,
int embb_duration_compare(const embb_duration_t* lhs, int embb_duration_compare(const embb_duration_t* lhs,
const embb_duration_t* rhs) { const embb_duration_t* rhs) {
if (lhs == NULL || rhs == NULL) { assert(lhs != NULL && rhs != NULL);
return EMBB_ERROR; assert(lhs->nanoseconds < 1000000000 && rhs->nanoseconds < 1000000000);
}
if (lhs->nanoseconds >= 1000000000 || rhs->nanoseconds >= 1000000000) {
return EMBB_ERROR;
}
if (lhs->seconds > rhs->seconds) { if (lhs->seconds > rhs->seconds) {
return 1; return 1;
} else if (lhs->seconds < rhs->seconds) { } else if (lhs->seconds < rhs->seconds) {
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <embb/base/c/log.h> #include <embb/base/c/log.h>
...@@ -35,6 +36,7 @@ ...@@ -35,6 +36,7 @@
void embb_log_write_file( void embb_log_write_file(
void * context, void * context,
char const * message) { char const * message) {
assert(context != NULL);
FILE * ff = (FILE*)context; FILE * ff = (FILE*)context;
fprintf(ff, "%s", message); fprintf(ff, "%s", message);
fflush(ff); fflush(ff);
......
...@@ -33,13 +33,8 @@ void embb_time_now(embb_time_t* time) { ...@@ -33,13 +33,8 @@ void embb_time_now(embb_time_t* time) {
} }
int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) { int embb_time_compare(const embb_time_t* lhs, const embb_time_t* rhs) {
if (lhs == NULL || rhs == NULL) { assert(lhs != NULL && rhs != NULL);
return EMBB_ERROR; assert(lhs->nanoseconds < 1000000000 && rhs->nanoseconds < 1000000000);
}
if (lhs->nanoseconds >= 1000000000 || rhs->nanoseconds >= 1000000000) {
return EMBB_ERROR;
}
if (lhs->seconds > rhs->seconds) { if (lhs->seconds > rhs->seconds) {
return 1; return 1;
} else if (lhs->seconds < rhs->seconds) { } else if (lhs->seconds < rhs->seconds) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment