aio_write(3)
β¨ aio_write(3) β the "write but make it async" icon β¨
okay bestie, so this is a page from the Library Functions Manual and it's about aio_write(3) β literally the async glow-up of write(2). iykyk. let's get into it π
πΈ LIBRARY πΈ
Real-time library β link it with -lrt if you want in on this. π«Ά
π¦ SYNOPSIS π¦
#include <aio.h>
int aio_write(struct aiocb *aiocbp);
π DESCRIPTION π
so what aio_write() does is it queues up the I/O request described by the buffer that aiocbp points to. it's fr fr the asynchronous analog of write(2) β same energy, just not blocking your whole vibe while it happens.
the args of a write(2) call like
write(fd, buf, count)
line up (in order π―) with the fields aio_fildes, aio_buf, and aio_nbytes of the struct that aiocbp points at. (if you're like "bestie what even is the aiocb structure", go read aio(7), it's got the whole rundown.)
okay now here's where the positioning tea gets spilled β :
- if
O_APPENDis not set, the data gets written starting at the absolute positionaiocbp->aio_offsetβ and it does NOT care about the file offset, periodt. - if
O_APPENDis set, the data goes to the end of the file, in the same order as theaio_write()calls were made. π
and after the call? the value of the file offset is unspecified. don't ask, it's giving mysterious. π
"The asynchronous" means this call returns as soon as the request has been enqueued β the write may or may not have actually completed by the time it comes back to you. shocking, i know. π
to check if it's done, you test it with aio_error(3). to get the return status of a completed I/O operation, use aio_return(3). and if you want the I/O completion to ping you, set aiocbp->aio_sigevent appropriately β the details live in sigevent(3type). π
If _POSIX_PRIORITIZED_IO is defined, and the file supports it, then the async operation gets submitted at a priority equal to that of the calling process minus aiocbp->aio_reqprio. math girlies rise π§
lowkey important: the field aiocbp->aio_lio_opcode is ignored. she said "not today." π
and no data is written to a regular file beyond its maximum offset. that's a hard boundary, bestie. π
π RETURN VALUE π
- on success β 0 is returned. slay. β¨
- on error β the request is not enqueued, -1 is returned, and
errnogets set to tell you what went wrong. - if an error only shows up later, it gets reported via
aio_return(3)(returns status -1) andaio_error(3)(error status β whatever you would have gotten inerrno, likeEBADF). so the drama comes in two acts, okay? π
π ERRORS π
EAGAINβ out of resources. the vibes are depleted. πEBADFβaio_fildesis not a valid file descriptor open for writing. she's not even allowed in here. π«EFBIGβ the file is a regular file, we want to write at least one byte, but the starting position is at or beyond the maximum offset for this file. too far, babes. πEINVALβ one or more ofaio_offset,aio_reqprio,aio_nbytesare invalid. nope nope nope. πENOSYSβaio_write()is not implemented. bestie... this function doesn't exist here. π
π ATTRIBUTES π
for the whole explanation of these terms, hit up attributes(7). here's the stat block, just not in table form because we're cute like that β¨:
aio_write()β Thread safety:MT-Safe
so yeah, threads can share it. icon behavior. π
β STANDARDS β
POSIX.1-2008. official, certified, iconic.
π¦ HISTORY π¦
- glibc 2.1
- POSIX.1-2001
she's been around. a true veteran. π€
π NOTES π
okay listen up, these are the rules of the house:
- it is a good idea to zero out the control block before use. do it. bestie please.
- the control block must not be changed while the write operation is in progress. hands off. π
- the buffer area being written out must not be accessed during the operation, or undefined results may occur. and we do NOT do undefined results in this household. π
- the memory areas involved must remain valid.
- simultaneous I/O operations specifying the same
aiocbstructure produce undefined results. sharing is not always caring, bestie. π
π₯ SEE ALSO π₯
aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3), aio_return(3), aio_suspend(3), lio_listio(3), aio(7)
okay that's the whole page, bestie!! π«Ά this was Linux man-pages 6.20, dated 2026-02-08, and the page you just read is aio_write(3). go queue some async writes and absolutely eat. mwah πβ¨ππ¦πΈ
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-2.0-or-later
- Copyright 2003, Andries E. Brouwer <aeb@cwi.nl>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms