ungetwc.c (93996f6d58e252f9f975d3bc8522df8fe227f002) ungetwc.c (87275e436a0fb31fea2757532860a3ec993d2cd6)
1/*-
1/*-
2 * Copyright (c) 2002 Tim J. Robbins.
2 * Copyright (c) 2002-2004 Tim J. Robbins.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 26 unchanged lines hidden (view full) ---

37#include "local.h"
38
39/*
40 * Non-MT-safe version.
41 */
42wint_t
43__ungetwc(wint_t wc, FILE *fp)
44{
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright

--- 26 unchanged lines hidden (view full) ---

37#include "local.h"
38
39/*
40 * Non-MT-safe version.
41 */
42wint_t
43__ungetwc(wint_t wc, FILE *fp)
44{
45 static const mbstate_t initial;
46 mbstate_t mbs;
47 char buf[MB_LEN_MAX];
48 size_t len;
49
50 if (wc == WEOF)
51 return (WEOF);
45 char buf[MB_LEN_MAX];
46 size_t len;
47
48 if (wc == WEOF)
49 return (WEOF);
52 mbs = initial;
53 if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
50 if ((len = wcrtomb(buf, wc, &fp->_extra->mbstate)) == (size_t)-1) {
54 fp->_flags |= __SERR;
55 return (WEOF);
56 }
57 while (len-- != 0)
58 if (__ungetc((unsigned char)buf[len], fp) == EOF)
59 return (WEOF);
60
61 return (wc);

--- 17 unchanged lines hidden ---
51 fp->_flags |= __SERR;
52 return (WEOF);
53 }
54 while (len-- != 0)
55 if (__ungetc((unsigned char)buf[len], fp) == EOF)
56 return (WEOF);
57
58 return (wc);

--- 17 unchanged lines hidden ---