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 * aio_cancel() shall return AIO_ALLDONE if all operation have already 13 * completed 14 * 15 * method: 16 * 17 * execute one aio_write(), wait it is finished 18 * execute aio_cancel 19 * if result is AIO_ALLDONE, test is passed 20 * otherwise it is failed 21 * 22 */ 23 24#define _XOPEN_SOURCE 600 25#include <stdio.h> 26#include <sys/types.h> 27#include <unistd.h> 28#include <sys/stat.h> 29#include <fcntl.h> 30#include <string.h> 31#include <errno.h> 32#include <stdlib.h> 33#include <aio.h> 34 35#include "posixtest.h" 36 37#define TNAME "aio_cancel/8-1.c" 38 39int main() 40{ 41 char tmpfname[256]; 42#define BUF_SIZE 1024 43 char buf[BUF_SIZE]; 44 int fd; 45 struct aiocb aiocb; 46 47#if _POSIX_ASYNCHRONOUS_IO != 200112L 48 return PTS_UNSUPPORTED; 49#endif 50 51 snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_1_1_%d", 52 getpid()); 53 unlink(tmpfname); 54 fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, 55 S_IRUSR | S_IWUSR); 56 if (fd == -1) 57 { 58 printf(TNAME " Error at open(): %s\n", 59 strerror(errno)); 60 return PTS_UNRESOLVED; 61 } 62 63 unlink(tmpfname); 64 65 memset(buf, 0xaa, BUF_SIZE); 66 memset(&aiocb, 0, sizeof(struct aiocb)); 67 aiocb.aio_fildes = fd; 68 aiocb.aio_buf = buf; 69 aiocb.aio_nbytes = BUF_SIZE; 70 71 if (aio_write(&aiocb) == -1) 72 { 73 printf(TNAME " Error at aio_write(): %s\n", 74 strerror(errno)); 75 return PTS_FAIL; 76 } 77 78 while (aio_error(&aiocb) == EINPROGRESS); 79 80 if (aio_cancel(fd, &aiocb) != AIO_ALLDONE) 81 { 82 printf(TNAME " Error at aio_cancel(): %s\n", 83 strerror(errno)); 84 return PTS_FAIL; 85 } 86 87 close(fd); 88 printf ("Test PASSED\n"); 89 return PTS_PASS; 90} 91