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 *	if aiobcp is NULL, all outstanding cancelable AIO against fildes
13 *	shall be canceled.
14 *
15 * method:
16 *
17 *	open a file
18 *	execute aio_cancel() on this file
19 *	check aio_cancel() is not -1
20 *	-> aio_cancel() works on standard fildes
21 *
22 */
23
24#define _XOPEN_SOURCE 600
25#include <stdio.h>
26#include <sys/types.h>
27#include <unistd.h>
28#include <sys/stat.h>
29#include <fcntl.h>
30#include <string.h>
31#include <errno.h>
32#include <stdlib.h>
33#include <aio.h>
34
35#include "posixtest.h"
36
37#define TNAME "aio_cancel/2-2.c"
38
39int main()
40{
41	char tmpfname[256];
42	int fd;
43
44#if _POSIX_ASYNCHRONOUS_IO != 200112L
45	return PTS_UNSUPPORTED;
46#endif
47
48	snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_2_2_%d",
49		  getpid());
50	unlink(tmpfname);
51	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
52		  S_IRUSR | S_IWUSR);
53	if (fd == -1)
54	{
55		printf(TNAME " Error at open(): %s\n",
56		       strerror(errno));
57		return PTS_UNRESOLVED;
58	}
59
60	unlink(tmpfname);
61
62	if (aio_cancel(fd, NULL) == -1)
63	{
64		printf(TNAME " Error at aio_cancel(): %s\n",
65		       strerror(errno));
66		return PTS_FAIL;
67	}
68
69	close(fd);
70	printf ("Test PASSED\n");
71	return PTS_PASS;
72}
73