fgetwc.c (87275e436a0fb31fea2757532860a3ec993d2cd6) | fgetwc.c (d6ed810a67fa30e63c4e41b72d7d18da9dfa741b) |
---|---|
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 --- 63 unchanged lines hidden (view full) --- 72 FUNLOCKFILE(fp); 73 74 return (r); 75} 76 77static __inline wint_t 78__fgetwc_nbf(FILE *fp) 79{ | 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 --- 63 unchanged lines hidden (view full) --- 72 FUNLOCKFILE(fp); 73 74 return (r); 75} 76 77static __inline wint_t 78__fgetwc_nbf(FILE *fp) 79{ |
80 size_t n, nconv; 81 int c; 82 char cc; | |
83 wchar_t wc; | 80 wchar_t wc; |
81 size_t nconv; |
|
84 | 82 |
85 n = 0; 86 for (;;) { 87 if ((c = __sgetc(fp)) == EOF) { 88 if (n == 0) 89 return (WEOF); | 83 if (fp->_r <= 0 && __srefill(fp)) 84 return (WEOF); 85 do { 86 nconv = mbrtowc(&wc, fp->_p, fp->_r, &fp->_extra->mbstate); 87 if (nconv == (size_t)-1) |
90 break; | 88 break; |
91 } 92 n++; 93 cc = (char)c; 94 nconv = mbrtowc(&wc, &cc, 1, &fp->_extra->mbstate); 95 if (nconv == (size_t)-2) | 89 else if (nconv == (size_t)-2) |
96 continue; | 90 continue; |
97 else if (nconv == (size_t)-1) 98 break; 99 else if (nconv == 0) | 91 else if (nconv == 0) { 92 /* 93 * Assume that the only valid representation of 94 * the null wide character is a single null byte. 95 */ 96 fp->_p++; 97 fp->_r--; |
100 return (L'\0'); | 98 return (L'\0'); |
101 else | 99 } else { 100 fp->_p += nconv; 101 fp->_r -= nconv; |
102 return (wc); | 102 return (wc); |
103 } | 103 } 104 } while (__srefill(fp) == 0); |
104 fp->_flags |= __SERR; 105 errno = EILSEQ; 106 return (WEOF); 107} | 105 fp->_flags |= __SERR; 106 errno = EILSEQ; 107 return (WEOF); 108} |