blob: 4129dcd904f49e6e5ef7a5dd09dd54ebea0e93bc [file] [log] [blame]
robbiew0dc07652005-06-03 16:29:48 +00001/*
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
Garrett Cooper2c282152010-12-16 00:55:50 -08005 * of this license, see the COPYING file at the top level of this
robbiew0dc07652005-06-03 16:29:48 +00006 * 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/8-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
Garrett Cooper264074b2010-12-21 12:25:33 -080033 if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
Garrett Cooperec555782010-07-10 21:16:48 -070034 return PTS_UNSUPPORTED;
robbiew0dc07652005-06-03 16:29:48 +000035
Garrett Cooper2c282152010-12-16 00:55:50 -080036 snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_8_1_%d",
robbiew0dc07652005-06-03 16:29:48 +000037 getpid());
38 unlink(tmpfname);
39 fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL,
40 S_IRUSR | S_IWUSR);
Wanlong Gaoaa22e582012-07-24 14:44:02 +080041 if (fd == -1) {
robbiew0dc07652005-06-03 16:29:48 +000042 printf(TNAME " Error at open(): %s\n",
43 strerror(errno));
44 exit(PTS_UNRESOLVED);
45 }
46
47 unlink(tmpfname);
48
49 memset(&aiocb_write, 0, sizeof(aiocb_write));
50 aiocb_write.aio_fildes = fd;
51 aiocb_write.aio_buf = buf;
52 aiocb_write.aio_nbytes = BUF_SIZE;
53
Wanlong Gaoaa22e582012-07-24 14:44:02 +080054 if (aio_write(&aiocb_write) == -1) {
robbiew0dc07652005-06-03 16:29:48 +000055 printf(TNAME " Error at aio_write(): %s\n",
56 strerror(errno));
57 exit(PTS_FAIL);
58 }
59
60 memset(&aiocb_fsync, 0, sizeof(aiocb_fsync));
61 aiocb_fsync.aio_fildes = fd;
62 aiocb_fsync.aio_nbytes = -1;
63
Wanlong Gaoaa22e582012-07-24 14:44:02 +080064 if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) {
robbiew0dc07652005-06-03 16:29:48 +000065 printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno));
66 exit(PTS_FAIL);
67 }
68
69 close(fd);
Wanlong Gaoaa22e582012-07-24 14:44:02 +080070 printf("Test PASSED\n");
robbiew0dc07652005-06-03 16:29:48 +000071 return PTS_PASS;
Wanlong Gaoaa22e582012-07-24 14:44:02 +080072}