Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
asctime_r.c
Go to the documentation of this file.
1
#define _GNU_SOURCE
2
#include <
assert.h
>
3
#include <
langinfo.h
>
4
#include <
stdio.h
>
5
#include <
time.h
>
6
7
char
*
asctime_r
(
const
struct
tm
* restrict
tm
,
char
* restrict buf)
8
{
9
if
(snprintf(buf, 26,
"%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
,
nl_langinfo
(
ABDAY_1
+
tm
->
tm_wday
),
10
nl_langinfo
(
ABMON_1
+
tm
->
tm_mon
),
tm
->
tm_mday
,
tm
->
tm_hour
,
tm
->
tm_min
,
tm
->
tm_sec
,
11
1900 +
tm
->
tm_year
) >= 26)
12
{
13
/* ISO C requires us to use the above format string,
14
* even if it will not fit in the buffer. Thus asctime_r
15
* is _supposed_ to crash if the fields in tm are too large.
16
* We follow this behavior and crash "gracefully" to warn
17
* application developers that they may not be so lucky
18
* on other implementations (e.g. stack smashing..).
19
*/
20
assert
(0 &&
"tm fields are too large for buffer"
);
21
}
22
return
buf;
23
}
tm::tm_hour
int tm_hour
Definition:
time.h:45
time.h
tm::tm_sec
int tm_sec
Definition:
time.h:43
tm::tm_mday
int tm_mday
Definition:
time.h:46
nl_langinfo
char * nl_langinfo(nl_item item)
Definition:
langinfo.c:64
assert
#define assert(x)
Definition:
assert.h:11
assert.h
ABDAY_1
#define ABDAY_1
Definition:
langinfo.h:27
langinfo.h
tm::tm_mon
int tm_mon
Definition:
time.h:47
tm::tm_year
int tm_year
Definition:
time.h:48
tm::tm_wday
int tm_wday
Definition:
time.h:49
tm
Definition:
time.h:41
asctime_r
char * asctime_r(const struct tm *restrict tm, char *restrict buf)
Definition:
asctime_r.c:7
stdio.h
ABMON_1
#define ABMON_1
Definition:
langinfo.h:43
tm::tm_min
int tm_min
Definition:
time.h:44
src
time
asctime_r.c
Generated by
1.8.15