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 (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
@@ -42,29 +43,37 @@
#include "lint.h"
#include <wchar.h>
#include "_ctype.h"
#include "runetype.h"
+#include "localeimpl.h"
#undef wcwidth
int
-wcwidth(wchar_t wc)
+wcwidth_l(wchar_t wc, locale_t loc)
{
unsigned int x;
+ const _RuneLocale *rl = loc->runelocale;
if (wc == 0)
return (0);
- x = ((wc < 0 || wc >= _CACHED_RUNES) ? ___runetype(wc) :
- _CurrentRuneLocale->__runetype[wc]) & (_CTYPE_SWM|_CTYPE_R);
+ x = ((wc < 0 || wc >= _CACHED_RUNES) ? __runetype(rl, wc) :
+ rl->__runetype[wc]) & (_CTYPE_SWM|_CTYPE_R);
if ((x & _CTYPE_SWM) != 0)
return ((x & _CTYPE_SWM) >> _CTYPE_SWS);
return ((x & _CTYPE_R) != 0 ? 1 : -1);
}
+int
+wcwidth(wchar_t wc)
+{
+ return (wcwidth_l(wc, uselocale(NULL)));
+}
+
#pragma weak _scrwidth = scrwidth
/*
* This is a Solaris extension. It never returns a negative width, even for
* non-printable characters. It is used internally by the printf