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, 2003 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -26,14 +27,16 @@
*/
#include "lint.h"
#include <stdio.h>
#include <wchar.h>
+#include <locale.h>
+#include <xlocale.h>
#include "mblocal.h"
wint_t
-btowc(int c)
+btowc_l(int c, locale_t loc)
{
static const mbstate_t initial = { 0 };
mbstate_t mbs = initial;
char cc;
wchar_t wc;
@@ -44,9 +47,15 @@
* We expect mbrtowc() to return 0 or 1, hence the check for n > 1
* which detects error return values as well as "impossible" byte
* counts.
*/
cc = (char)c;
- if (__mbrtowc(&wc, &cc, 1, &mbs) > 1)
+ if (mbrtowc_l(&wc, &cc, 1, &mbs, loc) > 1)
return (WEOF);
return (wc);
+}
+
+wint_t
+btowc(int c)
+{
+ return (btowc_l(c, uselocale(NULL)));
}