fgetwc.c (93996f6d58e252f9f975d3bc8522df8fe227f002) | fgetwc.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 --- 61 unchanged lines hidden (view full) --- 72 FUNLOCKFILE(fp); 73 74 return (r); 75} 76 77static __inline wint_t 78__fgetwc_nbf(FILE *fp) 79{ | 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 --- 61 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 static const mbstate_t initial; 81 mbstate_t mbs; 82 char buf[MB_LEN_MAX]; | |
83 size_t n, nconv; 84 int c; | 80 size_t n, nconv; 81 int c; |
82 char cc; |
|
85 wchar_t wc; 86 87 n = 0; | 83 wchar_t wc; 84 85 n = 0; |
88 while (n < MB_CUR_MAX) { | 86 for (;;) { |
89 if ((c = __sgetc(fp)) == EOF) { 90 if (n == 0) 91 return (WEOF); 92 break; 93 } | 87 if ((c = __sgetc(fp)) == EOF) { 88 if (n == 0) 89 return (WEOF); 90 break; 91 } |
94 buf[n++] = (char)c; 95 mbs = initial; 96 nconv = mbrtowc(&wc, buf, n, &mbs); 97 if (nconv == n) 98 return (wc); 99 else if (nconv == 0) 100 return (L'\0'); | 92 n++; 93 cc = (char)c; 94 nconv = mbrtowc(&wc, &cc, 1, &fp->_extra->mbstate); 95 if (nconv == (size_t)-2) 96 continue; |
101 else if (nconv == (size_t)-1) 102 break; | 97 else if (nconv == (size_t)-1) 98 break; |
99 else if (nconv == 0) 100 return (L'\0'); 101 else 102 return (wc); |
|
103 } | 103 } |
104 105 while (n-- != 0) 106 __ungetc((unsigned char)buf[n], fp); 107 errno = EILSEQ; | |
108 fp->_flags |= __SERR; | 104 fp->_flags |= __SERR; |
105 errno = EILSEQ; |
|
109 return (WEOF); 110} | 106 return (WEOF); 107} |