diff options
author | Pauli <pauli@openssl.org> | 2021-07-14 11:02:57 +1000 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-07-14 09:17:45 +0200 |
commit | 2f0a53816b2956f585903a52ab6ab681cf6f9ae1 (patch) | |
tree | d3b7d87f421b929faa10682f6c71a77166b65b41 /apps/lib/apps.c | |
parent | 4e0383d8519373372c899380842adad7ef887e16 (diff) |
apps: avoid using POSIX IO macros and functions when built without them.
Fall back to stdio functions if not available.
Fixes a daily run-checker failure (no-posix-io)
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16073)
Diffstat (limited to 'apps/lib/apps.c')
-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; } |