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 * The aio_read() function shall return the value zero if operation is 13 * successfuly queued. 14 * 15 * method: 16 * 17 * - write data to a file 18 * - read file using aio_read 19 * - check aio_read return value 20 */ 21 22#define _XOPEN_SOURCE 600 23#include <stdio.h> 24#include <sys/types.h> 25#include <unistd.h> 26#include <sys/stat.h> 27#include <fcntl.h> 28#include <string.h> 29#include <errno.h> 30#include <stdlib.h> 31#include <aio.h> 32 33#include "posixtest.h" 34 35#define TNAME "aio_read/7-1.c" 36 37int main(void) 38{ 39 char tmpfname[256]; 40#define BUF_SIZE 111 41 unsigned char check[BUF_SIZE]; 42 int fd; 43 int ret; 44 struct aiocb aiocb; 45 46 if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L) 47 return PTS_UNSUPPORTED; 48 49 snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_7_1_%d", 50 getpid()); 51 unlink(tmpfname); 52 fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); 53 if (fd == -1) { 54 printf(TNAME " Error at open(): %s\n", strerror(errno)); 55 exit(PTS_UNRESOLVED); 56 } 57 58 unlink(tmpfname); 59 60 memset(check, 0xaa, BUF_SIZE); 61 memset(&aiocb, 0, sizeof(struct aiocb)); 62 aiocb.aio_fildes = fd; 63 aiocb.aio_buf = check; 64 aiocb.aio_nbytes = BUF_SIZE; 65 66 if (aio_read(&aiocb) == -1) { 67 printf(TNAME " Error at aio_read(): %s\n", strerror(errno)); 68 exit(PTS_FAIL); 69 } 70 71 do { 72 usleep(10000); 73 ret = aio_error(&aiocb); 74 } while (ret == EINPROGRESS); 75 76 close(fd); 77 printf("Test PASSED\n"); 78 return PTS_PASS; 79} 80