diff options
author | djm <> | 2010-10-01 22:59:01 +0000 |
---|---|---|
committer | djm <> | 2010-10-01 22:59:01 +0000 |
commit | fe047d8b632246cb2db3234a0a4f32e5c318857b (patch) | |
tree | 939b752540947d33507b3acc48d76a8bfb7c3dc3 /src/lib/libcrypto/bio/bss_file.c | |
parent | 2ea67f4aa254b09ded62e6e14fc893bbe6381579 (diff) | |
download | openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.gz openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.bz2 openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.zip |
resolve conflicts, fix local changes
Diffstat (limited to 'src/lib/libcrypto/bio/bss_file.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_file.c | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index e692a08e58..8bfa0bcd97 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c | |||
@@ -118,10 +118,47 @@ static BIO_METHOD methods_filep= | |||
118 | 118 | ||
119 | BIO *BIO_new_file(const char *filename, const char *mode) | 119 | BIO *BIO_new_file(const char *filename, const char *mode) |
120 | { | 120 | { |
121 | BIO *ret; | 121 | BIO *ret; |
122 | FILE *file; | 122 | FILE *file=NULL; |
123 | |||
124 | #if defined(_WIN32) && defined(CP_UTF8) | ||
125 | int sz, len_0 = (int)strlen(filename)+1; | ||
123 | 126 | ||
124 | if ((file=fopen(filename,mode)) == NULL) | 127 | /* |
128 | * Basically there are three cases to cover: a) filename is | ||
129 | * pure ASCII string; b) actual UTF-8 encoded string and | ||
130 | * c) locale-ized string, i.e. one containing 8-bit | ||
131 | * characters that are meaningful in current system locale. | ||
132 | * If filename is pure ASCII or real UTF-8 encoded string, | ||
133 | * MultiByteToWideChar succeeds and _wfopen works. If | ||
134 | * filename is locale-ized string, chances are that | ||
135 | * MultiByteToWideChar fails reporting | ||
136 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall | ||
137 | * back to fopen... | ||
138 | */ | ||
139 | if ((sz=MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS, | ||
140 | filename,len_0,NULL,0))>0) | ||
141 | { | ||
142 | WCHAR wmode[8]; | ||
143 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); | ||
144 | |||
145 | if (MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS, | ||
146 | filename,len_0,wfilename,sz) && | ||
147 | MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1, | ||
148 | wmode,sizeof(wmode)/sizeof(wmode[0])) && | ||
149 | (file=_wfopen(wfilename,wmode))==NULL && errno==ENOENT | ||
150 | ) /* UTF-8 decode succeeded, but no file, filename | ||
151 | * could still have been locale-ized... */ | ||
152 | file = fopen(filename,mode); | ||
153 | } | ||
154 | else if (GetLastError()==ERROR_NO_UNICODE_TRANSLATION) | ||
155 | { | ||
156 | file = fopen(filename,mode); | ||
157 | } | ||
158 | #else | ||
159 | file=fopen(filename,mode); | ||
160 | #endif | ||
161 | if (file == NULL) | ||
125 | { | 162 | { |
126 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); | 163 | SYSerr(SYS_F_FOPEN,get_last_sys_error()); |
127 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); | 164 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); |
@@ -131,7 +168,7 @@ BIO *BIO_new_file(const char *filename, const char *mode) | |||
131 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); | 168 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); |
132 | return(NULL); | 169 | return(NULL); |
133 | } | 170 | } |
134 | if ((ret=BIO_new(BIO_s_file_internal())) == NULL) | 171 | if ((ret=BIO_new(BIO_s_file())) == NULL) |
135 | { | 172 | { |
136 | fclose(file); | 173 | fclose(file); |
137 | return(NULL); | 174 | return(NULL); |
@@ -241,7 +278,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
241 | if (b->flags&BIO_FLAGS_UPLINK) | 278 | if (b->flags&BIO_FLAGS_UPLINK) |
242 | ret=(long)UP_fseek(b->ptr,num,0); | 279 | ret=(long)UP_fseek(b->ptr,num,0); |
243 | else | 280 | else |
244 | ret=(long)fseek(fp,num,SEEK_SET); | 281 | ret=(long)fseek(fp,num,0); |
245 | break; | 282 | break; |
246 | case BIO_CTRL_EOF: | 283 | case BIO_CTRL_EOF: |
247 | if (b->flags&BIO_FLAGS_UPLINK) | 284 | if (b->flags&BIO_FLAGS_UPLINK) |
@@ -272,9 +309,9 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
272 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); | 309 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); |
273 | #endif | 310 | #endif |
274 | #endif | 311 | #endif |
275 | #ifdef UP_fsetmode | 312 | #ifdef UP_fsetmod |
276 | if (b->flags&BIO_FLAGS_UPLINK) | 313 | if (b->flags&BIO_FLAGS_UPLINK) |
277 | UP_fsetmode(b->ptr,num&BIO_FP_TEXT?'t':'b'); | 314 | UP_fsetmod(b->ptr,(char)((num&BIO_FP_TEXT)?'t':'b')); |
278 | else | 315 | else |
279 | #endif | 316 | #endif |
280 | { | 317 | { |
@@ -286,8 +323,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
286 | _setmode(fd,_O_BINARY); | 323 | _setmode(fd,_O_BINARY); |
287 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) | 324 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) |
288 | int fd = fileno((FILE*)ptr); | 325 | int fd = fileno((FILE*)ptr); |
289 | /* Under CLib there are differences in file modes | 326 | /* Under CLib there are differences in file modes */ |
290 | */ | ||
291 | if (num & BIO_FP_TEXT) | 327 | if (num & BIO_FP_TEXT) |
292 | setmode(fd,O_TEXT); | 328 | setmode(fd,O_TEXT); |
293 | else | 329 | else |
@@ -308,7 +344,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
308 | else | 344 | else |
309 | _setmode(fd,_O_BINARY); | 345 | _setmode(fd,_O_BINARY); |
310 | } | 346 | } |
311 | #elif defined(OPENSSL_SYS_OS2) | 347 | #elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) |
312 | int fd = fileno((FILE*)ptr); | 348 | int fd = fileno((FILE*)ptr); |
313 | if (num & BIO_FP_TEXT) | 349 | if (num & BIO_FP_TEXT) |
314 | setmode(fd, O_TEXT); | 350 | setmode(fd, O_TEXT); |
@@ -404,11 +440,18 @@ static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size) | |||
404 | 440 | ||
405 | buf[0]='\0'; | 441 | buf[0]='\0'; |
406 | if (bp->flags&BIO_FLAGS_UPLINK) | 442 | if (bp->flags&BIO_FLAGS_UPLINK) |
407 | UP_fgets(buf,size,bp->ptr); | 443 | { |
444 | if (!UP_fgets(buf,size,bp->ptr)) | ||
445 | goto err; | ||
446 | } | ||
408 | else | 447 | else |
409 | fgets(buf,size,(FILE *)bp->ptr); | 448 | { |
449 | if (!fgets(buf,size,(FILE *)bp->ptr)) | ||
450 | goto err; | ||
451 | } | ||
410 | if (buf[0] != '\0') | 452 | if (buf[0] != '\0') |
411 | ret=strlen(buf); | 453 | ret=strlen(buf); |
454 | err: | ||
412 | return(ret); | 455 | return(ret); |
413 | } | 456 | } |
414 | 457 | ||