File: set-date-epoch.c

package info (click to toggle)
clock-setup 0.123
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 688 kB
  • ctags: 19
  • sloc: sh: 190; makefile: 36; ansic: 28
file content (44 lines) | stat: -rw-r--r-- 855 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright (c) 2009 Frans Pop <fjp@debian.org>
 * Licence: GPL version 2 or later
 */

/*
 * set-date-epoch.c:
 * Set the system date to the epoch if the current date is before the epoch.
 */

#include <sys/time.h>
#include <err.h>
#include <time.h>
#include <stdio.h>

#define EPOCH	70
#define DEBUG	0

int
main(int argc, char **argv)
{
	struct timeval tp;
	struct timezone tzp;
	struct tm *now;

	if (gettimeofday(&tp, &tzp) == -1)
		err(1, "Failed to get time of day");
	now = gmtime(&tp.tv_sec);

#if DEBUG
	printf("The current year is %i.\n", 1900 + now->tm_year);
#endif

	if (now->tm_year < EPOCH) {
		printf("System date is before 1-1-1970; correcting...\n");
		tp.tv_sec = 0;
		tp.tv_usec = 0;
		if (settimeofday(&tp, NULL) == -1)
			err(1, "Could not set time of day");
		printf("System date has been set to 1-1-1970.\n");
	}

	return 0;
}