diff options
-rw-r--r-- | apps/lib/apps.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/apps/lib/apps.c b/apps/lib/apps.c index a29d582990..9762001b6a 100644 --- a/apps/lib/apps.c +++ b/apps/lib/apps.c @@ -2962,28 +2962,32 @@ BIO *bio_open_owner(const char *filename, int format, int private) { FILE *fp = NULL; BIO *b = NULL; - int fd = -1, bflags, mode, textmode; + int textmode, bflags; +#ifndef OPENSSL_NO_POSIX_IO + int fd = -1, mode; +#endif if (!private || filename == NULL || strcmp(filename, "-") == 0) return bio_open_default(filename, 'w', format); + textmode = FMT_istext(format); +#ifndef OPENSSL_NO_POSIX_IO mode = O_WRONLY; -#ifdef O_CREAT +# ifdef O_CREAT mode |= O_CREAT; -#endif -#ifdef O_TRUNC +# endif +# ifdef O_TRUNC mode |= O_TRUNC; -#endif - textmode = FMT_istext(format); +# endif if (!textmode) { -#ifdef O_BINARY +# ifdef O_BINARY mode |= O_BINARY; -#elif defined(_O_BINARY) +# elif defined(_O_BINARY) mode |= _O_BINARY; -#endif +# endif } -#ifdef OPENSSL_SYS_VMS +# ifdef OPENSSL_SYS_VMS /* VMS doesn't have O_BINARY, it just doesn't make sense. But, * it still needs to know that we're going binary, or fdopen() * will fail with "invalid argument"... so we tell VMS what the @@ -2992,18 +2996,22 @@ BIO *bio_open_owner(const char *filename, int format, int private) if (!textmode) fd = open(filename, mode, 0600, "ctx=bin"); else -#endif +# endif fd = open(filename, mode, 0600); if (fd < 0) goto err; fp = fdopen(fd, modestr('w', format)); +#else /* OPENSSL_NO_POSIX_IO */ + /* Have stdio but not Posix IO, do the best we can */ + fp = fopen(filename, modestr('w', format)); +#endif /* OPENSSL_NO_POSIX_IO */ if (fp == NULL) goto err; bflags = BIO_CLOSE; if (textmode) bflags |= BIO_FP_TEXT; b = BIO_new_fp(fp, bflags); - if (b) + if (b != NULL) return b; err: @@ -3011,10 +3019,12 @@ BIO *bio_open_owner(const char *filename, int format, int private) opt_getprog(), filename, strerror(errno)); ERR_print_errors(bio_err); /* If we have fp, then fdopen took over fd, so don't close both. */ - if (fp) + if (fp != NULL) fclose(fp); +#ifndef OPENSSL_NO_POSIX_IO else if (fd >= 0) close(fd); +#endif return NULL; } |