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)
@@ -2962,11 +2962,16 @@ 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
mode |= O_CREAT;
@@ -2974,7 +2979,6 @@ BIO *bio_open_owner(const char *filename, int format, int private)
# ifdef O_TRUNC
mode |= O_TRUNC;
# endif
- textmode = FMT_istext(format);
if (!textmode) {
# ifdef O_BINARY
mode |= O_BINARY;
@@ -2997,13 +3001,17 @@ BIO *bio_open_owner(const char *filename, int format, int private)
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;
}
