Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>

*** 1,6 **** --- 1,7 ---- /* + * Copyright 2013 Garrett D'Amore <garrett@damore.org> * Copyright 2010 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2002-2004 Tim J. Robbins. * All rights reserved. * * Redistribution and use in source and binary forms, with or without
*** 27,54 **** #include "lint.h" #include <limits.h> #include <stdlib.h> #include <string.h> #include <wchar.h> #include "mblocal.h" size_t ! wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src, ! size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps) { static mbstate_t mbs; if (ps == NULL) ps = &mbs; ! return (__wcsnrtombs(dst, src, nwc, len, ps)); } size_t ! __wcsnrtombs_std(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src, size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps) { mbstate_t mbsbak; char buf[MB_LEN_MAX]; const wchar_t *s; size_t nbytes; size_t nb; --- 28,66 ---- #include "lint.h" #include <limits.h> #include <stdlib.h> #include <string.h> + #include <locale.h> #include <wchar.h> #include "mblocal.h" + #include "localeimpl.h" + #include "lctype.h" size_t ! wcsnrtombs_l(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src, ! size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps, locale_t loc) { static mbstate_t mbs; if (ps == NULL) ps = &mbs; ! return (loc->ctype->lc_wcsnrtombs(dst, src, nwc, len, ps)); } size_t ! wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src, size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps) { + return (wcsnrtombs_l(dst, src, nwc, len, ps, uselocale(NULL))); + } + + size_t + __wcsnrtombs_std(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src, + size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps, + wcrtomb_pfn_t pwcrtomb) + { mbstate_t mbsbak; char buf[MB_LEN_MAX]; const wchar_t *s; size_t nbytes; size_t nb;
*** 56,66 **** s = *src; nbytes = 0; if (dst == NULL) { while (nwc-- > 0) { ! if ((nb = __wcrtomb(buf, *s, ps)) == (size_t)-1) /* Invalid character - wcrtomb() sets errno. */ return ((size_t)-1); else if (*s == L'\0') return (nbytes + nb - 1); s++; --- 68,78 ---- s = *src; nbytes = 0; if (dst == NULL) { while (nwc-- > 0) { ! if ((nb = pwcrtomb(buf, *s, ps)) == (size_t)-1) /* Invalid character - wcrtomb() sets errno. */ return ((size_t)-1); else if (*s == L'\0') return (nbytes + nb - 1); s++;
*** 70,80 **** } while (len > 0 && nwc-- > 0) { if (len > (size_t)MB_CUR_MAX) { /* Enough space to translate in-place. */ ! if ((nb = __wcrtomb(dst, *s, ps)) == (size_t)-1) { *src = s; return ((size_t)-1); } } else { /* --- 82,92 ---- } while (len > 0 && nwc-- > 0) { if (len > (size_t)MB_CUR_MAX) { /* Enough space to translate in-place. */ ! if ((nb = pwcrtomb(dst, *s, ps)) == (size_t)-1) { *src = s; return ((size_t)-1); } } else { /*
*** 83,93 **** * We need to save a copy of the conversion state * here so we can restore it if the multibyte * character is too long for the buffer. */ mbsbak = *ps; ! if ((nb = __wcrtomb(buf, *s, ps)) == (size_t)-1) { *src = s; return ((size_t)-1); } if (nb > (int)len) { /* MB sequence for character won't fit. */ --- 95,105 ---- * We need to save a copy of the conversion state * here so we can restore it if the multibyte * character is too long for the buffer. */ mbsbak = *ps; ! if ((nb = pwcrtomb(buf, *s, ps)) == (size_t)-1) { *src = s; return ((size_t)-1); } if (nb > (int)len) { /* MB sequence for character won't fit. */