2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include "xlocale_private.h"
30 #include "runedepreciated.h"
32 __private_extern__
const char __rune_depreciated_msg
[] = "\
33 %s and other functions prototyped in rune.h are depreciated in favor of\n\
34 the ISO C99 extended multibyte and wide character facilities and should not\n\
35 be used in new applications.\n\
38 __private_extern__ rune_t
39 __sgetrune(const char *string
, size_t n
, char const **result
)
42 size_t converted
= mbrtowc(&wc
, string
, n
, NULL
);
43 __darwin_rune_t invalid_rune
= __current_locale()->__lc_ctype
->_CurrentRuneLocale
.__invalid_rune
;
46 case (size_t)-2: /* incomplete */
50 case (size_t)-1: /* invalid */
54 case (size_t)0: /* null wide character */
58 for (i
= 1; i
< n
; i
++)
59 if (mbrtowc(&wc
, string
, n
, NULL
) == (size_t)0)
67 *result
= string
+ converted
;
73 __private_extern__
int
74 __sputrune(rune_t rune
, char *string
, size_t n
, char **result
)
77 size_t converted
= wcrtomb(buf
, rune
, NULL
);
82 } else if (n
>= converted
) {
84 bcopy(buf
, string
, converted
);
86 *result
= string
+ converted
;
89 return (converted
< 0 ? 0 : converted
);
92 __private_extern__ rune_t
93 sgetrune(const char *string
, size_t n
, char const **result
)
95 static int warn_depreciated
= 1;
97 if (warn_depreciated
) {
99 fprintf(stderr
, __rune_depreciated_msg
, "sgetrune");
101 return __sgetrune(string
, n
, result
);
104 __private_extern__
int
105 sputrune(rune_t rune
, char *string
, size_t n
, char **result
)
107 static int warn_depreciated
= 1;
109 if (warn_depreciated
) {
110 warn_depreciated
= 0;
111 fprintf(stderr
, __rune_depreciated_msg
, "sputrune");
113 return __sputrune(rune
, string
, n
, result
);