4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1996, by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * ISO/IEC 9899: 1990/Add.3: 1993 (E): Wide character header file
32 * Copyright 1992, 1993 by Mortice Kern Systems Inc. All rights reserved.
34 * $Header: /rd/h/rcs/m_wchar.h 1.51 1995/09/20 19:17:54 ant Exp $
38 #ifndef __M_M_WCHAR_H__
39 #define __M_M_WCHAR_H__ 1
43 * configuration file for multi-byte vs. single byte enablement
48 #include <limits.h> /* Fetch MB_LEN_MAX */
50 #ifdef M_I18N_LOCKING_SHIFT
51 extern char *m_strsanitize (char *);
53 #define m_strsanitize(str) (str)
54 #endif /* M_I18N_LOCKING_SHIFT */
59 # error M_I18N_MB defined; but the local system does not support multibyte
60 # endif /* MB_LEN_MAX */
62 #define MB_BEGIN if (MB_CUR_MAX > 1) {
63 #define MB_ELSE } else {
66 #define M_MB_L(s) L##s
70 /* a typedef to allow single byte distinction between char and uchar
73 typedef wchar_t wuchar_t
;
76 extern wint_t m_escapewc(wchar_t **);
77 extern int m_fputmbs(FILE* fp
, char *mbs
, int wid
, int prec
, int ljust
);
78 extern int m_fgetws (wchar_t *, size_t, FILE *);
79 extern FILE *m_fwopen (wchar_t *, char *);
80 extern wchar_t *m_wcsdup (const wchar_t *);
81 extern wchar_t *m_mbstowcsdup (const char *s
);
82 extern char *m_wcstombsdup (const wchar_t *w
);
83 extern char *m_mbschr (const char *, int);
84 extern char *m_mbsrchr (const char *, int);
85 extern char *m_mbspbrk (const char *, const char *);
86 extern wchar_t *m_wcsset (wchar_t *, wchar_t, size_t);
87 extern int iswabsname (wchar_t *);
89 #define m_smalls(s) (s)
90 #define wctomb_init() wctomb(NULL,0)
92 #else /* !M_I18N_MB */
94 /* include <stdlib.h> here,
95 * We must include the multibyte function prototypes (in <stdlib.h>) before
96 * redefining the prototype function names below.
98 * AND including <stdlib.h> DOES NOT cause a problem with wchar_t.
100 * ANSI says that the typedef of wchar_t should be defined in stdlib.h.
101 * Thus, the prototypes in stdlib.h are declared using stdlib's definition
105 #include <stdlib.h> /* DO NOT MOVE THIS include - THIS must be first */
119 #define m_escapewc m_escapec
120 #define m_fgetws m_fgets
121 #define m_fwopen fopen
122 #define m_wcsdup strdup
123 #define m_mbstowcsdup strdup
124 #define m_wcstombsdup strdup
125 #define m_mbschr strchr
126 #define m_mbsrchr strrchr
127 #define m_mbspbrk strpbrk
128 #define m_wcsset memset
129 #define iswabsname(s) isabsname(s)
131 #define m_fputmbs(fp, str, wid, prec, ljust) \
132 fprintf((fp), (ljust) ? "%-*.*s" : "%*.*s", wid, prec, str)
135 #define MB_BEGIN if (0) {
136 #define MB_ELSE } else {
150 #define wchar_t char /* ensures we never use the wchar_t typedef */
151 #define wint_t int /* type as large as either wchar_t or WEOF */
152 #define wuchar_t unsigned char /* Force override of typedef */
155 * Must define _WCHAR_T, _WINT_T and _WUCHAR_T to avoid typedefs collisions
156 * in other system headers.
157 * Most systems do something like this:
160 * typedef unsigned short wchar_t
162 * in their system headers to avoid multiple declarations of wchar_t
196 #define getwchar getchar
199 #define putwchar putchar
203 #define ungetwc ungetc
204 #define fwprintf fprintf
205 #define fwscanf fscanf
206 #define wprintf printf
208 #define swscanf sscanf
209 #define vfwprintf vfprintf
210 #define vwprintf vprintf
212 * In single byte mode, both swprintf() and vswprintf() are converted to
213 * similar, but NOT IDENTICAL, functions that have slightly different
215 * The 2nd argument to both these routines (e.g the size_t arg)
216 * is not used in the singlebyte environment since sprintf() and vsprintf()
217 * do not support this argument.
218 * One has to be careful when using this routine to not depend on
219 * the enforcement/safety of this 2nd argument.
221 * swprintf() is converted to m_swprintf(), which is a C function
222 * (because it can use a variable number of args),
223 * which is implemented as a call to vsprint()
224 * vswprintf() is converted to vsprintf()
227 #define swprintf m_swprintf
228 #define vswprintf(w,n,f,v) vsprintf((char*)w,(const char*)f, v)
231 extern wchar_t *m_smalls (const wchar_t *);
242 #define wcstod strtod
243 #define wcstol strtol
244 #define wcstoul strtoul
245 #define wctomb_init() (0) /* No state dependency for nonmultibyte. */
248 * Wide string handling
269 #define wcscpy strcpy
270 #define wcsncpy strncpy
271 #define wcscat strcat
272 #define wcsncat strncat
273 #define wcscoll strcoll
274 #define wcscmp strcmp
275 #define wcsncmp strncmp
276 #define wcsxfrm strxfrm
277 #define wcschr strchr
278 #define wcscspn strcspn
279 #define wcspbrk strpbrk
280 #define wcsrchr strrchr
281 #define wcsspn strspn
282 #define wcsstr strstr
283 #define wcstok(x, y, z) strtok(x, y)
284 #define wcslen strlen
285 #define wcswidth(s1, n) strlen(s1) /* Need a strnlen? */
292 #define wcsftime strftime
295 * Extended Multibyte functions
301 #define wctob(c) ((int) (wint_t) (c))
302 #define sisinit(p) (1) /* Always in initial state */
305 * Define prototypes for singlebyte equivalents of multibyte functions.
306 * We have to use macros to map them to other function names, so that
307 * they do not conflict with the prototypes from <stdlib.h> that may have
308 * used a different definition of wchar_t. The restartable functions are
309 * mapped to their non-restartable counterparts, since there is no state
310 * information to be preserved.
324 #define mblen(s, n) m_sb_mblen(s, n)
325 #define mbrlen(s, n, ps) m_sb_mblen(s, n)
326 #define mbtowc(pwc, s, n) m_sb_mbtowc(pwc, s, n)
327 #define mbrtowc(pwc, s, n, ps) m_sb_mbtowc(pwc, s, n)
328 #define wctomb(s, wc) m_sb_wctomb(s, wc)
329 #define wcrtomb(s, wc, ps) m_sb_wctomb(s, wc)
330 #define mbstowcs(pwcs, s, n) m_sb_mbstowcs(pwcs, s, n)
331 #define mbsrtowcs(pwcs, s, n, ps) m_sb_mbstowcs(pwcs, s, n)
332 #define wcstombs(s, pwcs, n) m_sb_wcstombs(s, pwcs, n)
333 #define wcsrtombs(s, pwcs, n, ps) m_sb_wcstombs(s, pwcs, n)
335 extern int m_sb_mblen(const char *s
, size_t n
);
336 extern int m_sb_mbtowc(wchar_t *pwc
, const char *s
, size_t n
);
337 extern int m_sb_wctomb(char *s
, wchar_t wc
);
338 extern size_t m_sb_mbstowcs(wchar_t *pwcs
, const char *s
, size_t n
);
339 extern size_t m_sb_wcstombs(char *s
, const wchar_t *pwcs
, size_t n
);
342 * convert definitions from <wctype.h>
359 #define iswalnum(c) isalnum(c)
360 #define iswalpha(c) isalpha(c)
361 #define iswcntrl(c) iscntrl(c)
362 #define iswdigit(c) isdigit(c)
363 #define iswgraph(c) isgraph(c)
364 #define iswlower(c) islower(c)
365 #define iswprint(c) isprint(c)
366 #define iswpunct(c) ispunct(c)
367 #define iswspace(c) isspace(c)
368 #define iswupper(c) isupper(c)
369 #define iswxdigit(c) isxdigit(c)
370 #define iswblank(c) isblank(c)
371 #define towlower(c) tolower(c)
372 #define towupper(c) toupper(c)
375 * Note: MKS libc/gen/iswctype.c contains the system independent version
376 * of wctype() and iswctype().
378 * In single byte mode, we can't use the names wctype() and iswctype().
379 * These may have been defined in the system's headers (e.g <wctype.h>)
380 * using the system definition of wint_t and wctype_t.
381 * BUT we have just changed the meaning of wint_t above, to an 'int'
382 * which may not be the same size as wint_t.
383 * Thus, we rename them so that we don't get any prototype conflicts
387 #define wctype _m_wctype
388 #define iswctype _m_iswctype
390 extern wctype_t wctype(const char *property
);
391 extern int iswctype(wint_t wc
, wctype_t desc
);
400 #define fnwwmatch fnmatch
401 #define fnwnmatch fnmatch
410 #define regwcomp regcomp
411 #define regwexec regexec
412 #define regwdosub regdosub
413 #define regwdosuba regdosuba
414 #define regwmatch_t regmatch_t
416 #endif /* M_I18N_MB */
419 * prototypes that are common to both SingleByte and MultiByte
421 extern int m_mbswidth (const char *, size_t);
422 extern int m_mbsrwidth (const char *, size_t, mbstate_t *);
425 #endif /*__M_M_WCHAR_H__*/