Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | /* * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ #include "xlocale_private.h" #include <ctype.h> #include <string.h> #include <rune.h> #include <stdlib.h> #include <wchar.h> #include "runedepreciated.h" __private_extern__ const char __rune_depreciated_msg[] = "\ %s and other functions prototyped in rune.h are depreciated in favor of\n\ the ISO C99 extended multibyte and wide character facilities and should not\n\ be used in new applications.\n\ "; __private_extern__ rune_t __sgetrune(const char *string, size_t n, char const **result) { wchar_t wc; size_t converted = mbrtowc(&wc, string, n, NULL); __darwin_rune_t invalid_rune = __current_lc_ctype->_CurrentRuneLocale->__invalid_rune; switch (converted) { case (size_t)-2: /* incomplete */ if (result) *result = string; return invalid_rune; case (size_t)-1: /* invalid */ if (result) *result = string + 1; return invalid_rune; case (size_t)0: /* null wide character */ { int i; for (i = 1; i < n; i++) if (mbrtowc(&wc, string, n, NULL) == (size_t)0) break; if (result) *result = string + i; return (rune_t)0; } default: if (result) *result = string + converted; return (rune_t)wc; } /* NOTREACHED */ } __private_extern__ int __sputrune(rune_t rune, char *string, size_t n, char **result) { char buf[MB_CUR_MAX]; size_t converted = wcrtomb(buf, rune, NULL); if (converted == (size_t)-1) { if (result) *result = string; } else if (n >= converted) { if (string) bcopy(buf, string, converted); if (result) *result = string + converted; } else if (result) *result = NULL; return (converted == (size_t)-1 ? 0 : converted); } __private_extern__ rune_t sgetrune(const char *string, size_t n, char const **result) { static int warn_depreciated = 1; if (warn_depreciated) { warn_depreciated = 0; fprintf(stderr, __rune_depreciated_msg, "sgetrune"); } return __sgetrune(string, n, result); } __private_extern__ int sputrune(rune_t rune, char *string, size_t n, char **result) { static int warn_depreciated = 1; if (warn_depreciated) { warn_depreciated = 0; fprintf(stderr, __rune_depreciated_msg, "sputrune"); } return __sputrune(rune, string, n, result); } |