clock-util: make clock_is_localtime() testable and add initial tests
Add path argument to clock_is_localtime() and default to "/etc/adjtime" if it's NULL. This makes the function testable. Add test-clock: initial test cases for some scenarios, using a temporary file. This also checks the behaviour with a NULL (i. e. the system's /etc/adjtime) file.
This commit is contained in:
@@ -69,9 +69,12 @@ int clock_set_hwclock(const struct tm *tm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int clock_is_localtime(void) {
|
||||
int clock_is_localtime(const char* adjtime_path) {
|
||||
_cleanup_fclose_ FILE *f;
|
||||
|
||||
if (adjtime_path == NULL)
|
||||
adjtime_path = "/etc/adjtime";
|
||||
|
||||
/*
|
||||
* The third line of adjtime is "UTC" or "LOCAL" or nothing.
|
||||
* # /etc/adjtime
|
||||
@@ -79,7 +82,7 @@ int clock_is_localtime(void) {
|
||||
* 0
|
||||
* UTC
|
||||
*/
|
||||
f = fopen("/etc/adjtime", "re");
|
||||
f = fopen(adjtime_path, "re");
|
||||
if (f) {
|
||||
char line[LINE_MAX];
|
||||
bool b;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
int clock_is_localtime(void);
|
||||
int clock_is_localtime(const char* adjtime_path);
|
||||
int clock_set_timezone(int *min);
|
||||
int clock_reset_timewarp(void);
|
||||
int clock_get_hwclock(struct tm *tm);
|
||||
|
||||
Reference in New Issue
Block a user