vrb_write(3)

πŸ“¦ version 0.5.1, in nixos 26.05

πŸ’… vrb_write(3) β€” writing data out of a VRB, bestie edition

okay so real talk, this one lives in the VRB Programmer's Manual and honestly it's kind of a vibe. You've got a virtual ring buffer stuffed with data, you've got an open file descriptor, and you want the first one to pour into the second one. That's the whole plot. Let's get into it 🫢

πŸ“š LIBRARY

Link against -lvrb and you're golden ✨

✨ SYNOPSIS ✨

#include <vrb.h>

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

🌸 DESCRIPTION 🌸

vrb_write takes data and writes it out to an open file descriptor you specify, using write(2), pulling from the virtual ring buffer you point it at. It keeps going until one of these happens:

  • the maximum length you asked for has been written πŸ’–
  • the buffer is full (nothing more to give) πŸŽ€
  • an error gets returned β€” and yes, that includes EAGAIN or EWOULDBLOCK when you're dealing with a non-blocking descriptor, so keep that in mind ngl πŸ’€

🌈 ARGUMENTS 🌈

  • vrb_p vrb β€” which virtual ring buffer we're working with, like, the actual source of the data πŸ’…
  • int fd β€” the open file descriptor to write to, the destination, the moment πŸ¦‹
  • size_t size β€” the maximum length to write, OR pass ~0 for unlimited (which means all of the buffer, go off πŸ‘‘)

⭐ RETURN VALUE ⭐

The type is size_t, and here's how it goes:

  • if it works, you get back the actual length of data written out of the buffer βœ…
  • if there was literally no data available to write, you get 0 β€” not an error, just an empty vibe check πŸ™ˆ
  • if write(2) itself errors out, the return value is ~0 and errno gets set by write(2) β€” so like, the error is coming from the write call, not from this function's own drama 😭

πŸ’€ ERRORS πŸ’€

If an error comes back, errno is gonna be one of these:

  • 0 β€” an end-of-file has occurred. And lowkey pay attention here: this is a different way of returning an end-of-file condition than write(2) uses. Not me warning you, that's just the docs fr fr πŸ’€
  • EINVAL β€” you handed over an invalid virtual ring buffer pointer. Rude, but fair 🌸
bestie fr fr double-check your pointer before you call this, EINVAL is literally sitting right there waiting

🧚 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(3), vrb_read_min(3), vrb_resize(3), vrb_space_len(3), vrb_space_ptr(3), vrb_take(3), vrb_uninit(3), vrb_write_min(3), write(2)


and that's the whole page, periodt πŸ’œ this little icon dropped under the vrb name and it's dated 2002-09-30 β€” vintage, honestly iconic, no cap πŸŽ€βœ¨

πŸ“¦ where this page comes from