fputwc.c (93996f6d58e252f9f975d3bc8522df8fe227f002) | fputwc.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 --- 27 unchanged lines hidden (view full) --- 38#include "local.h" 39 40/* 41 * Non-MT-safe version. 42 */ 43wint_t 44__fputwc(wchar_t wc, FILE *fp) 45{ | 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 --- 27 unchanged lines hidden (view full) --- 38#include "local.h" 39 40/* 41 * Non-MT-safe version. 42 */ 43wint_t 44__fputwc(wchar_t wc, FILE *fp) 45{ |
46 static const mbstate_t initial; 47 mbstate_t mbs; | |
48 char buf[MB_LEN_MAX]; 49 size_t i, len; 50 51 if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) { 52 /* 53 * Assume single-byte locale with no special encoding. 54 * A more careful test would be to check 55 * _CurrentRuneLocale->encoding. 56 */ 57 *buf = (unsigned char)wc; 58 len = 1; 59 } else { | 46 char buf[MB_LEN_MAX]; 47 size_t i, len; 48 49 if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) { 50 /* 51 * Assume single-byte locale with no special encoding. 52 * A more careful test would be to check 53 * _CurrentRuneLocale->encoding. 54 */ 55 *buf = (unsigned char)wc; 56 len = 1; 57 } else { |
60 mbs = initial; 61 if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) { | 58 if ((len = wcrtomb(buf, wc, &fp->_extra->mbstate)) == 59 (size_t)-1) { |
62 fp->_flags |= __SERR; 63 return (WEOF); 64 } 65 } 66 67 for (i = 0; i < len; i++) 68 if (__sputc((unsigned char)buf[i], fp) == EOF) 69 return (WEOF); --- 19 unchanged lines hidden --- | 60 fp->_flags |= __SERR; 61 return (WEOF); 62 } 63 } 64 65 for (i = 0; i < len; i++) 66 if (__sputc((unsigned char)buf[i], fp) == EOF) 67 return (WEOF); --- 19 unchanged lines hidden --- |