Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Approved by: TBD
@@ -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
@@ -29,26 +30,36 @@
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <wchar.h>
#include "mblocal.h"
+#include "localeimpl.h"
+#include "lctype.h"
size_t
-mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
- size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD ps)
+mbsnrtowcs_l(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
+ size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD ps, locale_t loc)
{
static mbstate_t mbs;
if (ps == NULL)
ps = &mbs;
- return (__mbsnrtowcs(dst, src, nms, len, ps));
+ return (loc->ctype->lc_mbsnrtowcs(dst, src, nms, len, ps));
}
size_t
-__mbsnrtowcs_std(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
+mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD ps)
{
+ return (mbsnrtowcs_l(dst, src, nms, len, ps, uselocale(NULL)));
+}
+
+size_t
+__mbsnrtowcs_std(wchar_t *_RESTRICT_KYWD dst, const char **_RESTRICT_KYWD src,
+ size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD ps,
+ mbrtowc_pfn_t pmbrtowc)
+{
const char *s;
size_t nchr;
wchar_t wc;
size_t nb;
@@ -55,11 +66,11 @@
s = *src;
nchr = 0;
if (dst == NULL) {
for (;;) {
- if ((nb = __mbrtowc(&wc, s, nms, ps)) == (size_t)-1)
+ if ((nb = pmbrtowc(&wc, s, nms, ps)) == (size_t)-1)
/* Invalid sequence - mbrtowc() sets errno. */
return ((size_t)-1);
else if (nb == 0 || nb == (size_t)-2)
return (nchr);
s += nb;
@@ -68,11 +79,11 @@
}
/*NOTREACHED*/
}
while (len-- > 0) {
- if ((nb = __mbrtowc(dst, s, nms, ps)) == (size_t)-1) {
+ if ((nb = pmbrtowc(dst, s, nms, ps)) == (size_t)-1) {
*src = s;
return ((size_t)-1);
} else if (nb == (size_t)-2) {
*src = s + nms;
return (nchr);