vrb_read(3)

πŸ“¦ version 0.5.1, in nixos 26.05

✨ vrb_read(3) β€” the VRB Programmer's Manual, section 3, bestie ✨

okay so real talk, this one is from the VRB Programmer's Manual and it's genuinely one of my faves because it does exactly one thing and it does it slayfully πŸ’…


🌸 NAME 🌸

vrb_read β€” read data into a VRB. that's it. that's the whole job. iconic.


πŸŽ€ LIBRARY πŸŽ€

-lvrb

(link against it or you get nothing, fr fr πŸ”₯)


✨ SYNOPSIS ✨

#include <vrb.h>

size_t vrb_read(vrb_p vrb, int fd, size_t size);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the vibe: vrb_read reads data from a specified open file descriptor β€” using read(2) under the hood, ngl β€” straight into the specified virtual ring buffer. πŸ’«

and it keeps going until any of these happen:

  • the specified maximum length has been read,
  • the buffer is full,
  • end-of-file hits,
  • or an error comes back (and yes, that includes EAGAIN or EWOULDBLOCK if your descriptor is non-blocking πŸ‘€).

🌈 ARGUMENTS 🌈

  • vrb_p vrb β€” specifies which virtual ring buffer. like, which one. this one. the one you mean. 🫢
  • int fd β€” specifies the open file descriptor to read from πŸ”₯
  • size_t size β€” specifies the maximum length to read, or ~0 for unlimited. go big or go home, yk? πŸ’œ

πŸ‘‘ RETURN VALUE πŸ‘‘

returns size_t.

  • if it's successful, you get the actual length of data read into the buffer back. slay. ✨
  • if end-of-file occurs, the return value is ~0 and errno is 0.
  • if an error occurs from read(2), the return value is ~0 and errno is set by read(2).
⚠️ bestie please note: this is a different way of returning an end-of-file condition than read(2) uses. that's not a bug, that's just the house style. don't come for me 😭

πŸ’€ ERRORS πŸ’€

if an error is returned, then errno will have one of these values:

  • 0 β€” an end-of-file has occurred. and again, note that this is a different way of returning an end-of-file condition than read(2) uses. i said what i said πŸ™ˆ
  • EINVAL β€” an invalid virtual ring buffer pointer was specified. you handed it a fake vrb, it's not gonna pretend to like it πŸ’…

🧚 SEE ALSO 🧚

vrb(3), vrb_capacity(3), vrb_data_len(3), vrb_data_ptr(3), vrb_destroy(3), vrb_get(3), vrb_get_min(3), vrb_give(3), vrb_init(3), vrb_init_opt(3), vrb_is_empty(3), vrb_is_full(3), vrb_is_not_empty(3), vrb_is_not_full(3), vrb_move(3), vrb_new(3), vrb_new_opt(3), vrb_put(3), vrb_put_all(3), vrb_read_min(3), vrb_resize(3), vrb_space_len(3), vrb_space_ptr(3), vrb_take(3), vrb_uninit(3), vrb_write(3), vrb_write_min(3), read(2)

(the whole friend group, basically 🫢 go say hi)


and that's the page!! πŸŽ€ authored under vrb, dated 2002-09-30, from the VRB Programmer's Manual β€” vintage but still eating, no cap πŸ“βœ¨

πŸ“¦ where this page comes from