1/*
2 * Copyright (c) 2004, Bull SA. All rights reserved.
3 * Created by:  Laurent.Vivier@bull.net
4 * This file is licensed under the GPL license.  For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7 */
8
9/*
10 * assertion:
11 *
12 *	The aio_error() function shall return the error status (errno)
13 *	associated with tha aiobcp argument.
14 *
15 * method:
16 *
17 *	execute aio_write()
18 *	and check result with aio_error()
19 *
20 */
21
22#define _XOPEN_SOURCE 600
23#include <stdio.h>
24#include <sys/types.h>
25#include <unistd.h>
26#include <sys/stat.h>
27#include <fcntl.h>
28#include <string.h>
29#include <errno.h>
30#include <stdlib.h>
31#include <aio.h>
32
33#include "posixtest.h"
34
35#define TNAME "aio_error/1-1.c"
36
37int main()
38{
39	char tmpfname[256];
40#define BUF_SIZE 111
41	char buf[BUF_SIZE];
42	int fd;
43	struct aiocb aiocb;
44
45#if _POSIX_ASYNCHRONOUS_IO != 200112L
46	return PTS_UNSUPPORTED;
47#endif
48
49	snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_error_1_1_%d",
50		  getpid());
51	unlink(tmpfname);
52	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
53		  S_IRUSR | S_IWUSR);
54	if (fd == -1)
55	{
56		printf(TNAME " Error at open(): %s\n",
57		       strerror(errno));
58		return PTS_UNRESOLVED;
59	}
60
61	unlink(tmpfname);
62
63	memset(buf, 0xaa, BUF_SIZE);
64	memset(&aiocb, 0, sizeof(struct aiocb));
65	aiocb.aio_fildes = fd;
66	aiocb.aio_buf = buf;
67	aiocb.aio_nbytes = BUF_SIZE;
68
69	if (aio_write(&aiocb) == -1)
70	{
71		printf(TNAME " Error at aio_write(): %s\n",
72		       strerror(errno));
73		return PTS_FAIL;
74	}
75
76	while(aio_error(&aiocb) == EINPROGRESS);
77
78	if (aio_error(&aiocb) != 0)
79	{
80		printf(TNAME " Error at aio_error(): %s\n",
81		       strerror(errno));
82		return PTS_FAIL;
83	}
84
85	close(fd);
86	printf ("Test PASSED\n");
87	return PTS_PASS;
88}
89