BIO_S_FD(3ossl)
π BIO_S_FD β the file descriptor BIO, bestie
okay so this is the <pink>OpenSSL</pink> manual page for BIO_s_fd, BIO_set_fd, BIO_get_fd and BIO_new_fd β collectively known as the <rainbow>file descriptor BIO</rainbow> β¨. Yeah. We're doing fd stuff today. Buckle up, it's giving low-level but make it cute π
β¨ NAME β¨
BIO_s_fd, BIO_set_fd, BIO_get_fd, BIO_new_fd β the <hotpink>file descriptor BIO</hotpink> π¦
πΈ 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);
like, that's the whole vibe check right there π
π DESCRIPTION π
BIO_s_fd() returns the <purple>file descriptor BIO method</purple>. Think of it as a lil wrapper round the platform's file descriptor routines β you know, the classics like read() and write(). It's giving "adapter pattern but make it C" π§
BIO_read_ex() and BIO_write_ex() read or write the underlying descriptor. BIO_puts() is <green>supported</green> but BIO_gets() is <red>NOT</red> π β yes, that's the whole tea, don't come for me.
If the <yellow>close flag</yellow> is set, then close() gets called on the underlying file descriptor when the BIO is freed. Important. Noted. Moving on π
BIO_reset() attempts to change the file pointer to the start of file β like, such as by using lseek(fd, 0, 0). Back to the beginning, periodt β
BIO_seek() sets the file pointer to position ofs from start of file, such as by using lseek(fd, ofs, 0). Pick a spot, any spot π
BIO_tell() returns the current file position, such as by calling lseek(fd, 0, 1). where u at bestie π«Ά
BIO_set_fd() sets the file descriptor of BIO b to fd and the close flag to c. Two for one, slay π
BIO_get_fd() places the file descriptor of BIO b in c if it is not NULL. It <hotpink>also returns</hotpink> the file descriptor. Double duty, main character energy π
BIO_new_fd() returns a file descriptor BIO using fd and close_flag. Brand new, freshly allocated, iconic π
π¦ NOTES π¦
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 <yellow>non blocking mode</yellow>, then the BIO will behave in the manner described in the BIO_read_ex(3) and BIO_should_retry(3) manual pages. iykyk π
File descriptor BIOs should NOT be used for socket I/O. Use socket BIOs instead. fr fr, don't do it, I'm begging π
Also heads up: BIO_set_fd() and BIO_get_fd() are implemented as <purple>macros</purple>. So like... don't try anything weird with function pointers, mmkay π
β RETURN VALUES β
BIO_s_fd()returns the file descriptor BIO method. predictable, we love her πBIO_set_fd()returns1on success or<=0for failure.BIO_get_fd()returns the file descriptor or-1if the BIO has not been initialized. It<peach>also</peach>returns zero and negative values if other error occurs.BIO_new_fd()returns the newly allocated BIO orNULLis an error occurred. π (yes that's the original wording, don't @ me)
π EXAMPLES π
okay this is literally the <rainbow>file descriptor BIO</rainbow> version of "Hello World" β the classic, the blueprint, the moment π
BIO *out;
out = BIO_new_fd(fileno(stdout), BIO_NOCLOSE);
BIO_printf(out, "Hello World\n");
BIO_free(out);
ate. no crumbs. π
π 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)
go read those too, they're all bangers π₯
π COPYRIGHT π
Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the <cyan>Apache License 2.0</cyan> (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, thanks for coming to my TED talk π«Ά <lavender>OpenSSL 3.5.6</lavender>, dated <lavender>2026-04-07</lavender> β from the BIO_S_FD(3ossl) girlies to you. mwah π β¨
π¦ where this page comes from
- freebsd 15.1: base 15.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms