-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
714d12a
commit 41709ba
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
#ifndef TIME_MANAGEMENT_H | ||
#define TIME_MANAGEMENT_H | ||
#endif | ||
|
||
/*Copies time struct ts into td*/ | ||
void time_copy(struct timespec *td, struct timespec ts); | ||
|
||
/*Adds ms milliseconds to the time variable pointed by t*/ | ||
void time_add_ms(struct timespec *t, int ms); | ||
|
||
/* Returns 0 if t1 == t2 | ||
* Returns 1 if t1 > t2 | ||
* Returns -1 if t1 < 2 | ||
*/ | ||
int time_cmp(struct timespec t1,struct timespec t2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <time.h> | ||
#include <timemanagement.h> | ||
|
||
/*Copies time struct ts into td*/ | ||
void time_copy(struct timespec *td, struct timespec ts){ | ||
td->tv_sec = ts.tv_sec; | ||
td->tv_nsec = ts.tv_nsec; | ||
} | ||
|
||
/*Adds ms milliseconds to the time variable pointed by t*/ | ||
void time_add_ms(struct timespec *t, int ms){ | ||
t->tv_sec += ms/1000; | ||
t->tv_nsec += (ms%1000)*1000000; | ||
if (t->tv_nsec > 1000000000) { | ||
t->tv_nsec -= 1000000000; | ||
t->tv_sec += 1; | ||
} | ||
} | ||
|
||
/* Returns 0 if t1 == t2 | ||
* Returns 1 if t1 > t2 | ||
* Returns -1 if t1 < 2 | ||
*/ | ||
int time_cmp(struct timespec t1,struct timespec t2){ | ||
if (t1.tv_sec > t2.tv_sec) return 1; | ||
if (t1.tv_sec < t2.tv_sec) return -1; | ||
if (t1.tv_nsec > t2.tv_nsec) return 1; | ||
if (t1.tv_nsec < t2.tv_nsec) return -1; | ||
return 0; | ||
} | ||
|