]> git.saurik.com Git - apple/libc.git/blobdiff - stdio/FreeBSD/ungetwc.c
Libc-1439.100.3.tar.gz
[apple/libc.git] / stdio / FreeBSD / ungetwc.c
index b90671acfce3b4b0f797fe5292be3c5bb4dbb06f..37e6402a8774bf4b2e9f980a4d7519ec5b6a4de9 100644 (file)
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/ungetwc.c,v 1.9 2004/07/20 08:27:27 tjr Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/ungetwc.c,v 1.11 2008/04/17 22:17:54 jhb Exp $");
+
+#include "xlocale_private.h"
 
 #include "namespace.h"
 #include <errno.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <wchar.h>
@@ -41,14 +44,14 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/ungetwc.c,v 1.9 2004/07/20 08:27:27 tjr E
  * Non-MT-safe version.
  */
 wint_t
-__ungetwc(wint_t wc, FILE *fp)
+__ungetwc(wint_t wc, FILE *fp, locale_t loc)
 {
        char buf[MB_LEN_MAX];
        size_t len;
 
        if (wc == WEOF)
                return (WEOF);
-       if ((len = __wcrtomb(buf, wc, &fp->_extra->mbstate)) == (size_t)-1) {
+       if ((len = loc->__lc_ctype->__wcrtomb(buf, wc, &fp->_mbstate, loc)) == (size_t)-1) {
                fp->_flags |= __SERR;
                return (WEOF);
        }
@@ -69,7 +72,21 @@ ungetwc(wint_t wc, FILE *fp)
 
        FLOCKFILE(fp);
        ORIENT(fp, 1);
-       r = __ungetwc(wc, fp);
+       r = __ungetwc(wc, fp, __current_locale());
+       FUNLOCKFILE(fp);
+
+       return (r);
+}
+
+wint_t
+ungetwc_l(wint_t wc, FILE *fp, locale_t loc)
+{
+       wint_t r;
+
+       NORMALIZE_LOCALE(loc);
+       FLOCKFILE(fp);
+       ORIENT(fp, 1);
+       r = __ungetwc(wc, fp, loc);
        FUNLOCKFILE(fp);
 
        return (r);