diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_file.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_file.c | 418 |
1 files changed, 203 insertions, 215 deletions
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index 638572ab7f..794f503a69 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c | |||
@@ -102,8 +102,8 @@ static int file_gets(BIO *h, char *str, int size); | |||
102 | static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2); | 102 | static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2); |
103 | static int file_new(BIO *h); | 103 | static int file_new(BIO *h); |
104 | static int file_free(BIO *data); | 104 | static int file_free(BIO *data); |
105 | static BIO_METHOD methods_filep= | 105 | |
106 | { | 106 | static BIO_METHOD methods_filep = { |
107 | BIO_TYPE_FILE, | 107 | BIO_TYPE_FILE, |
108 | "FILE pointer", | 108 | "FILE pointer", |
109 | file_write, | 109 | file_write, |
@@ -114,15 +114,16 @@ static BIO_METHOD methods_filep= | |||
114 | file_new, | 114 | file_new, |
115 | file_free, | 115 | file_free, |
116 | NULL, | 116 | NULL, |
117 | }; | 117 | }; |
118 | 118 | ||
119 | BIO *BIO_new_file(const char *filename, const char *mode) | 119 | BIO |
120 | { | 120 | *BIO_new_file(const char *filename, const char *mode) |
121 | { | ||
121 | BIO *ret; | 122 | BIO *ret; |
122 | FILE *file=NULL; | 123 | FILE *file = NULL; |
123 | 124 | ||
124 | #if defined(_WIN32) && defined(CP_UTF8) | 125 | #if defined(_WIN32) && defined(CP_UTF8) |
125 | int sz, len_0 = (int)strlen(filename)+1; | 126 | int sz, len_0 = (int)strlen(filename) + 1; |
126 | DWORD flags; | 127 | DWORD flags; |
127 | 128 | ||
128 | /* | 129 | /* |
@@ -137,173 +138,171 @@ BIO *BIO_new_file(const char *filename, const char *mode) | |||
137 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall | 138 | * ERROR_NO_UNICODE_TRANSLATION, in which case we fall |
138 | * back to fopen... | 139 | * back to fopen... |
139 | */ | 140 | */ |
140 | if ((sz=MultiByteToWideChar(CP_UTF8,(flags=MB_ERR_INVALID_CHARS), | 141 | if ((sz = MultiByteToWideChar(CP_UTF8,(flags = MB_ERR_INVALID_CHARS), |
141 | filename,len_0,NULL,0))>0 || | 142 | filename, len_0, NULL, 0)) > 0 || |
142 | (GetLastError()==ERROR_INVALID_FLAGS && | 143 | (GetLastError() == ERROR_INVALID_FLAGS && |
143 | (sz=MultiByteToWideChar(CP_UTF8,(flags=0), | 144 | (sz = MultiByteToWideChar(CP_UTF8,(flags = 0), |
144 | filename,len_0,NULL,0))>0) | 145 | filename, len_0, NULL, 0)) > 0)) { |
145 | ) | ||
146 | { | ||
147 | WCHAR wmode[8]; | 146 | WCHAR wmode[8]; |
148 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); | 147 | WCHAR *wfilename = _alloca(sz*sizeof(WCHAR)); |
149 | 148 | ||
150 | if (MultiByteToWideChar(CP_UTF8,flags, | 149 | if (MultiByteToWideChar(CP_UTF8, flags, filename, len_0, |
151 | filename,len_0,wfilename,sz) && | 150 | wfilename, sz) && MultiByteToWideChar(CP_UTF8, 0, mode, |
152 | MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1, | 151 | strlen(mode) + 1, wmode, |
153 | wmode,sizeof(wmode)/sizeof(wmode[0])) && | 152 | sizeof(wmode) / sizeof(wmode[0])) && |
154 | (file=_wfopen(wfilename,wmode))==NULL && | 153 | (file = _wfopen(wfilename, wmode)) == NULL && |
155 | (errno==ENOENT || errno==EBADF) | 154 | (errno == ENOENT || errno == EBADF) |
156 | ) /* UTF-8 decode succeeded, but no file, filename | 155 | ) /* UTF - 8 decode succeeded, but no file, filename |
157 | * could still have been locale-ized... */ | 156 | * could still have been locale-ized... */ |
158 | file = fopen(filename,mode); | 157 | file = fopen(filename, mode); |
159 | } | 158 | } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) { |
160 | else if (GetLastError()==ERROR_NO_UNICODE_TRANSLATION) | 159 | file = fopen(filename, mode); |
161 | { | 160 | } |
162 | file = fopen(filename,mode); | ||
163 | } | ||
164 | #else | 161 | #else |
165 | file=fopen(filename,mode); | 162 | file = fopen(filename, mode); |
163 | |||
166 | #endif | 164 | #endif |
167 | if (file == NULL) | 165 | if (file == NULL) { |
168 | { | ||
169 | SYSerr(SYS_F_FOPEN, errno); | 166 | SYSerr(SYS_F_FOPEN, errno); |
170 | ERR_add_error_data(5,"fopen('",filename,"','",mode,"')"); | 167 | ERR_add_error_data(5, "fopen('", filename, "', '", mode, "')"); |
171 | if (errno == ENOENT) | 168 | if (errno == ENOENT) |
172 | BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE); | 169 | BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE); |
173 | else | 170 | else |
174 | BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB); | 171 | BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB); |
175 | return(NULL); | 172 | return (NULL); |
176 | } | 173 | } |
177 | if ((ret=BIO_new(BIO_s_file())) == NULL) | 174 | if ((ret = BIO_new(BIO_s_file())) == NULL) { |
178 | { | ||
179 | fclose(file); | 175 | fclose(file); |
180 | return(NULL); | 176 | return (NULL); |
181 | } | ||
182 | |||
183 | BIO_clear_flags(ret,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ | ||
184 | BIO_set_fp(ret,file,BIO_CLOSE); | ||
185 | return(ret); | ||
186 | } | 177 | } |
187 | 178 | ||
188 | BIO *BIO_new_fp(FILE *stream, int close_flag) | 179 | BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ |
189 | { | 180 | BIO_set_fp(ret, file, BIO_CLOSE); |
190 | BIO *ret; | 181 | return (ret); |
191 | 182 | } | |
192 | if ((ret=BIO_new(BIO_s_file())) == NULL) | ||
193 | return(NULL); | ||
194 | |||
195 | BIO_set_flags(ret,BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */ | ||
196 | BIO_set_fp(ret,stream,close_flag); | ||
197 | return(ret); | ||
198 | } | ||
199 | 183 | ||
200 | BIO_METHOD *BIO_s_file(void) | 184 | BIO |
201 | { | 185 | *BIO_new_fp(FILE *stream, int close_flag) |
202 | return(&methods_filep); | 186 | { |
203 | } | 187 | BIO *ret; |
204 | 188 | ||
205 | static int file_new(BIO *bi) | 189 | if ((ret = BIO_new(BIO_s_file())) == NULL) |
206 | { | 190 | return (NULL); |
207 | bi->init=0; | 191 | |
208 | bi->num=0; | 192 | BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */ |
209 | bi->ptr=NULL; | 193 | BIO_set_fp(ret, stream, close_flag); |
194 | return (ret); | ||
195 | } | ||
196 | |||
197 | BIO_METHOD | ||
198 | *BIO_s_file(void) | ||
199 | { | ||
200 | return (&methods_filep); | ||
201 | } | ||
202 | |||
203 | static int | ||
204 | file_new(BIO *bi) | ||
205 | { | ||
206 | bi->init = 0; | ||
207 | bi->num = 0; | ||
208 | bi->ptr = NULL; | ||
210 | bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ | 209 | bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ |
211 | return(1); | 210 | return (1); |
212 | } | 211 | } |
213 | 212 | ||
214 | static int file_free(BIO *a) | 213 | static int |
215 | { | 214 | file_free(BIO *a) |
216 | if (a == NULL) return(0); | 215 | { |
217 | if (a->shutdown) | 216 | if (a == NULL) |
218 | { | 217 | return (0); |
219 | if ((a->init) && (a->ptr != NULL)) | 218 | if (a->shutdown) { |
220 | { | 219 | if ((a->init) && (a->ptr != NULL)) { |
221 | if (a->flags&BIO_FLAGS_UPLINK) | 220 | if (a->flags&BIO_FLAGS_UPLINK) |
222 | UP_fclose (a->ptr); | 221 | UP_fclose (a->ptr); |
223 | else | 222 | else |
224 | fclose (a->ptr); | 223 | fclose (a->ptr); |
225 | a->ptr=NULL; | 224 | a->ptr = NULL; |
226 | a->flags=BIO_FLAGS_UPLINK; | 225 | a->flags = BIO_FLAGS_UPLINK; |
227 | } | ||
228 | a->init=0; | ||
229 | } | 226 | } |
230 | return(1); | 227 | a->init = 0; |
231 | } | 228 | } |
232 | 229 | return (1); | |
233 | static int file_read(BIO *b, char *out, int outl) | 230 | } |
234 | { | ||
235 | int ret=0; | ||
236 | 231 | ||
237 | if (b->init && (out != NULL)) | 232 | static int |
238 | { | 233 | file_read(BIO *b, char *out, int outl) |
234 | { | ||
235 | int ret = 0; | ||
236 | |||
237 | if (b->init && (out != NULL)) { | ||
239 | if (b->flags&BIO_FLAGS_UPLINK) | 238 | if (b->flags&BIO_FLAGS_UPLINK) |
240 | ret=UP_fread(out,1,(int)outl,b->ptr); | 239 | ret = UP_fread(out, 1,(int)outl, b->ptr); |
241 | else | 240 | else |
242 | ret=fread(out,1,(int)outl,(FILE *)b->ptr); | 241 | ret = fread(out, 1,(int)outl,(FILE *)b->ptr); |
243 | if(ret == 0 && (b->flags&BIO_FLAGS_UPLINK)?UP_ferror((FILE *)b->ptr):ferror((FILE *)b->ptr)) | 242 | if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ? |
244 | { | 243 | UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) { |
245 | SYSerr(SYS_F_FREAD, errno); | 244 | SYSerr(SYS_F_FREAD, errno); |
246 | BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB); | 245 | BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); |
247 | ret=-1; | 246 | ret = -1; |
248 | } | ||
249 | } | 247 | } |
250 | return(ret); | ||
251 | } | 248 | } |
249 | return (ret); | ||
250 | } | ||
252 | 251 | ||
253 | static int file_write(BIO *b, const char *in, int inl) | 252 | static int |
254 | { | 253 | file_write(BIO *b, const char *in, int inl) |
255 | int ret=0; | 254 | { |
255 | int ret = 0; | ||
256 | 256 | ||
257 | if (b->init && (in != NULL)) | 257 | if (b->init && (in != NULL)) { |
258 | { | ||
259 | if (b->flags&BIO_FLAGS_UPLINK) | 258 | if (b->flags&BIO_FLAGS_UPLINK) |
260 | ret=UP_fwrite(in,(int)inl,1,b->ptr); | 259 | ret = UP_fwrite(in,(int)inl, 1, b->ptr); |
261 | else | 260 | else |
262 | ret=fwrite(in,(int)inl,1,(FILE *)b->ptr); | 261 | ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr); |
263 | if (ret) | 262 | if (ret) |
264 | ret=inl; | 263 | ret = inl; |
265 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ | 264 | /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ |
266 | /* according to Tim Hudson <tjh@cryptsoft.com>, the commented | 265 | /* according to Tim Hudson <tjh@cryptsoft.com>, the commented |
267 | * out version above can cause 'inl' write calls under | 266 | * out version above can cause 'inl' write calls under |
268 | * some stupid stdio implementations (VMS) */ | 267 | * some stupid stdio implementations (VMS) */ |
269 | } | ||
270 | return(ret); | ||
271 | } | 268 | } |
272 | 269 | return (ret); | |
273 | static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | 270 | } |
274 | { | 271 | |
275 | long ret=1; | 272 | static long |
276 | FILE *fp=(FILE *)b->ptr; | 273 | file_ctrl(BIO *b, int cmd, long num, void *ptr) |
274 | { | ||
275 | long ret = 1; | ||
276 | FILE *fp = (FILE *)b->ptr; | ||
277 | FILE **fpp; | 277 | FILE **fpp; |
278 | char p[4]; | 278 | char p[4]; |
279 | 279 | ||
280 | switch (cmd) | 280 | switch (cmd) { |
281 | { | ||
282 | case BIO_C_FILE_SEEK: | 281 | case BIO_C_FILE_SEEK: |
283 | case BIO_CTRL_RESET: | 282 | case BIO_CTRL_RESET: |
284 | if (b->flags&BIO_FLAGS_UPLINK) | 283 | if (b->flags&BIO_FLAGS_UPLINK) |
285 | ret=(long)UP_fseek(b->ptr,num,0); | 284 | ret = (long)UP_fseek(b->ptr, num, 0); |
286 | else | 285 | else |
287 | ret=(long)fseek(fp,num,0); | 286 | ret = (long)fseek(fp, num, 0); |
288 | break; | 287 | break; |
289 | case BIO_CTRL_EOF: | 288 | case BIO_CTRL_EOF: |
290 | if (b->flags&BIO_FLAGS_UPLINK) | 289 | if (b->flags&BIO_FLAGS_UPLINK) |
291 | ret=(long)UP_feof(fp); | 290 | ret = (long)UP_feof(fp); |
292 | else | 291 | else |
293 | ret=(long)feof(fp); | 292 | ret = (long)feof(fp); |
294 | break; | 293 | break; |
295 | case BIO_C_FILE_TELL: | 294 | case BIO_C_FILE_TELL: |
296 | case BIO_CTRL_INFO: | 295 | case BIO_CTRL_INFO: |
297 | if (b->flags&BIO_FLAGS_UPLINK) | 296 | if (b->flags&BIO_FLAGS_UPLINK) |
298 | ret=UP_ftell(b->ptr); | 297 | ret = UP_ftell(b->ptr); |
299 | else | 298 | else |
300 | ret=ftell(fp); | 299 | ret = ftell(fp); |
301 | break; | 300 | break; |
302 | case BIO_C_SET_FILE_PTR: | 301 | case BIO_C_SET_FILE_PTR: |
303 | file_free(b); | 302 | file_free(b); |
304 | b->shutdown=(int)num&BIO_CLOSE; | 303 | b->shutdown = (int)num&BIO_CLOSE; |
305 | b->ptr=ptr; | 304 | b->ptr = ptr; |
306 | b->init=1; | 305 | b->init = 1; |
307 | #if BIO_FLAGS_UPLINK!=0 | 306 | #if BIO_FLAGS_UPLINK!=0 |
308 | #if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES) | 307 | #if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES) |
309 | #define _IOB_ENTRIES 20 | 308 | #define _IOB_ENTRIES 20 |
@@ -311,8 +310,8 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
311 | #if defined(_IOB_ENTRIES) | 310 | #if defined(_IOB_ENTRIES) |
312 | /* Safety net to catch purely internal BIO_set_fp calls */ | 311 | /* Safety net to catch purely internal BIO_set_fp calls */ |
313 | if ((size_t)ptr >= (size_t)stdin && | 312 | if ((size_t)ptr >= (size_t)stdin && |
314 | (size_t)ptr < (size_t)(stdin+_IOB_ENTRIES)) | 313 | (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES)) |
315 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); | 314 | BIO_clear_flags(b, BIO_FLAGS_UPLINK); |
316 | #endif | 315 | #endif |
317 | #endif | 316 | #endif |
318 | #ifdef UP_fsetmod | 317 | #ifdef UP_fsetmod |
@@ -322,102 +321,94 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
322 | #endif | 321 | #endif |
323 | { | 322 | { |
324 | #if defined(OPENSSL_SYS_WINDOWS) | 323 | #if defined(OPENSSL_SYS_WINDOWS) |
325 | int fd = _fileno((FILE*)ptr); | 324 | int fd = _fileno((FILE*)ptr); |
326 | if (num & BIO_FP_TEXT) | 325 | if (num & BIO_FP_TEXT) |
327 | _setmode(fd,_O_TEXT); | 326 | _setmode(fd, _O_TEXT); |
328 | else | 327 | else |
329 | _setmode(fd,_O_BINARY); | 328 | _setmode(fd, _O_BINARY); |
330 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) | 329 | #elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB) |
331 | int fd = fileno((FILE*)ptr); | 330 | int fd = fileno((FILE*)ptr); |
332 | /* Under CLib there are differences in file modes */ | 331 | /* Under CLib there are differences in file modes */ |
333 | if (num & BIO_FP_TEXT) | 332 | if (num & BIO_FP_TEXT) |
334 | setmode(fd,O_TEXT); | 333 | setmode(fd, O_TEXT); |
335 | else | ||
336 | setmode(fd,O_BINARY); | ||
337 | #elif defined(OPENSSL_SYS_MSDOS) | ||
338 | int fd = fileno((FILE*)ptr); | ||
339 | /* Set correct text/binary mode */ | ||
340 | if (num & BIO_FP_TEXT) | ||
341 | _setmode(fd,_O_TEXT); | ||
342 | /* Dangerous to set stdin/stdout to raw (unless redirected) */ | ||
343 | else | ||
344 | { | ||
345 | if (fd == STDIN_FILENO || fd == STDOUT_FILENO) | ||
346 | { | ||
347 | if (isatty(fd) <= 0) | ||
348 | _setmode(fd,_O_BINARY); | ||
349 | } | ||
350 | else | 334 | else |
351 | _setmode(fd,_O_BINARY); | 335 | setmode(fd, O_BINARY); |
336 | #elif defined(OPENSSL_SYS_MSDOS) | ||
337 | int fd = fileno((FILE*)ptr); | ||
338 | /* Set correct text/binary mode */ | ||
339 | if (num & BIO_FP_TEXT) | ||
340 | _setmode(fd, _O_TEXT); | ||
341 | /* Dangerous to set stdin/stdout to raw (unless redirected) */ | ||
342 | else { | ||
343 | if (fd == STDIN_FILENO || fd == STDOUT_FILENO) { | ||
344 | if (isatty(fd) <= 0) | ||
345 | _setmode(fd, _O_BINARY); | ||
346 | } else | ||
347 | _setmode(fd, _O_BINARY); | ||
352 | } | 348 | } |
353 | #elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) | 349 | #elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) |
354 | int fd = fileno((FILE*)ptr); | 350 | int fd = fileno((FILE*)ptr); |
355 | if (num & BIO_FP_TEXT) | 351 | if (num & BIO_FP_TEXT) |
356 | setmode(fd, O_TEXT); | 352 | setmode(fd, O_TEXT); |
357 | else | 353 | else |
358 | setmode(fd, O_BINARY); | 354 | setmode(fd, O_BINARY); |
359 | #endif | 355 | #endif |
360 | } | 356 | } |
361 | break; | 357 | break; |
362 | case BIO_C_SET_FILENAME: | 358 | case BIO_C_SET_FILENAME: |
363 | file_free(b); | 359 | file_free(b); |
364 | b->shutdown=(int)num&BIO_CLOSE; | 360 | b->shutdown = (int)num&BIO_CLOSE; |
365 | if (num & BIO_FP_APPEND) | 361 | if (num & BIO_FP_APPEND) { |
366 | { | ||
367 | if (num & BIO_FP_READ) | 362 | if (num & BIO_FP_READ) |
368 | BUF_strlcpy(p,"a+",sizeof p); | 363 | BUF_strlcpy(p, "a+", sizeof p); |
369 | else BUF_strlcpy(p,"a",sizeof p); | 364 | else BUF_strlcpy(p, "a", sizeof p); |
370 | } | 365 | } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) |
371 | else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) | 366 | BUF_strlcpy(p, "r+", sizeof p); |
372 | BUF_strlcpy(p,"r+",sizeof p); | ||
373 | else if (num & BIO_FP_WRITE) | 367 | else if (num & BIO_FP_WRITE) |
374 | BUF_strlcpy(p,"w",sizeof p); | 368 | BUF_strlcpy(p, "w", sizeof p); |
375 | else if (num & BIO_FP_READ) | 369 | else if (num & BIO_FP_READ) |
376 | BUF_strlcpy(p,"r",sizeof p); | 370 | BUF_strlcpy(p, "r", sizeof p); |
377 | else | 371 | else { |
378 | { | 372 | BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE); |
379 | BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE); | 373 | ret = 0; |
380 | ret=0; | ||
381 | break; | 374 | break; |
382 | } | 375 | } |
383 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) | 376 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN) |
384 | if (!(num & BIO_FP_TEXT)) | 377 | if (!(num & BIO_FP_TEXT)) |
385 | strcat(p,"b"); | 378 | strcat(p, "b"); |
386 | else | 379 | else |
387 | strcat(p,"t"); | 380 | strcat(p, "t"); |
388 | #endif | 381 | #endif |
389 | #if defined(OPENSSL_SYS_NETWARE) | 382 | #if defined(OPENSSL_SYS_NETWARE) |
390 | if (!(num & BIO_FP_TEXT)) | 383 | if (!(num & BIO_FP_TEXT)) |
391 | strcat(p,"b"); | 384 | strcat(p, "b"); |
392 | else | 385 | else |
393 | strcat(p,"t"); | 386 | strcat(p, "t"); |
394 | #endif | 387 | #endif |
395 | fp=fopen(ptr,p); | 388 | fp = fopen(ptr, p); |
396 | if (fp == NULL) | 389 | if (fp == NULL) { |
397 | { | ||
398 | SYSerr(SYS_F_FOPEN, errno); | 390 | SYSerr(SYS_F_FOPEN, errno); |
399 | ERR_add_error_data(5,"fopen('",ptr,"','",p,"')"); | 391 | ERR_add_error_data(5, "fopen('", ptr, "', '", p, "')"); |
400 | BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB); | 392 | BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB); |
401 | ret=0; | 393 | ret = 0; |
402 | break; | 394 | break; |
403 | } | 395 | } |
404 | b->ptr=fp; | 396 | b->ptr = fp; |
405 | b->init=1; | 397 | b->init = 1; |
406 | BIO_clear_flags(b,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ | 398 | BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ |
407 | break; | 399 | break; |
408 | case BIO_C_GET_FILE_PTR: | 400 | case BIO_C_GET_FILE_PTR: |
409 | /* the ptr parameter is actually a FILE ** in this case. */ | 401 | /* the ptr parameter is actually a FILE ** in this case. */ |
410 | if (ptr != NULL) | 402 | if (ptr != NULL) { |
411 | { | 403 | fpp = (FILE **)ptr; |
412 | fpp=(FILE **)ptr; | 404 | *fpp = (FILE *)b->ptr; |
413 | *fpp=(FILE *)b->ptr; | 405 | } |
414 | } | ||
415 | break; | 406 | break; |
416 | case BIO_CTRL_GET_CLOSE: | 407 | case BIO_CTRL_GET_CLOSE: |
417 | ret=(long)b->shutdown; | 408 | ret = (long)b->shutdown; |
418 | break; | 409 | break; |
419 | case BIO_CTRL_SET_CLOSE: | 410 | case BIO_CTRL_SET_CLOSE: |
420 | b->shutdown=(int)num; | 411 | b->shutdown = (int)num; |
421 | break; | 412 | break; |
422 | case BIO_CTRL_FLUSH: | 413 | case BIO_CTRL_FLUSH: |
423 | if (b->flags&BIO_FLAGS_UPLINK) | 414 | if (b->flags&BIO_FLAGS_UPLINK) |
@@ -426,7 +417,7 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
426 | fflush((FILE *)b->ptr); | 417 | fflush((FILE *)b->ptr); |
427 | break; | 418 | break; |
428 | case BIO_CTRL_DUP: | 419 | case BIO_CTRL_DUP: |
429 | ret=1; | 420 | ret = 1; |
430 | break; | 421 | break; |
431 | 422 | ||
432 | case BIO_CTRL_WPENDING: | 423 | case BIO_CTRL_WPENDING: |
@@ -434,44 +425,41 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
434 | case BIO_CTRL_PUSH: | 425 | case BIO_CTRL_PUSH: |
435 | case BIO_CTRL_POP: | 426 | case BIO_CTRL_POP: |
436 | default: | 427 | default: |
437 | ret=0; | 428 | ret = 0; |
438 | break; | 429 | break; |
439 | } | ||
440 | return(ret); | ||
441 | } | 430 | } |
431 | return (ret); | ||
432 | } | ||
442 | 433 | ||
443 | static int file_gets(BIO *bp, char *buf, int size) | 434 | static int |
444 | { | 435 | file_gets(BIO *bp, char *buf, int size) |
445 | int ret=0; | 436 | { |
437 | int ret = 0; | ||
446 | 438 | ||
447 | buf[0]='\0'; | 439 | buf[0] = '\0'; |
448 | if (bp->flags&BIO_FLAGS_UPLINK) | 440 | if (bp->flags&BIO_FLAGS_UPLINK) { |
449 | { | 441 | if (!UP_fgets(buf, size, bp->ptr)) |
450 | if (!UP_fgets(buf,size,bp->ptr)) | ||
451 | goto err; | 442 | goto err; |
452 | } | 443 | } else { |
453 | else | 444 | if (!fgets(buf, size,(FILE *)bp->ptr)) |
454 | { | ||
455 | if (!fgets(buf,size,(FILE *)bp->ptr)) | ||
456 | goto err; | 445 | goto err; |
457 | } | ||
458 | if (buf[0] != '\0') | ||
459 | ret=strlen(buf); | ||
460 | err: | ||
461 | return(ret); | ||
462 | } | 446 | } |
447 | if (buf[0] != '\0') | ||
448 | ret = strlen(buf); | ||
449 | err: | ||
450 | return (ret); | ||
451 | } | ||
463 | 452 | ||
464 | static int file_puts(BIO *bp, const char *str) | 453 | static int |
465 | { | 454 | file_puts(BIO *bp, const char *str) |
466 | int n,ret; | 455 | { |
456 | int n, ret; | ||
467 | 457 | ||
468 | n=strlen(str); | 458 | n = strlen(str); |
469 | ret=file_write(bp,str,n); | 459 | ret = file_write(bp, str, n); |
470 | return(ret); | 460 | return (ret); |
471 | } | 461 | } |
472 | 462 | ||
473 | #endif /* OPENSSL_NO_STDIO */ | 463 | #endif /* OPENSSL_NO_STDIO */ |
474 | 464 | ||
475 | #endif /* HEADER_BSS_FILE_C */ | 465 | #endif /* HEADER_BSS_FILE_C */ |
476 | |||
477 | |||