Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/uchar/c32rtomb.c
2 views
1
/* c32rtomb( char *, char32_t, mbstate_t * )
2
3
This file is part of the Public Domain C Library (PDCLib).
4
Permission is granted to use, modify, and / or redistribute at will.
5
*/
6
7
#ifndef REGTEST
8
#include <uchar.h>
9
#include <errno.h>
10
#include <stdint.h>
11
#include <assert.h>
12
#include <stdlib.h>
13
#include "_PDCLIB_encoding.h"
14
#include "_PDCLIB_locale.h"
15
16
size_t c32rtomb_l(
17
char *restrict s,
18
char32_t c32,
19
mbstate_t *restrict ps,
20
locale_t restrict l
21
)
22
{
23
char buf[s ? 0 : MB_CUR_MAX];
24
s = s ? s : buf;
25
26
const char32_t *restrict psrc = &c32;
27
size_t srcsz = 1;
28
size_t dstsz = MB_CUR_MAX;
29
size_t dstrem = dstsz;
30
31
if(l->_Codec->__c32stombs(&s, &dstrem, &psrc, &srcsz, ps)) {
32
// Successful conversion
33
return dstsz - dstrem;
34
} else {
35
errno = EILSEQ;
36
return (size_t) -1;
37
}
38
}
39
40
size_t c32rtomb(
41
char *restrict s,
42
char32_t c32,
43
mbstate_t *restrict ps
44
)
45
{
46
return c32rtomb_l(s, c32, ps, _PDCLIB_threadlocale());
47
}
48
49
#endif
50
51
#ifdef TEST
52
#include "_PDCLIB_test.h"
53
54
int main( void )
55
{
56
TESTCASE( NO_TESTDRIVER );
57
return TEST_RESULTS;
58
}
59
#endif
60
61