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

Go to the source code of this file.

Functions

char * nl_langinfo (nl_item item)
 

Variables

static const char c_time []
 
static const char c_messages []
 
static const char c_numeric []
 

Function Documentation

◆ nl_langinfo()

char* nl_langinfo ( nl_item  item)

The nl_langinfo function can be used to access individual elements of the locale categories. Unlike the localeconv function, which returns all the information, nl_langinfo lets the caller select what information it requires. This is very fast and it is not a problem to call this function multiple times.

A second advantage is that in addition to the numeric and monetary formatting information, information from the LC_TIME and LC_MESSAGES categories is available.

The type item is defined in nl_types.h. The argument item is a numeric value defined in this header.

Definition at line 64 of file langinfo.c.

65 {
66  int cat = item >> 16;
67  int idx = item & 65535;
68  const char* str;
69 
70  if(item == CODESET)
71  {
72  assert(0 /*"Codeset langinfo not implemented"*/);
73  // return loc->cat[LC_CTYPE] ? "UTF-8" : "ASCII";
74  }
75 
76  /* _NL_LOCALE_NAME extension */
77  if(idx == 65535 && cat < LC_ALL)
78  {
79  assert(0 /*"LOCALE_NAME langinfo not implemented"*/);
80  // return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C";
81  }
82 
83  switch(cat)
84  {
85  case LC_NUMERIC:
86  if(idx > 1)
87  {
88  return (char*)(uintptr_t) "";
89  }
90  str = c_numeric;
91  break;
92  case LC_TIME:
93  if(idx > 0x31)
94  {
95  return (char*)(uintptr_t) "";
96  }
97  str = c_time;
98  break;
99  case LC_MONETARY:
100  if(idx > 0)
101  {
102  return (char*)(uintptr_t) "";
103  }
104  str = "";
105  break;
106  case LC_MESSAGES:
107  if(idx > 3)
108  {
109  return (char*)(uintptr_t) "";
110  }
111  str = c_messages;
112  break;
113  default:
114  return (char*)(uintptr_t) "";
115  }
116 
117  for(; idx; idx--, str++)
118  {
119  for(; *str; str++)
120  {
121  }
122  }
123 
124 #if 0
125  if (cat != LC_NUMERIC && *str)
126  {
127  str = LCTRANS(str, cat, loc);
128  }
129 #endif
130 
131  return (char*)(uintptr_t)str;
132 }
static const char c_time[]
Definition: langinfo.c:6
#define assert(x)
Definition: assert.h:11
static const char c_numeric[]
Definition: langinfo.c:61
#define CODESET
Definition: langinfo.h:83
static const char c_messages[]
Definition: langinfo.c:57
#define LC_MONETARY
Definition: locale.h:14
#define LC_ALL
Definition: locale.h:16
#define LC_TIME
Definition: locale.h:12
#define LC_NUMERIC
Definition: locale.h:11
#define LC_MESSAGES
Definition: locale.h:15

References assert, c_messages, c_numeric, c_time, CODESET, LC_ALL, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and LC_TIME.

Referenced by asctime_r().

Here is the caller graph for this function:

Variable Documentation

◆ c_messages

const char c_messages[]
static
Initial value:
= "^[yY]\0"
"^[nN]\0"
"yes\0"
"no"

Definition at line 57 of file langinfo.c.

Referenced by nl_langinfo().

◆ c_numeric

const char c_numeric[]
static
Initial value:
= ".\0"
""

Definition at line 61 of file langinfo.c.

Referenced by nl_langinfo().

◆ c_time

const char c_time[]
static

Definition at line 6 of file langinfo.c.

Referenced by nl_langinfo().