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#define _XOPEN_SOURCE 600
10#include <stdio.h>
11#include <sys/types.h>
12#include <unistd.h>
13#include <sys/stat.h>
14#include <fcntl.h>
15#include <string.h>
16#include <errno.h>
17#include <stdlib.h>
18#include <aio.h>
19
20#include "posixtest.h"
21
22#define TNAME "aio_fsync/14-1.c"
23
24int main()
25{
26	char tmpfname[256];
27#define BUF_SIZE 111
28	char buf[BUF_SIZE];
29	int fd;
30	struct aiocb aiocb_write;
31	struct aiocb aiocb_fsync;
32
33#if _POSIX_ASYNCHRONOUS_IO != 200112L
34	exit(PTS_UNSUPPORTED);
35#endif
36
37	snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_14_1_%d",
38		  getpid());
39	unlink(tmpfname);
40	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
41		  S_IRUSR | S_IWUSR);
42	if (fd == -1)
43	{
44		printf(TNAME " Error at open(): %s\n",
45		       strerror(errno));
46		exit(PTS_UNRESOLVED);
47	}
48
49	unlink(tmpfname);
50
51	memset(&aiocb_write, 0, sizeof(aiocb_write));
52	aiocb_write.aio_fildes = fd;
53	aiocb_write.aio_buf = buf;
54	aiocb_write.aio_nbytes = BUF_SIZE;
55
56	if (aio_write(&aiocb_write) == -1)
57	{
58		printf(TNAME " Error at aio_write(): %s\n",
59		       strerror(errno));
60		exit(PTS_FAIL);
61	}
62
63	memset(&aiocb_fsync, 0, sizeof(aiocb_fsync));
64	aiocb_fsync.aio_fildes = fd;
65
66	if (aio_fsync(-1, &aiocb_fsync) != -1)
67	{
68		printf(TNAME " aio_fsync() accepts bad op\n");
69		exit(PTS_FAIL);
70	}
71
72	if (errno != EINVAL)
73	{
74		printf(TNAME " errno is not EINVAL (%d)\n", errno);
75		exit(PTS_FAIL);
76	}
77
78	close(fd);
79	printf ("Test PASSED\n");
80	return PTS_PASS;
81}
82