none.c (18b20312986af58ed39c318788680fabfad739f3) none.c (1949a3470f29c5edaa5fc2770c2886d653fa68d1)
1/*-
2 * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
3 * Copyright (c) 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Paul Borman at Krystal Technologies.
8 *

--- 41 unchanged lines hidden (view full) ---

50#include <string.h>
51#include <wchar.h>
52#include "mblocal.h"
53
54int _none_init(_RuneLocale *);
55size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
56 mbstate_t * __restrict);
57int _none_mbsinit(const mbstate_t *);
1/*-
2 * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
3 * Copyright (c) 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Paul Borman at Krystal Technologies.
8 *

--- 41 unchanged lines hidden (view full) ---

50#include <string.h>
51#include <wchar.h>
52#include "mblocal.h"
53
54int _none_init(_RuneLocale *);
55size_t _none_mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
56 mbstate_t * __restrict);
57int _none_mbsinit(const mbstate_t *);
58size_t _none_mbsrtowcs(wchar_t * __restrict, const char ** __restrict,
59 size_t, mbstate_t * __restrict);
58size_t _none_mbsnrtowcs(wchar_t * __restrict dst,
59 const char ** __restrict src, size_t nms, size_t len,
60 mbstate_t * __restrict ps __unused);
60size_t _none_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
61size_t _none_wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
61size_t _none_wcsrtombs(char * __restrict, const wchar_t ** __restrict,
62 size_t, mbstate_t * __restrict);
62size_t _none_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
63 size_t, size_t, mbstate_t * __restrict);
63
64int
65_none_init(_RuneLocale *rl)
66{
67
68 __mbrtowc = _none_mbrtowc;
69 __mbsinit = _none_mbsinit;
64
65int
66_none_init(_RuneLocale *rl)
67{
68
69 __mbrtowc = _none_mbrtowc;
70 __mbsinit = _none_mbsinit;
70 __mbsrtowcs = _none_mbsrtowcs;
71 __mbsnrtowcs = _none_mbsnrtowcs;
71 __wcrtomb = _none_wcrtomb;
72 __wcrtomb = _none_wcrtomb;
72 __wcsrtombs = _none_wcsrtombs;
73 __wcsnrtombs = _none_wcsnrtombs;
73 _CurrentRuneLocale = rl;
74 __mb_cur_max = 1;
75 return(0);
76}
77
78int
79_none_mbsinit(const mbstate_t *ps __unused)
80{

--- 33 unchanged lines hidden (view full) ---

114 errno = EILSEQ;
115 return ((size_t)-1);
116 }
117 *s = (unsigned char)wc;
118 return (1);
119}
120
121size_t
74 _CurrentRuneLocale = rl;
75 __mb_cur_max = 1;
76 return(0);
77}
78
79int
80_none_mbsinit(const mbstate_t *ps __unused)
81{

--- 33 unchanged lines hidden (view full) ---

115 errno = EILSEQ;
116 return ((size_t)-1);
117 }
118 *s = (unsigned char)wc;
119 return (1);
120}
121
122size_t
122_none_mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
123 size_t len, mbstate_t * __restrict ps __unused)
123_none_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
124 size_t nms, size_t len, mbstate_t * __restrict ps __unused)
124{
125 const char *s;
126 size_t nchr;
127
125{
126 const char *s;
127 size_t nchr;
128
128 if (dst == NULL)
129 return (strlen(*src));
129 if (dst == NULL) {
130 s = memchr(*src, '\0', nms);
131 return (s != NULL ? s - *src : nms);
132 }
130
131 s = *src;
132 nchr = 0;
133
134 s = *src;
135 nchr = 0;
133 while (len-- > 0) {
136 while (len-- > 0 && nms-- > 0) {
134 if ((*dst++ = (unsigned char)*s++) == L'\0') {
135 *src = NULL;
136 return (nchr);
137 }
138 nchr++;
139 }
140 *src = s;
141 return (nchr);
142}
143
144size_t
137 if ((*dst++ = (unsigned char)*s++) == L'\0') {
138 *src = NULL;
139 return (nchr);
140 }
141 nchr++;
142 }
143 *src = s;
144 return (nchr);
145}
146
147size_t
145_none_wcsrtombs(char * __restrict dst, const wchar_t ** __restrict src,
146 size_t len, mbstate_t * __restrict ps __unused)
148_none_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
149 size_t nwc, size_t len, mbstate_t * __restrict ps __unused)
147{
148 const wchar_t *s;
149 size_t nchr;
150
151 if (dst == NULL) {
150{
151 const wchar_t *s;
152 size_t nchr;
153
154 if (dst == NULL) {
152 for (s = *src; *s != L'\0'; s++) {
155 for (s = *src; nwc > 0 && *s != L'\0'; s++, nwc--) {
153 if (*s < 0 || *s > UCHAR_MAX) {
154 errno = EILSEQ;
155 return ((size_t)-1);
156 }
157 }
158 return (s - *src);
159 }
160
161 s = *src;
162 nchr = 0;
156 if (*s < 0 || *s > UCHAR_MAX) {
157 errno = EILSEQ;
158 return ((size_t)-1);
159 }
160 }
161 return (s - *src);
162 }
163
164 s = *src;
165 nchr = 0;
163 while (len-- > 0) {
166 while (len-- > 0 && nwc-- > 0) {
164 if (*s < 0 || *s > UCHAR_MAX) {
165 errno = EILSEQ;
166 return ((size_t)-1);
167 }
168 if ((*dst++ = *s++) == '\0') {
169 *src = NULL;
170 return (nchr);
171 }
172 nchr++;
173 }
174 *src = s;
175 return (nchr);
176}
167 if (*s < 0 || *s > UCHAR_MAX) {
168 errno = EILSEQ;
169 return ((size_t)-1);
170 }
171 if ((*dst++ = *s++) == '\0') {
172 *src = NULL;
173 return (nchr);
174 }
175 nchr++;
176 }
177 *src = s;
178 return (nchr);
179}