BIO_S_FD(3ossl)
π BIO_S_FD β file descriptor BIO π
okay bestie, sit down, hydrate, and let me tell you about the file descriptor BIO from OpenSSL (yes, that OpenSSL, the one in the manual section 3ossl). this is the little glue layer that lets a BIO chat with a plain old file descriptor like it's a file. it's giving "wrapper class but make it C" and honestly? iconic. π
β¨ NAME β¨
BIO_s_fd, BIO_set_fd, BIO_get_fd, BIO_new_fd β file descriptor BIO π
β¨ SYNOPSIS β¨
#include <openssl/bio.h>
const BIO_METHOD *BIO_s_fd(void);
int BIO_set_fd(BIO *b, int fd, int c);
int BIO_get_fd(BIO *b, int *c);
BIO *BIO_new_fd(int fd, int close_flag);
β¨ DESCRIPTION β¨
so. BIO_s_fd() hands you the file descriptor BIO method. it's a wrapper round the platform's file descriptor routines β you know, the classics like read() and write(). π¦
BIO_read_ex() and BIO_write_ex() read or write the underlying descriptor. BIO_puts() is supported, but BIO_gets() is not β she simply does not do that. no cap. π
if the close flag is set, then close() gets called on the underlying file descriptor when the BIO is freed. so like, she cleans up after herself. periodt. π§Ήβ¨
BIO_reset()tries to change the file pointer to the start of file, such as by usinglseek(fd, 0, 0).BIO_seek()sets the file pointer to position ofs from start of file, such as by usinglseek(fd, ofs, 0).BIO_tell()returns the current file position, such as by callinglseek(fd, 0, 1).
then the setters and getters, our main characters:
BIO_set_fd()sets the file descriptor of BIObtofdand the close flag toc.BIO_get_fd()places the file descriptor of BIObincif it is notNULL. it also returns the file descriptor. double duty, she's booked and busy. πBIO_new_fd()returns a file descriptor BIO usingfdandclose_flag.
β¨ NOTES β¨
ngl this part matters. the behaviour of BIO_read_ex() and BIO_write_ex() depends on the behavior of the platform's read() and write() calls on the descriptor. so if the underlying file descriptor is in a non blocking mode, then the BIO will behave in the manner described in the BIO_read_ex(3) and BIO_should_retry(3) manual pages. go read those, bestie, i'm not summarising them for you. π
π¨ file descriptor BIOs should not be used for socket I/O. use socket BIOs instead. this is not a suggestion, this is a vibe check she will fail. π
also important, lowkey sneaky: BIO_set_fd() and BIO_get_fd() are implemented as macros. so don't be out here taking their address or whatever. π
β¨ RETURN VALUES β¨
BIO_s_fd()returns the file descriptor BIO method. π«ΆBIO_set_fd()returns1on success or<=0for failure.BIO_get_fd()returns the file descriptor, or-1if the BIO has not been initialized. it also returns zero and negative values if other error occurs. so like, read the room on those return values. πBIO_new_fd()returns the newly allocated BIO, orNULLis an error occurred. (yes, the grammar is hers, not mine. i am but a vessel. π)
β¨ EXAMPLES β¨
this is the file descriptor BIO version of "Hello World", and it absolutely ate:
BIO *out;
out = BIO_new_fd(fileno(stdout), BIO_NOCLOSE);
BIO_printf(out, "Hello World\n");
BIO_free(out);
look at her. four lines. no notes. πΈ
β¨ SEE ALSO β¨
BIO_seek(3), BIO_tell(3), BIO_reset(3), BIO_read_ex(3), BIO_write_ex(3), BIO_puts(3), BIO_gets(3), BIO_printf(3), BIO_set_close(3), BIO_get_close(3)
the whole friend group, fr fr. go say hi. π¦
β¨ COPYRIGHT β¨
Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
okay that's the whole page, bestie!! this was OpenSSL version 3.5.9, dated 2026-09-29, and you can find her filed under BIO_S_FD(3ossl). go forth and wrap those file descriptors responsibly. mwah. π
πβ¨
π¦ where this page comes from
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 43: openssl-devel 1:3.5.9-1.fc43 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- fedora 44: openssl-devel 1:3.5.9-1.fc44 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms