source: UsbWattMeter/trunk/lwip-1.4.1/ports/grsakura/wolfssl_asp_dcre.c@ 167

Last change on this file since 167 was 167, checked in by coas-nagasima, 8 years ago

MIMEにSJISを設定

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc; charset=SHIFT_JIS
File size: 5.1 KB
Line 
1#include "stddef.h"
2#include <wolfssl/wolfcrypt/error-crypt.h>
3#include <wolfssl/wolfcrypt/wc_port.h>
4#include <wolfssl/wolfcrypt/random.h>
5#include "lwip/sockets.h"
6#include "kernel.h"
7#include "itron.h"
8#ifdef __RX
9#include "sys/time.h"
10#endif
11#include "time.h"
12
13#ifdef __RX
14_Ctype_t _Touptab;
15
16char *getenv(const char *name)
17{
18 syslog(LOG_NOTICE, name);
19 return "";
20}
21#else
22struct tm *gmtime_r(const time_t *pt, struct tm* tm);
23#endif
24
25/* NTPサーバーのグローバル時間 */
26static time_t sys_time_offset = 1453334400LL;
27
28time_t sys_time(time_t *t)
29{
30 if (t == NULL) {
31 time_t temp;
32 return time(&temp);
33 }
34
35 SYSTIM tim;
36 get_tim(&tim);
37 *t = (time_t)(tim / 1000) + sys_time_offset;
38 return *t;
39}
40
41void sys_set_system_time(time_t t)
42{
43 SYSTIM tim;
44 get_tim(&tim);
45 sys_time_offset = t - (time_t)(tim / 1000);
46
47 struct tm tm;
48 gmtime_r(&t, &tm);
49 syslog(LOG_NOTICE, "%d/%d/%d %d:%d:%d", 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
50 tm.tm_hour, tm.tm_min, tm.tm_sec);
51}
52
53/* musl-1.1.12/src/time/__secs_to_tm.c */
54/* musl as a whole is licensed under the following standard MIT license:
55 *
56 * ----------------------------------------------------------------------
57 * Copyright (C) 2005-2014 Rich Felker, et al.
58 *
59 * Permission is hereby granted, free of charge, to any person obtaining
60 * a copy of this software and associated documentation files (the
61 * "Software"), to deal in the Software without restriction, including
62 * without limitation the rights to use, copy, modify, merge, publish,
63 * distribute, sublicense, and/or sell copies of the Software, and to
64 * permit persons to whom the Software is furnished to do so, subject to
65 * the following conditions:
66 *
67 * The above copyright notice and this permission notice shall be
68 * included in all copies or substantial portions of the Software.
69 *
70 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
71 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
73 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
74 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
75 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
76 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
77 * ----------------------------------------------------------------------*/
78
79/* 2000-03-01 (mod 400 year, immediately after feb29 */
80#define LEAPOCH (946684800LL + 86400*(31+29))
81
82#define DAYS_PER_400Y (365*400 + 97)
83#define DAYS_PER_100Y (365*100 + 24)
84#define DAYS_PER_4Y (365*4 + 1)
85
86struct tm *gmtime_r(const time_t *pt, struct tm* tm)
87{
88 time_t t = *pt;
89 time_t days, secs, years;
90 int remdays, remsecs, remyears;
91 int qc_cycles, c_cycles, q_cycles;
92 int months;
93 int wday, yday, leap;
94 static const char days_in_month[] = {31,30,31,30,31,31,30,31,30,31,31,29};
95
96 /* Reject time_t values whose year would overflow int */
97 if (t < INT_MIN * 31622400LL || t > INT_MAX * 31622400LL)
98 return NULL;
99
100 secs = t - LEAPOCH;
101 days = secs / 86400;
102 remsecs = secs % 86400;
103 if (remsecs < 0) {
104 remsecs += 86400;
105 days--;
106 }
107
108 wday = (3 + days) % 7;
109 if (wday < 0) wday += 7;
110
111 qc_cycles = days / DAYS_PER_400Y;
112 remdays = days % DAYS_PER_400Y;
113 if (remdays < 0) {
114 remdays += DAYS_PER_400Y;
115 qc_cycles--;
116 }
117
118 c_cycles = remdays / DAYS_PER_100Y;
119 if (c_cycles == 4) c_cycles--;
120 remdays -= c_cycles * DAYS_PER_100Y;
121
122 q_cycles = remdays / DAYS_PER_4Y;
123 if (q_cycles == 25) q_cycles--;
124 remdays -= q_cycles * DAYS_PER_4Y;
125
126 remyears = remdays / 365;
127 if (remyears == 4) remyears--;
128 remdays -= remyears * 365;
129
130 leap = !remyears && (q_cycles || !c_cycles);
131 yday = remdays + 31 + 28 + leap;
132 if (yday >= 365 + leap) yday -= 365 + leap;
133
134 years = remyears + 4 * q_cycles + 100 * c_cycles + 400LL * qc_cycles;
135
136 for (months = 0; days_in_month[months] <= remdays; months++)
137 remdays -= days_in_month[months];
138
139 if (years + 100 > INT_MAX || years + 100 < INT_MIN)
140 return NULL;
141
142 tm->tm_year = years + 100;
143 tm->tm_mon = months + 2;
144 if (tm->tm_mon >= 12) {
145 tm->tm_mon -= 12;
146 tm->tm_year++;
147 }
148 tm->tm_mday = remdays + 1;
149 tm->tm_wday = wday;
150 tm->tm_yday = yday;
151
152 tm->tm_hour = remsecs / 3600;
153 tm->tm_min = remsecs / 60 % 60;
154 tm->tm_sec = remsecs % 60;
155
156 return tm;
157}
158
159struct tm *sys_gmtime(const time_t *pt)
160{
161 static struct tm tm;
162 return gmtime_r(pt, &tm);
163}
164
165DWORD get_fattime(void)
166{
167 time_t temp;
168 struct tm _tm;
169
170 time(&temp);
171 gmtime_r(&temp, &_tm);
172
173 return ((DWORD)(_tm.tm_year - 1980) << 25)
174 | ((DWORD)_tm.tm_mon << 21)
175 | ((DWORD)_tm.tm_mday << 16)
176 | ((DWORD)_tm.tm_hour << 11)
177 | ((DWORD)_tm.tm_min << 5)
178 | ((DWORD)_tm.tm_sec >> 1);
179}
180
181FIL *sys_stderr = (FIL *)1;
182FIL *sys_stdout = (FIL *)2;
183FIL *sys_stdin = (FIL *)3;
184
185long sys_fprintf(FIL *fp, const char *str, ...)
186{
187 long res = 0;
188 va_list ap;
189
190 if (fp == sys_stdin)
191 return res;
192
193 va_start(ap, str);
194
195 if (fp == sys_stderr) {
196 vsyslog(LOG_ERROR, str, ap);
197 }
198 else if (fp == sys_stdout) {
199 vsyslog(LOG_NOTICE, str, ap);
200 }
201 else {
202 res = f_vprintf(fp, str, ap);
203 }
204
205 va_end(ap);
206
207 return res;
208}
209
210int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
211{
212 word32 i;
213 for (i = 0; i < sz; i++)
214 output[i] = rand();
215
216 (void)os;
217
218 return 0;
219}
Note: See TracBrowser for help on using the repository browser.