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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/* EINA - EFL data type library
* Copyright (C) 2008 Cedric Bail
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library;
* if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include "eina_config.h"
#include "eina_types.h"
#include "eina_hamster.h"
/*============================================================================*
* Local *
*============================================================================*/
/**
* @cond LOCAL
*/
const char *_eina_hamster_time = __TIME__;
const char *_eina_hamster_date = __DATE__;
static int _eina_hamsters = -1;
/**
* @endcond
*/
/*============================================================================*
* Global *
*============================================================================*/
/*============================================================================*
* API *
*============================================================================*/
EAPI int
eina_hamster_count(void)
{
if (_eina_hamsters < 0)
{
int hrs = 0, min = 0, sec = 0;
char mon[8] = "";
int monnum = 0, day = 0, year = 0;
int fields;
fields = sscanf(_eina_hamster_time, "%02d:%02d:%02d", &hrs, &min, &sec);
if (fields == 3)
{
_eina_hamsters = (hrs * 60) + min;
fields = sscanf(_eina_hamster_date, "%s %d %d", mon, &day, &year);
if (fields == 3)
{
int i;
const char *mons[] =
{
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
for (i = 0; i < 12; i++)
{
if (!strcmp(mon, mons[i]))
{
monnum = i + 1;
break;
}
}
// alloc 60 for mins, 24 for hrs
// alloc 1-31 (32) for days, 1-12 (13) for months
// use year as-is, for 31 bits (signed) this gives us up to
// 3584 years, which is good enough imho. - 1500 years from
// now or so. :)
_eina_hamsters +=
(day + (monnum * 32) + (13 * 32 * year)) * (24 * 60);
}
}
}
// format: [rest - year][0-12 - month][0-31 - day][0-23 - hrs][0-59 - sec]
return _eina_hamsters;
}
/**
* @}
*/
|