timeval_func: move all timeval manipulation to separate file

There are several definitions of the same functions manipulating timeval
structures. Let's move them to separate file and arrange the code
preperly.

Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
This commit is contained in:
Vadim Fedorenko
2023-04-26 03:23:41 -07:00
parent 648ad4db6f
commit a197aac2f6
10 changed files with 182 additions and 193 deletions
+1 -14
View File
@@ -65,6 +65,7 @@
#include "sldns/wire2str.h"
#include "sldns/str2wire.h"
#include "daemon/remote.h"
#include "util/timeval_func.h"
#include <signal.h>
struct worker;
struct daemon_remote;
@@ -95,20 +96,6 @@ struct fake_commpoint {
/** Global variable: the scenario. Saved here for when event_init is done. */
static struct replay_scenario* saved_scenario = NULL;
/** add timers and the values do not overflow or become negative */
static void
timeval_add(struct timeval* d, const struct timeval* add)
{
#ifndef S_SPLINT_S
d->tv_sec += add->tv_sec;
d->tv_usec += add->tv_usec;
if(d->tv_usec >= 1000000) {
d->tv_usec -= 1000000;
d->tv_sec++;
}
#endif
}
void
fake_temp_file(const char* adj, const char* id, char* buf, size_t len)
{
+1 -16
View File
@@ -51,6 +51,7 @@
#include "testcode/testpkts.h"
#include "testcode/fake_event.h"
#include "sldns/str2wire.h"
#include "util/timeval_func.h"
/** max length of lines in file */
#define MAX_LINE_LEN 10240
@@ -66,22 +67,6 @@
static char* macro_expand(rbtree_type* store,
struct replay_runtime* runtime, char** text);
/** compare of time values */
static int
timeval_smaller(const struct timeval* x, const struct timeval* y)
{
#ifndef S_SPLINT_S
if(x->tv_sec < y->tv_sec)
return 1;
else if(x->tv_sec == y->tv_sec) {
if(x->tv_usec <= y->tv_usec)
return 1;
else return 0;
}
else return 0;
#endif
}
/** parse keyword in string.
* @param line: if found, the line is advanced to after the keyword.
* @param keyword: string.