MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / gmtime_r

Function gmtime_r

components/libc/compilers/common/ctime.c:155–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

153#endif /* RT_LIBC_USING_LIGHT_TZ_DST */
154
155struct tm *gmtime_r(const time_t *timep, struct tm *r)
156{
157 int i;
158 int work;
159
160 if(timep == RT_NULL || r == RT_NULL)
161 {
162 rt_set_errno(EFAULT);
163 return RT_NULL;
164 }
165
166 rt_memset(r, RT_NULL, sizeof(struct tm));
167
168 work = *timep % (24*60*60);
169 r->tm_sec = work % 60;
170 work /= 60;
171 r->tm_min = work % 60;
172 r->tm_hour = work / 60;
173 work = (int)(*timep / (24*60*60));
174 r->tm_wday = (4 + work) % 7;
175 for (i = 1970;; ++i)
176 {
177 int k = __isleap(i) ? 366 : 365;
178 if (work >= k)
179 work -= k;
180 else
181 break;
182 }
183 r->tm_year = i - 1900;
184 r->tm_yday = work;
185
186 r->tm_mday = 1;
187 if (__isleap(i) && (work > 58))
188 {
189 if (work == 59)
190 r->tm_mday = 2; /* 29.2. */
191 work -= 1;
192 }
193
194 for (i = 11; i && (__spm[i] > work); --i);
195
196 r->tm_mon = i;
197 r->tm_mday += work - __spm[i];
198#if defined(RT_LIBC_USING_LIGHT_TZ_DST)
199 r->tm_isdst = rt_tz_is_dst();
200#else
201 r->tm_isdst = 0U;
202#endif /* RT_LIBC_USING_LIGHT_TZ_DST */
203 return r;
204}
205RTM_EXPORT(gmtime_r);
206
207struct tm* gmtime(const time_t* t)

Callers 8

gmtimeFunction · 0.70
localtime_rFunction · 0.70
alarm_updateFunction · 0.50
alarm_setupFunction · 0.50
rt_alarm_startFunction · 0.50
syslog_formaterFunction · 0.50
get_fattimeFunction · 0.50
get_fattimeFunction · 0.50

Calls 4

rt_set_errnoFunction · 0.85
rt_memsetFunction · 0.85
__isleapFunction · 0.85
rt_tz_is_dstFunction · 0.85

Tested by

no test coverage detected