]> 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 62415d380dba4df032b29fc65aef8ec1588b6601..37e6402a8774bf4b2e9f980a4d7519ec5b6a4de9 100644 (file)
@@ -1,5 +1,5 @@
 /*-
- * 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/stdio/ungetwc.c,v 1.5 2002/10/16 12:09:43 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>
 #include "un-namespace.h"
 #include "libc_private.h"
 #include "local.h"
+#include "mblocal.h"
 
 /*
  * 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];
-       mbstate_t mbs;
        size_t len;
 
        if (wc == WEOF)
                return (WEOF);
-       memset(&mbs, 0, sizeof(mbs));
-       if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
+       if ((len = loc->__lc_ctype->__wcrtomb(buf, wc, &fp->_mbstate, loc)) == (size_t)-1) {
                fp->_flags |= __SERR;
                return (WEOF);
        }
@@ -70,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);