robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 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 |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 5 | * of this license, see the COPYING file at the top level of this |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 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/8-1.c" |
| 23 | |
| 24 | int 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 Cooper | ec55578 | 2010-07-10 21:16:48 -0700 | [diff] [blame] | 33 | if (sysconf(_SC_ASYNCHRONOUS_IO) != 200112L) |
| 34 | return PTS_UNSUPPORTED; |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 35 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 36 | snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_8_1_%d", |
robbiew | 0dc0765 | 2005-06-03 16:29:48 +0000 | [diff] [blame] | 37 | getpid()); |
| 38 | unlink(tmpfname); |
| 39 | fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, |
| 40 | S_IRUSR | S_IWUSR); |
| 41 | if (fd == -1) |
| 42 | { |
| 43 | printf(TNAME " Error at open(): %s\n", |
| 44 | strerror(errno)); |
| 45 | exit(PTS_UNRESOLVED); |
| 46 | } |
| 47 | |
| 48 | unlink(tmpfname); |
| 49 | |
| 50 | memset(&aiocb_write, 0, sizeof(aiocb_write)); |
| 51 | aiocb_write.aio_fildes = fd; |
| 52 | aiocb_write.aio_buf = buf; |
| 53 | aiocb_write.aio_nbytes = BUF_SIZE; |
| 54 | |
| 55 | if (aio_write(&aiocb_write) == -1) |
| 56 | { |
| 57 | printf(TNAME " Error at aio_write(): %s\n", |
| 58 | strerror(errno)); |
| 59 | exit(PTS_FAIL); |
| 60 | } |
| 61 | |
| 62 | memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); |
| 63 | aiocb_fsync.aio_fildes = fd; |
| 64 | aiocb_fsync.aio_nbytes = -1; |
| 65 | |
| 66 | if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) |
| 67 | { |
| 68 | printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); |
| 69 | exit(PTS_FAIL); |
| 70 | } |
| 71 | |
| 72 | close(fd); |
| 73 | printf ("Test PASSED\n"); |
| 74 | return PTS_PASS; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame^] | 75 | } |