- if(buf){
- buf->in=in;
- buf->conv=NULL;
- buf->showWarning = showWarning;
- buf->isBuffered = buffered;
- buf->signatureLength=0;
- if(*cp==NULL || **cp=='\0'){
- /* don't have code page name... try to autodetect */
- ucbuf_autodetect_fs(in,cp,&buf->conv,&buf->signatureLength,error);
- }else if(ucbuf_isCPKnown(*cp)){
- /* discard BOM */
- ucbuf_autodetect_fs(in,&knownCp,&buf->conv,&buf->signatureLength,error);
- }
- if(U_SUCCESS(*error) && buf->conv==NULL) {
- buf->conv=ucnv_open(*cp,error);
- }
- if(U_FAILURE(*error)){
- ucnv_close(buf->conv);
- uprv_free(buf);
- return NULL;
- }
-
- if((buf->conv==NULL) && (buf->showWarning==TRUE)){
- fprintf(stderr,"###WARNING: No converter defined. Using codepage of system.\n");
- }
- buf->remaining=fileSize-buf->signatureLength;
- if(buf->isBuffered){
- buf->buffer=(UChar*) uprv_malloc(U_SIZEOF_UCHAR* MAX_U_BUF);
- buf->bufCapacity=MAX_U_BUF;
- }else{
- buf->buffer=(UChar*) uprv_malloc(U_SIZEOF_UCHAR * (buf->remaining+buf->signatureLength));
- buf->bufCapacity=buf->remaining+buf->signatureLength;
- }
- if (buf->buffer == NULL) {
- *error = U_MEMORY_ALLOCATION_ERROR;
- return NULL;
- }
- buf->currentPos=buf->buffer;
- buf->bufLimit=buf->buffer;
- if(U_FAILURE(*error)){
- fprintf(stderr, "Could not open codepage [%s]: %s\n", *cp, u_errorName(*error));
- return NULL;
- }
- buf=ucbuf_fillucbuf(buf,error);
- return buf;
+ if(buf == NULL){
+ *error = U_MEMORY_ALLOCATION_ERROR;
+ T_FileStream_close(in);
+ return NULL;
+ }
+ buf->in=in;
+ buf->conv=NULL;
+ buf->showWarning = showWarning;
+ buf->isBuffered = buffered;
+ buf->signatureLength=0;
+ if(*cp==NULL || **cp=='\0'){
+ /* don't have code page name... try to autodetect */
+ ucbuf_autodetect_fs(in,cp,&buf->conv,&buf->signatureLength,error);
+ }else if(ucbuf_isCPKnown(*cp)){
+ /* discard BOM */
+ ucbuf_autodetect_fs(in,&knownCp,&buf->conv,&buf->signatureLength,error);
+ }
+ if(U_SUCCESS(*error) && buf->conv==NULL) {
+ buf->conv=ucnv_open(*cp,error);
+ }
+ if(U_FAILURE(*error)){
+ ucnv_close(buf->conv);
+ uprv_free(buf);
+ T_FileStream_close(in);
+ return NULL;
+ }
+
+ if((buf->conv==NULL) && (buf->showWarning==TRUE)){
+ fprintf(stderr,"###WARNING: No converter defined. Using codepage of system.\n");
+ }
+ buf->remaining=fileSize-buf->signatureLength;
+ if(buf->isBuffered){
+ buf->bufCapacity=MAX_U_BUF;