/*-
- * Copyright (c) 2002 Tim J. Robbins.
+ * Copyright (c) 2002-2004 Tim J. Robbins.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/wcrtomb.c,v 1.4 2003/04/10 09:20:38 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/locale/wcrtomb.c,v 1.8 2004/05/12 14:09:04 tjr Exp $");
+
+#include "xlocale_private.h"
-#include <errno.h>
-#include <limits.h>
-#include <rune.h>
-#include <stdlib.h>
#include <wchar.h>
+#include "mblocal.h"
size_t
-wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps __unused)
+wcrtomb_l(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps,
+ locale_t loc)
{
- char *e;
- char buf[MB_LEN_MAX];
+ NORMALIZE_LOCALE(loc);
+ if (ps == NULL)
+ ps = &loc->__mbs_wcrtomb;
+ return (loc->__lc_ctype->__wcrtomb(s, wc, ps, loc));
+}
- if (s == NULL) {
- s = buf;
- wc = L'\0';
- }
- sputrune(wc, s, MB_CUR_MAX, &e);
- if (e == NULL) {
- errno = EILSEQ;
- return ((size_t)-1);
- }
- return ((size_t)(e - s));
+size_t
+wcrtomb(char * __restrict s, wchar_t wc, mbstate_t * __restrict ps)
+{
+ return wcrtomb_l(s, wc, ps, __current_locale());
}