1156230Smux/*
2156230Smux * Copyright (c) 2004, Bull SA. All rights reserved.
3156230Smux * Created by:  Laurent.Vivier@bull.net
4156230Smux * This file is licensed under the GPL license.  For the full content
5156230Smux * of this license, see the COPYING file at the top level of this
6156230Smux * source tree.
7156230Smux */
8156230Smux
9156230Smux#define _XOPEN_SOURCE 600
10156230Smux#include <stdio.h>
11156230Smux#include <sys/types.h>
12156230Smux#include <unistd.h>
13156230Smux#include <sys/stat.h>
14156230Smux#include <fcntl.h>
15156230Smux#include <string.h>
16156230Smux#include <errno.h>
17156230Smux#include <stdlib.h>
18156230Smux#include <aio.h>
19156230Smux
20156230Smux#include "posixtest.h"
21156230Smux
22156230Smux#define TNAME "aio_fsync/4-1.c"
23156230Smux
24156230Smuxint main()
25156230Smux{
26156230Smux	char tmpfname[256];
27156230Smux#define BUF_SIZE 111
28156230Smux	char buf[BUF_SIZE];
29156230Smux	int fd;
30156230Smux	struct aiocb aiocb_write;
31156230Smux	struct aiocb aiocb_fsync;
32156230Smux
33156230Smux#if _POSIX_ASYNCHRONOUS_IO != 200112L
34156230Smux	exit(PTS_UNSUPPORTED);
35156230Smux#endif
36156701Smux
37156230Smux	snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_4_1_%d",
38156230Smux		  getpid());
39156230Smux	unlink(tmpfname);
40156230Smux	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
41156230Smux		  S_IRUSR | S_IWUSR);
42156230Smux	if (fd == -1)
43156230Smux	{
44156230Smux		printf(TNAME " Error at open(): %s\n",
45156230Smux		       strerror(errno));
46156230Smux		exit(PTS_UNRESOLVED);
47156230Smux	}
48156230Smux
49156230Smux	unlink(tmpfname);
50156230Smux
51156230Smux	memset(&aiocb_write, 0, sizeof(aiocb_write));
52156230Smux	aiocb_write.aio_fildes = fd;
53156230Smux	aiocb_write.aio_buf = buf;
54156230Smux	aiocb_write.aio_nbytes = BUF_SIZE;
55156230Smux
56156230Smux	if (aio_write(&aiocb_write) == -1)
57156230Smux	{
58156230Smux		printf(TNAME " Error at aio_write(): %s\n",
59156230Smux		       strerror(errno));
60156230Smux		exit(PTS_FAIL);
61156230Smux	}
62156230Smux
63156230Smux	memset(&aiocb_fsync, 0, sizeof(aiocb_fsync));
64156230Smux	aiocb_fsync.aio_fildes = fd;
65156230Smux
66156230Smux	if (aio_fsync(O_SYNC, &aiocb_fsync) != 0)
67156701Smux	{
68156701Smux		printf(TNAME " Error at aio_fsync()\n");
69156701Smux		exit(PTS_FAIL);
70156701Smux	}
71156701Smux
72156701Smux	if (aio_error(&aiocb_fsync) < 0)
73156701Smux	{
74156701Smux		printf(TNAME " Error at aio_error() : %s\n", strerror(errno));
75156701Smux		exit(PTS_FAIL);
76156701Smux	}
77156701Smux
78156701Smux	close(fd);
79156701Smux	printf ("Test PASSED\n");
80156701Smux	return PTS_PASS;
81156701Smux}
82156701Smux