summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/bss_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/bio/bss_file.c')
-rw-r--r--src/lib/libcrypto/bio/bss_file.c67
1 files changed, 12 insertions, 55 deletions
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
index 8bfa0bcd97..e692a08e58 100644
--- a/src/lib/libcrypto/bio/bss_file.c
+++ b/src/lib/libcrypto/bio/bss_file.c
@@ -118,47 +118,10 @@ static BIO_METHOD methods_filep=
118 118
119BIO *BIO_new_file(const char *filename, const char *mode) 119BIO *BIO_new_file(const char *filename, const char *mode)
120 { 120 {
121 BIO *ret; 121 BIO *ret;
122 FILE *file=NULL; 122 FILE *file;
123
124#if defined(_WIN32) && defined(CP_UTF8)
125 int sz, len_0 = (int)strlen(filename)+1;
126 123
127 /* 124 if ((file=fopen(filename,mode)) == NULL)
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)
162 { 125 {
163 SYSerr(SYS_F_FOPEN,get_last_sys_error()); 126 SYSerr(SYS_F_FOPEN,get_last_sys_error());
164 ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); 127 ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");
@@ -168,7 +131,7 @@ BIO *BIO_new_file(const char *filename, const char *mode)
168 BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); 131 BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
169 return(NULL); 132 return(NULL);
170 } 133 }
171 if ((ret=BIO_new(BIO_s_file())) == NULL) 134 if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
172 { 135 {
173 fclose(file); 136 fclose(file);
174 return(NULL); 137 return(NULL);
@@ -278,7 +241,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
278 if (b->flags&BIO_FLAGS_UPLINK) 241 if (b->flags&BIO_FLAGS_UPLINK)
279 ret=(long)UP_fseek(b->ptr,num,0); 242 ret=(long)UP_fseek(b->ptr,num,0);
280 else 243 else
281 ret=(long)fseek(fp,num,0); 244 ret=(long)fseek(fp,num,SEEK_SET);
282 break; 245 break;
283 case BIO_CTRL_EOF: 246 case BIO_CTRL_EOF:
284 if (b->flags&BIO_FLAGS_UPLINK) 247 if (b->flags&BIO_FLAGS_UPLINK)
@@ -309,9 +272,9 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
309 BIO_clear_flags(b,BIO_FLAGS_UPLINK); 272 BIO_clear_flags(b,BIO_FLAGS_UPLINK);
310#endif 273#endif
311#endif 274#endif
312#ifdef UP_fsetmod 275#ifdef UP_fsetmode
313 if (b->flags&BIO_FLAGS_UPLINK) 276 if (b->flags&BIO_FLAGS_UPLINK)
314 UP_fsetmod(b->ptr,(char)((num&BIO_FP_TEXT)?'t':'b')); 277 UP_fsetmode(b->ptr,num&BIO_FP_TEXT?'t':'b');
315 else 278 else
316#endif 279#endif
317 { 280 {
@@ -323,7 +286,8 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
323 _setmode(fd,_O_BINARY); 286 _setmode(fd,_O_BINARY);
324#elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) 287#elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
325 int fd = fileno((FILE*)ptr); 288 int fd = fileno((FILE*)ptr);
326 /* Under CLib there are differences in file modes */ 289 /* Under CLib there are differences in file modes
290 */
327 if (num & BIO_FP_TEXT) 291 if (num & BIO_FP_TEXT)
328 setmode(fd,O_TEXT); 292 setmode(fd,O_TEXT);
329 else 293 else
@@ -344,7 +308,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
344 else 308 else
345 _setmode(fd,_O_BINARY); 309 _setmode(fd,_O_BINARY);
346 } 310 }
347#elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) 311#elif defined(OPENSSL_SYS_OS2)
348 int fd = fileno((FILE*)ptr); 312 int fd = fileno((FILE*)ptr);
349 if (num & BIO_FP_TEXT) 313 if (num & BIO_FP_TEXT)
350 setmode(fd, O_TEXT); 314 setmode(fd, O_TEXT);
@@ -440,18 +404,11 @@ static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
440 404
441 buf[0]='\0'; 405 buf[0]='\0';
442 if (bp->flags&BIO_FLAGS_UPLINK) 406 if (bp->flags&BIO_FLAGS_UPLINK)
443 { 407 UP_fgets(buf,size,bp->ptr);
444 if (!UP_fgets(buf,size,bp->ptr))
445 goto err;
446 }
447 else 408 else
448 { 409 fgets(buf,size,(FILE *)bp->ptr);
449 if (!fgets(buf,size,(FILE *)bp->ptr))
450 goto err;
451 }
452 if (buf[0] != '\0') 410 if (buf[0] != '\0')
453 ret=strlen(buf); 411 ret=strlen(buf);
454 err:
455 return(ret); 412 return(ret);
456 } 413 }
457 414