From 940a3f8f1ced4f833160611f297f005ee0770946 Mon Sep 17 00:00:00 2001 From: Ram Viswanadha Date: Fri, 22 Nov 2002 23:43:32 +0000 Subject: [PATCH] ICU-2474 dont make multiple calls to ungetc X-SVN-Rev: 10352 --- icu4c/source/tools/toolutil/ucbuf.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/icu4c/source/tools/toolutil/ucbuf.c b/icu4c/source/tools/toolutil/ucbuf.c index ce99378310..378e7403e4 100644 --- a/icu4c/source/tools/toolutil/ucbuf.c +++ b/icu4c/source/tools/toolutil/ucbuf.c @@ -57,12 +57,12 @@ ucbuf_autodetect_fs(FileStream* in, const char** cp, UConverter** conv, int32_t* numRead=T_FileStream_read(in, start, sizeof(start)); *cp = ucnv_detectUnicodeSignature(start, numRead, signatureLength, error); - if(*cp==NULL){ - /* unread the bytes already read */ - while(numRead>0) { - T_FileStream_ungetc(start[--numRead], in); - } + + /* unread the bytes beyond what was consumed for U+FEFF */ + T_FileStream_rewind(in); + numRead = T_FileStream_read(in, start,*signatureLength); + if(*cp==NULL){ *conv =NULL; return FALSE; } @@ -84,10 +84,7 @@ ucbuf_autodetect_fs(FileStream* in, const char** cp, UConverter** conv, int32_t* *error=U_INTERNAL_PROGRAM_ERROR; } - /* unread the bytes beyond what was consumed for U+FEFF */ - while(numRead>*signatureLength) { - T_FileStream_ungetc(start[--numRead], in); - } + return TRUE; }