summaryrefslogtreecommitdiff
path: root/lib/libc/aio/aio_error.c
blob: 9f7d05ca15b28bd387ef6eda681c914f225d2b94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "aio.h" // for aio_error, aiocb (ptr only)

#include <__aio.h>  // for aio_request, __aio_lookup, AIO_REQUEST_STATUS_PE...
#include <errno.h>  // for EINVAL, errno, EINPROGRESS
#include <stddef.h> // for NULL

int aio_error(const struct aiocb *aiocbp)
{
	struct aio_request *req;

	if (aiocbp == NULL) {
		errno = EINVAL;
		return -1;
	}

	req = __aio_lookup(aiocbp);

	if (req == NULL) {
		errno = EINVAL;
		return -1;
	}

	if (req->status == AIO_REQUEST_STATUS_PENDING) {
		return EINPROGRESS;
	}

	return req->result < 0 ? -req->result : 0;
}