PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_localeconv_r.c File Reference
#include "c.h"
#include <langinfo.h>
#include <pthread.h>
#include <limits.h>
Include dependency graph for pg_localeconv_r.c:

Go to the source code of this file.

Data Structures

struct  lconv_member_info
 

Macros

#define LCONV_M(is_string, category, name, item)    { is_string, category, offsetof(struct lconv, name) }
 
#define LCONV_S(c, n, i)   LCONV_M(true, c, n, i)
 
#define LCONV_C(c, n, i)   LCONV_M(false, c, n, i)
 

Functions

static char ** lconv_string_member (struct lconv *lconv, int i)
 
static charlconv_char_member (struct lconv *lconv, int i)
 
void pg_localeconv_free (struct lconv *lconv)
 
static int pg_localeconv_copy_members (struct lconv *dst, struct lconv *src, int category)
 
int pg_localeconv_r (const char *lc_monetary, const char *lc_numeric, struct lconv *output)
 

Variables

static const struct lconv_member_info table []
 

Macro Definition Documentation

◆ LCONV_C

#define LCONV_C (   c,
  n,
  i 
)    LCONV_M(false, c, n, i)

Definition at line 52 of file pg_localeconv_r.c.

◆ LCONV_M

#define LCONV_M (   is_string,
  category,
  name,
  item 
)     { is_string, category, offsetof(struct lconv, name) }

Definition at line 48 of file pg_localeconv_r.c.

49 { is_string, category, offsetof(struct lconv, name) }
static int fb(int x)
const char * name

◆ LCONV_S

#define LCONV_S (   c,
  n,
  i 
)    LCONV_M(true, c, n, i)

Definition at line 51 of file pg_localeconv_r.c.

Function Documentation

◆ lconv_char_member()

static char * lconv_char_member ( struct lconv lconv,
int  i 
)
inlinestatic

Definition at line 94 of file pg_localeconv_r.c.

95{
96 return (char *) lconv + table[i].offset;
97}
int i
Definition isn.c:77
static const struct lconv_member_info table[]

References fb(), i, lconv_member_info::offset, and table.

Referenced by pg_localeconv_copy_members().

◆ lconv_string_member()

static char ** lconv_string_member ( struct lconv lconv,
int  i 
)
inlinestatic

Definition at line 88 of file pg_localeconv_r.c.

89{
90 return (char **) ((char *) lconv + table[i].offset);
91}

References fb(), i, lconv_member_info::offset, and table.

Referenced by pg_localeconv_copy_members(), and pg_localeconv_free().

◆ pg_localeconv_copy_members()

static int pg_localeconv_copy_members ( struct lconv dst,
struct lconv src,
int  category 
)
static

Definition at line 155 of file pg_localeconv_r.c.

158{
159 for (int i = 0; i < lengthof(table); ++i)
160 {
161 if (table[i].category != category)
162 continue;
163
164 if (table[i].is_string)
165 {
166 char *string;
167
168 string = *lconv_string_member(src, i);
169 if (!(string = strdup(string)))
170 {
172 errno = ENOMEM;
173 return -1;
174 }
176 }
177 else
178 {
180 }
181 }
182
183 return 0;
184}
#define lengthof(array)
Definition c.h:803
static char * lconv_char_member(struct lconv *lconv, int i)
static char ** lconv_string_member(struct lconv *lconv, int i)
void pg_localeconv_free(struct lconv *lconv)
char string[11]

References lconv_member_info::category, fb(), i, lconv_member_info::is_string, lconv_char_member(), lconv_string_member(), lengthof, pg_localeconv_free(), and table.

Referenced by pg_localeconv_r().

◆ pg_localeconv_free()

void pg_localeconv_free ( struct lconv lconv)

Definition at line 104 of file pg_localeconv_r.c.

105{
106 for (int i = 0; i < lengthof(table); ++i)
107 if (table[i].is_string)
109}
#define free(a)

References fb(), free, i, lconv_member_info::is_string, lconv_string_member(), lengthof, and table.

Referenced by pg_localeconv_copy_members(), and PGLC_localeconv().

◆ pg_localeconv_r()

int pg_localeconv_r ( const char lc_monetary,
const char lc_numeric,
struct lconv output 
)

Definition at line 231 of file pg_localeconv_r.c.

234{
235#ifdef WIN32
236 wchar_t *save_lc_ctype = NULL;
237 wchar_t *save_lc_monetary = NULL;
238 wchar_t *save_lc_numeric = NULL;
240 int result = -1;
241
242 /* Put setlocale() into thread-local mode. */
244
245 /*
246 * Capture the current values as wide strings. Otherwise, we might not be
247 * able to restore them if their names contain non-ASCII characters and
248 * the intermediate locale changes the expected encoding. We don't want
249 * to leave the caller in an unexpected state by failing to restore, or
250 * crash the runtime library.
251 */
254 goto exit;
257 goto exit;
260 goto exit;
261
262 memset(output, 0, sizeof(*output));
263
264 /* Copy the LC_MONETARY members. */
266 goto exit;
268 if (result != 0)
269 goto exit;
270
271 /* Copy the LC_NUMERIC members. */
273 goto exit;
275
276exit:
277 /* Restore everything we changed. */
278 if (save_lc_ctype)
279 {
282 }
284 {
287 }
288 if (save_lc_numeric)
289 {
292 }
294
295 return result;
296
297#else /* !WIN32 */
300 int result;
301
302 /*
303 * All variations on Unix require locale_t objects for LC_MONETARY and
304 * LC_NUMERIC. We'll set all locale categories, so that we can don't have
305 * to worry about POSIX's undefined behavior if LC_CTYPE's encoding
306 * doesn't match.
307 */
308 errno = ENOENT;
310 if (monetary_locale == 0)
311 return -1;
313 if (numeric_locale == 0)
314 {
316 return -1;
317 }
318
319 memset(output, 0, sizeof(*output));
320#if defined(TRANSLATE_FROM_LANGINFO)
321 /* Copy from non-standard nl_langinfo_l() extended items. */
325#elif defined(HAVE_LOCALECONV_L)
326 /* Copy the LC_MONETARY members from a thread-safe lconv object. */
330 if (result == 0)
331 {
332 /* Copy the LC_NUMERIC members from a thread-safe lconv object. */
335 LC_NUMERIC);
336 }
337#else
338 /* We have nothing better than standard POSIX facilities. */
339 {
342
344 /* Copy the LC_MONETARY members. */
347 localeconv(),
349 if (result == 0)
350 {
351 /* Copy the LC_NUMERIC members. */
354 localeconv(),
355 LC_NUMERIC);
356 }
358
360 }
361#endif
362
365
366 return result;
367#endif /* !WIN32 */
368}
FILE * output
static char * lc_numeric
Definition initdb.c:144
static char * lc_monetary
Definition initdb.c:143
static int pg_localeconv_copy_members(struct lconv *dst, struct lconv *src, int category)
int pthread_mutex_unlock(pthread_mutex_t *mp)
int pthread_mutex_lock(pthread_mutex_t *mp)
#define PTHREAD_MUTEX_INITIALIZER
#define locale_t
Definition win32_port.h:429
#define setlocale(a, b)
Definition win32_port.h:472

References fb(), free, lc_monetary, lc_numeric, locale_t, output, pg_localeconv_copy_members(), PTHREAD_MUTEX_INITIALIZER, pthread_mutex_lock(), pthread_mutex_unlock(), and setlocale.

Referenced by PGLC_localeconv().

Variable Documentation

◆ table

const struct lconv_member_info table[]
static
Initial value:

Definition at line 63 of file pg_localeconv_r.c.

Referenced by afterTriggerDeleteHeadEventChunk(), AfterTriggerFreeQuery(), appendQualifiedRelation(), before_stmt_triggers_fired(), byword(), cancel_prior_stmt_triggers(), check_selective_binary_conversion(), cluster_one_database(), convert_int_from_base_unit(), convert_real_from_base_unit(), convert_to_base_unit(), create_foreign_modify(), deparseRelation(), fileGetOptions(), get_batch_size_option(), get_table_relkind(), GetAfterTriggersStoreSlot(), GetAfterTriggersTableData(), initCreateTables(), initialize_worker_spi(), initPopulateTable(), lconv_char_member(), lconv_string_member(), mbbisearch(), pg_localeconv_copy_members(), pg_localeconv_free(), postgresAcquireSampleRowsFunc(), postgresAnalyzeForeignTable(), postgresBeginDirectModify(), postgresBeginForeignScan(), postgresExecForeignTruncate(), postgresGetAnalyzeInfoForForeignTable(), postgresIsForeignRelUpdatable(), prepare_vacuum_command(), run_vacuum_command(), splitTableColumnsSpec(), TransitionTableAddTuple(), vacuumlo(), and worker_spi_main().