aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-09 19:10:49 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-09 19:10:49 +0100
commitdc698bb038756a926aaa529bda1b939eab2c1676 (patch)
tree4084a40897d9d81816228935a1398e80dd4b173b /libbb
parent0681137972dc89b5003b0415e09184c0ecf1c875 (diff)
downloadbusybox-w32-dc698bb038756a926aaa529bda1b939eab2c1676.tar.gz
busybox-w32-dc698bb038756a926aaa529bda1b939eab2c1676.tar.bz2
busybox-w32-dc698bb038756a926aaa529bda1b939eab2c1676.zip
*: make it easier to distinquish "struct tm", pointer to one, etc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/rtc.c12
-rw-r--r--libbb/time.c90
2 files changed, 51 insertions, 51 deletions
diff --git a/libbb/rtc.c b/libbb/rtc.c
index 9807e1cf9..fcd6c64d7 100644
--- a/libbb/rtc.c
+++ b/libbb/rtc.c
@@ -59,14 +59,14 @@ int FAST_FUNC rtc_xopen(const char **default_rtc, int flags)
59 return xopen(*default_rtc, flags); 59 return xopen(*default_rtc, flags);
60} 60}
61 61
62void FAST_FUNC rtc_read_tm(struct tm *tm, int fd) 62void FAST_FUNC rtc_read_tm(struct tm *ptm, int fd)
63{ 63{
64 memset(tm, 0, sizeof(*tm)); 64 memset(ptm, 0, sizeof(*ptm));
65 xioctl(fd, RTC_RD_TIME, tm); 65 xioctl(fd, RTC_RD_TIME, ptm);
66 tm->tm_isdst = -1; /* "not known" */ 66 ptm->tm_isdst = -1; /* "not known" */
67} 67}
68 68
69time_t FAST_FUNC rtc_tm2time(struct tm *tm, int utc) 69time_t FAST_FUNC rtc_tm2time(struct tm *ptm, int utc)
70{ 70{
71 char *oldtz = oldtz; /* for compiler */ 71 char *oldtz = oldtz; /* for compiler */
72 time_t t; 72 time_t t;
@@ -77,7 +77,7 @@ time_t FAST_FUNC rtc_tm2time(struct tm *tm, int utc)
77 tzset(); 77 tzset();
78 } 78 }
79 79
80 t = mktime(tm); 80 t = mktime(ptm);
81 81
82 if (utc) { 82 if (utc) {
83 unsetenv("TZ"); 83 unsetenv("TZ");
diff --git a/libbb/time.c b/libbb/time.c
index 85c72d163..82a0fa1fa 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -8,51 +8,51 @@
8 */ 8 */
9#include "libbb.h" 9#include "libbb.h"
10 10
11void FAST_FUNC parse_datestr(const char *date_str, struct tm *tm_time) 11void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
12{ 12{
13 char end = '\0'; 13 char end = '\0';
14 const char *last_colon = strrchr(date_str, ':'); 14 const char *last_colon = strrchr(date_str, ':');
15 15
16 if (last_colon != NULL) { 16 if (last_colon != NULL) {
17 /* Parse input and assign appropriately to tm_time */ 17 /* Parse input and assign appropriately to ptm */
18 18
19 /* HH:MM */ 19 /* HH:MM */
20 if (sscanf(date_str, "%u:%u%c", 20 if (sscanf(date_str, "%u:%u%c",
21 &tm_time->tm_hour, 21 &ptm->tm_hour,
22 &tm_time->tm_min, 22 &ptm->tm_min,
23 &end) >= 2) { 23 &end) >= 2) {
24 /* no adjustments needed */ 24 /* no adjustments needed */
25 } else 25 } else
26 /* mm.dd-HH:MM */ 26 /* mm.dd-HH:MM */
27 if (sscanf(date_str, "%u.%u-%u:%u%c", 27 if (sscanf(date_str, "%u.%u-%u:%u%c",
28 &tm_time->tm_mon, &tm_time->tm_mday, 28 &ptm->tm_mon, &ptm->tm_mday,
29 &tm_time->tm_hour, &tm_time->tm_min, 29 &ptm->tm_hour, &ptm->tm_min,
30 &end) >= 4) { 30 &end) >= 4) {
31 /* Adjust month from 1-12 to 0-11 */ 31 /* Adjust month from 1-12 to 0-11 */
32 tm_time->tm_mon -= 1; 32 ptm->tm_mon -= 1;
33 } else 33 } else
34 /* yyyy.mm.dd-HH:MM */ 34 /* yyyy.mm.dd-HH:MM */
35 if (sscanf(date_str, "%u.%u.%u-%u:%u%c", &tm_time->tm_year, 35 if (sscanf(date_str, "%u.%u.%u-%u:%u%c", &ptm->tm_year,
36 &tm_time->tm_mon, &tm_time->tm_mday, 36 &ptm->tm_mon, &ptm->tm_mday,
37 &tm_time->tm_hour, &tm_time->tm_min, 37 &ptm->tm_hour, &ptm->tm_min,
38 &end) >= 5) { 38 &end) >= 5) {
39 tm_time->tm_year -= 1900; /* Adjust years */ 39 ptm->tm_year -= 1900; /* Adjust years */
40 tm_time->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ 40 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
41 } else 41 } else
42 /* yyyy-mm-dd HH:MM */ 42 /* yyyy-mm-dd HH:MM */
43 if (sscanf(date_str, "%u-%u-%u %u:%u%c", &tm_time->tm_year, 43 if (sscanf(date_str, "%u-%u-%u %u:%u%c", &ptm->tm_year,
44 &tm_time->tm_mon, &tm_time->tm_mday, 44 &ptm->tm_mon, &ptm->tm_mday,
45 &tm_time->tm_hour, &tm_time->tm_min, 45 &ptm->tm_hour, &ptm->tm_min,
46 &end) >= 5) { 46 &end) >= 5) {
47 tm_time->tm_year -= 1900; /* Adjust years */ 47 ptm->tm_year -= 1900; /* Adjust years */
48 tm_time->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ 48 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
49//TODO: coreutils 6.9 also accepts "yyyy-mm-dd HH" (no minutes) 49//TODO: coreutils 6.9 also accepts "yyyy-mm-dd HH" (no minutes)
50 } else { 50 } else {
51 bb_error_msg_and_die(bb_msg_invalid_date, date_str); 51 bb_error_msg_and_die(bb_msg_invalid_date, date_str);
52 } 52 }
53 if (end == ':') { 53 if (end == ':') {
54 /* xxx:SS */ 54 /* xxx:SS */
55 if (sscanf(last_colon + 1, "%u%c", &tm_time->tm_sec, &end) == 1) 55 if (sscanf(last_colon + 1, "%u%c", &ptm->tm_sec, &end) == 1)
56 end = '\0'; 56 end = '\0';
57 /* else end != NUL and we error out */ 57 /* else end != NUL and we error out */
58 } 58 }
@@ -75,60 +75,60 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *tm_time)
75 75
76 /* MM[.SS] */ 76 /* MM[.SS] */
77 if (len == 2 && sscanf(date_str, "%2u%2u%2u%2u""%2u%c" + 12, 77 if (len == 2 && sscanf(date_str, "%2u%2u%2u%2u""%2u%c" + 12,
78 &tm_time->tm_min, 78 &ptm->tm_min,
79 &end) >= 1) { 79 &end) >= 1) {
80 } else 80 } else
81 /* HHMM[.SS] */ 81 /* HHMM[.SS] */
82 if (len == 4 && sscanf(date_str, "%2u%2u%2u""%2u%2u%c" + 9, 82 if (len == 4 && sscanf(date_str, "%2u%2u%2u""%2u%2u%c" + 9,
83 &tm_time->tm_hour, 83 &ptm->tm_hour,
84 &tm_time->tm_min, 84 &ptm->tm_min,
85 &end) >= 2) { 85 &end) >= 2) {
86 } else 86 } else
87 /* ddHHMM[.SS] */ 87 /* ddHHMM[.SS] */
88 if (len == 6 && sscanf(date_str, "%2u%2u""%2u%2u%2u%c" + 6, 88 if (len == 6 && sscanf(date_str, "%2u%2u""%2u%2u%2u%c" + 6,
89 &tm_time->tm_mday, 89 &ptm->tm_mday,
90 &tm_time->tm_hour, 90 &ptm->tm_hour,
91 &tm_time->tm_min, 91 &ptm->tm_min,
92 &end) >= 3) { 92 &end) >= 3) {
93 } else 93 } else
94 /* mmddHHMM[.SS] */ 94 /* mmddHHMM[.SS] */
95 if (len == 8 && sscanf(date_str, "%2u""%2u%2u%2u%2u%c" + 3, 95 if (len == 8 && sscanf(date_str, "%2u""%2u%2u%2u%2u%c" + 3,
96 &tm_time->tm_mon, 96 &ptm->tm_mon,
97 &tm_time->tm_mday, 97 &ptm->tm_mday,
98 &tm_time->tm_hour, 98 &ptm->tm_hour,
99 &tm_time->tm_min, 99 &ptm->tm_min,
100 &end) >= 4) { 100 &end) >= 4) {
101 /* Adjust month from 1-12 to 0-11 */ 101 /* Adjust month from 1-12 to 0-11 */
102 tm_time->tm_mon -= 1; 102 ptm->tm_mon -= 1;
103 } else 103 } else
104 /* yymmddHHMM[.SS] */ 104 /* yymmddHHMM[.SS] */
105 if (len == 10 && sscanf(date_str, "%2u%2u%2u%2u%2u%c", 105 if (len == 10 && sscanf(date_str, "%2u%2u%2u%2u%2u%c",
106 &tm_time->tm_year, 106 &ptm->tm_year,
107 &tm_time->tm_mon, 107 &ptm->tm_mon,
108 &tm_time->tm_mday, 108 &ptm->tm_mday,
109 &tm_time->tm_hour, 109 &ptm->tm_hour,
110 &tm_time->tm_min, 110 &ptm->tm_min,
111 &end) >= 5) { 111 &end) >= 5) {
112 /* Adjust month from 1-12 to 0-11 */ 112 /* Adjust month from 1-12 to 0-11 */
113 tm_time->tm_mon -= 1; 113 ptm->tm_mon -= 1;
114 } else 114 } else
115 /* ccyymmddHHMM[.SS] */ 115 /* ccyymmddHHMM[.SS] */
116 if (len == 12 && sscanf(date_str, "%4u%2u%2u%2u%2u%c", 116 if (len == 12 && sscanf(date_str, "%4u%2u%2u%2u%2u%c",
117 &tm_time->tm_year, 117 &ptm->tm_year,
118 &tm_time->tm_mon, 118 &ptm->tm_mon,
119 &tm_time->tm_mday, 119 &ptm->tm_mday,
120 &tm_time->tm_hour, 120 &ptm->tm_hour,
121 &tm_time->tm_min, 121 &ptm->tm_min,
122 &end) >= 5) { 122 &end) >= 5) {
123 tm_time->tm_year -= 1900; /* Adjust years */ 123 ptm->tm_year -= 1900; /* Adjust years */
124 tm_time->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */ 124 ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
125 } else { 125 } else {
126 bb_error_msg_and_die(bb_msg_invalid_date, date_str); 126 bb_error_msg_and_die(bb_msg_invalid_date, date_str);
127 } 127 }
128 if (end == '.') { 128 if (end == '.') {
129 /* xxx.SS */ 129 /* xxx.SS */
130 if (sscanf(strchr(date_str, '.') + 1, "%u%c", 130 if (sscanf(strchr(date_str, '.') + 1, "%u%c",
131 &tm_time->tm_sec, &end) == 1) 131 &ptm->tm_sec, &end) == 1)
132 end = '\0'; 132 end = '\0';
133 /* else end != NUL and we error out */ 133 /* else end != NUL and we error out */
134 } 134 }
@@ -138,9 +138,9 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *tm_time)
138 } 138 }
139} 139}
140 140
141time_t FAST_FUNC validate_tm_time(const char *date_str, struct tm *tm_time) 141time_t FAST_FUNC validate_tm_time(const char *date_str, struct tm *ptm)
142{ 142{
143 time_t t = mktime(tm_time); 143 time_t t = mktime(ptm);
144 if (t == (time_t) -1L) { 144 if (t == (time_t) -1L) {
145 bb_error_msg_and_die(bb_msg_invalid_date, date_str); 145 bb_error_msg_and_die(bb_msg_invalid_date, date_str);
146 } 146 }