BIO_S_FD(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… 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() returns 1 on success or <=0 for failure.
  • BIO_get_fd() returns the file descriptor or -1 if 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 or NULL is 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 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