fputwc.c (87275e436a0fb31fea2757532860a3ec993d2cd6) | fputwc.c (f9ceea9bf17bc8d7b0020c409743f162c3c5eebd) |
---|---|
1/*- 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 --- 22 unchanged lines hidden (view full) --- 31#include <errno.h> 32#include <limits.h> 33#include <stdio.h> 34#include <stdlib.h> 35#include <wchar.h> 36#include "un-namespace.h" 37#include "libc_private.h" 38#include "local.h" | 1/*- 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 --- 22 unchanged lines hidden (view full) --- 31#include <errno.h> 32#include <limits.h> 33#include <stdio.h> 34#include <stdlib.h> 35#include <wchar.h> 36#include "un-namespace.h" 37#include "libc_private.h" 38#include "local.h" |
39#include "mblocal.h" |
|
39 40/* 41 * Non-MT-safe version. 42 */ 43wint_t 44__fputwc(wchar_t wc, FILE *fp) 45{ 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 { | 40 41/* 42 * Non-MT-safe version. 43 */ 44wint_t 45__fputwc(wchar_t wc, FILE *fp) 46{ 47 char buf[MB_LEN_MAX]; 48 size_t i, len; 49 50 if (MB_CUR_MAX == 1 && wc > 0 && wc <= UCHAR_MAX) { 51 /* 52 * Assume single-byte locale with no special encoding. 53 * A more careful test would be to check 54 * _CurrentRuneLocale->encoding. 55 */ 56 *buf = (unsigned char)wc; 57 len = 1; 58 } else { |
58 if ((len = wcrtomb(buf, wc, &fp->_extra->mbstate)) == | 59 if ((len = __wcrtomb(buf, wc, &fp->_extra->mbstate)) == |
59 (size_t)-1) { 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) --- 20 unchanged lines hidden --- | 60 (size_t)-1) { 61 fp->_flags |= __SERR; 62 return (WEOF); 63 } 64 } 65 66 for (i = 0; i < len; i++) 67 if (__sputc((unsigned char)buf[i], fp) == EOF) --- 20 unchanged lines hidden --- |