Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
asctime_r.c File Reference
#include <assert.h>
#include <langinfo.h>
#include <stdio.h>
#include <time.h>
Include dependency graph for asctime_r.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

char * asctime_r (const struct tm *restrict tm, char *restrict buf)
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 1 of file asctime_r.c.

Function Documentation

◆ asctime_r()

char* asctime_r ( const struct tm *restrict  tm,
char *restrict  buf 
)

Definition at line 7 of file asctime_r.c.

8 {
9  if(snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", nl_langinfo(ABDAY_1 + tm->tm_wday),
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 }
int tm_hour
Definition: time.h:45
int tm_sec
Definition: time.h:43
int tm_mday
Definition: time.h:46
char * nl_langinfo(nl_item item)
Definition: langinfo.c:64
#define assert(x)
Definition: assert.h:11
#define ABDAY_1
Definition: langinfo.h:27
int tm_mon
Definition: time.h:47
int tm_year
Definition: time.h:48
int tm_wday
Definition: time.h:49
Definition: time.h:41
#define ABMON_1
Definition: langinfo.h:43
int tm_min
Definition: time.h:44

References ABDAY_1, ABMON_1, assert, nl_langinfo(), tm::tm_hour, tm::tm_mday, tm::tm_min, tm::tm_mon, tm::tm_sec, tm::tm_wday, and tm::tm_year.

Referenced by asctime().