X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/48b980fed3435926e0b3a8d72ecb58be703a1c7a..729e4ab9bc6618bc3d8a898e575df7f4019e29ca:/icuSources/io/ufile.c diff --git a/icuSources/io/ufile.c b/icuSources/io/ufile.c index e3f2d917..2f0739f1 100644 --- a/icuSources/io/ufile.c +++ b/icuSources/io/ufile.c @@ -1,7 +1,7 @@ /* ****************************************************************************** * -* Copyright (C) 1998-2008, International Business Machines +* Copyright (C) 1998-2010, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** @@ -42,10 +42,12 @@ #define fileno _fileno #endif -U_CAPI UFILE* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ -u_finit(FILE *f, - const char *locale, - const char *codepage) +static UFILE* +finit_owner(FILE *f, + const char *locale, + const char *codepage, + UBool takeOwnership + ) { UErrorCode status = U_ZERO_ERROR; UFILE *result; @@ -94,7 +96,10 @@ u_finit(FILE *f, } /* else result->fConverter is already memset'd to NULL. */ - if(U_FAILURE(status)) { + if(U_SUCCESS(status)) { + result->fOwnFile = takeOwnership; + } + else { #if !UCONFIG_NO_FORMATTING u_locbund_close(&result->str.fBundle); #endif @@ -106,6 +111,22 @@ u_finit(FILE *f, return result; } +U_CAPI UFILE* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ +u_finit(FILE *f, + const char *locale, + const char *codepage) +{ + return finit_owner(f, locale, codepage, FALSE); +} + +U_CAPI UFILE* U_EXPORT2 +u_fadopt(FILE *f, + const char *locale, + const char *codepage) +{ + return finit_owner(f, locale, codepage, TRUE); +} + U_CAPI UFILE* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ u_fopen(const char *filename, const char *perm, @@ -118,12 +139,9 @@ u_fopen(const char *filename, return 0; } - result = u_finit(systemFile, locale, codepage); + result = finit_owner(systemFile, locale, codepage, TRUE); - if (result) { - result->fOwnFile = TRUE; - } - else { + if (!result) { /* Something bad happened. Maybe the converter couldn't be opened. */ fclose(systemFile); @@ -183,6 +201,7 @@ U_CAPI void U_EXPORT2 u_fflush(UFILE *file) { ufile_flush_translit(file); + ufile_flush_io(file); if (file->fFile) { fflush(file->fFile); } @@ -210,18 +229,20 @@ u_frewind(UFILE *file) U_CAPI void U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ u_fclose(UFILE *file) { - u_fflush(file); - ufile_close_translit(file); + if (file) { + u_fflush(file); + ufile_close_translit(file); - if(file->fOwnFile) - fclose(file->fFile); + if(file->fOwnFile) + fclose(file->fFile); #if !UCONFIG_NO_FORMATTING - u_locbund_close(&file->str.fBundle); + u_locbund_close(&file->str.fBundle); #endif - ucnv_close(file->fConverter); - uprv_free(file); + ucnv_close(file->fConverter); + uprv_free(file); + } } U_CAPI FILE* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */