BIO *bio_open_owner(const char *filename, int format, int private)
{
    FILE *fp = NULL;
    BIO *b = NULL;
    int fd = -1, bflags, mode, binmode;
    if (!private || filename == NULL || strcmp(filename, "-") == 0)
        return bio_open_default(filename, 'w', format);
    mode = O_WRONLY;
#ifdef O_CREAT
    mode |= O_CREAT;
#endif
#ifdef O_TRUNC
    mode |= O_TRUNC;
#endif
    binmode = istext(format);
    if (binmode) {
#ifdef O_BINARY
        mode |= O_BINARY;
#elif defined(_O_BINARY)
        mode |= _O_BINARY;
#endif
    }
    fd = open(filename, mode, 0600);
    if (fd < 0)
        goto err;
    fp = fdopen(fd, modestr('w', format));
    if (fp == NULL)
        goto err;
    bflags = BIO_CLOSE;
    if (!binmode)
        bflags |= BIO_FP_TEXT;
    b = BIO_new_fp(fp, bflags);
    if (b)
        return b;
 err:
    BIO_printf(bio_err, "%s: Can't open \"%s\" for writing, %s\n",
               opt_getprog(), filename, strerror(errno));
    ERR_print_errors(bio_err);
    if (fp)
        fclose(fp);
    else if (fd >= 0)
        close(fd);
    return NULL;
}
['BIO *bio_open_owner(const char *filename, int format, int private)\n{\n    FILE *fp = NULL;\n    BIO *b = NULL;\n    int fd = -1, bflags, mode, binmode;\n    if (!private || filename == NULL || strcmp(filename, "-") == 0)\n        return bio_open_default(filename, \'w\', format);\n    mode = O_WRONLY;\n#ifdef O_CREAT\n    mode |= O_CREAT;\n#endif\n#ifdef O_TRUNC\n    mode |= O_TRUNC;\n#endif\n    binmode = istext(format);\n    if (binmode) {\n#ifdef O_BINARY\n        mode |= O_BINARY;\n#elif defined(_O_BINARY)\n        mode |= _O_BINARY;\n#endif\n    }\n    fd = open(filename, mode, 0600);\n    if (fd < 0)\n        goto err;\n    fp = fdopen(fd, modestr(\'w\', format));\n    if (fp == NULL)\n        goto err;\n    bflags = BIO_CLOSE;\n    if (!binmode)\n        bflags |= BIO_FP_TEXT;\n    b = BIO_new_fp(fp, bflags);\n    if (b)\n        return b;\n err:\n    BIO_printf(bio_err, "%s: Can\'t open \\"%s\\" for writing, %s\\n",\n               opt_getprog(), filename, strerror(errno));\n    ERR_print_errors(bio_err);\n    if (fp)\n        fclose(fp);\n    else if (fd >= 0)\n        close(fd);\n    return NULL;\n}', 'static int istext(int format)\n{\n    return (format & B_FORMAT_TEXT) == B_FORMAT_TEXT;\n}', 'static const char *modestr(char mode, int format)\n{\n    OPENSSL_assert(mode == \'a\' || mode == \'r\' || mode == \'w\');\n    switch (mode) {\n    case \'a\':\n        return istext(format) ? "a" : "ab";\n    case \'r\':\n        return istext(format) ? "r" : "rb";\n    case \'w\':\n        return istext(format) ? "w" : "wb";\n    }\n    return NULL;\n}']