1176771Sraj/* 2192532Sraj * Copyright (c) 2004, Bull SA. All rights reserved. 3176771Sraj * Created by: Laurent.Vivier@bull.net 4176771Sraj * This file is licensed under the GPL license. For the full content 5176771Sraj * of this license, see the COPYING file at the top level of this 6176771Sraj * source tree. 7176771Sraj */ 8176771Sraj 9176771Sraj/* 10176771Sraj * assertion: 11176771Sraj * 12176771Sraj * if aiobcp is NULL, all outstanding cancelable AIO against fildes 13176771Sraj * shall be canceled. 14176771Sraj * 15176771Sraj * method: 16176771Sraj * 17176771Sraj * open a file and queue a write to it with aio_write() 18176771Sraj * execute aio_cancel() on this file 19176771Sraj * check aio_cancel() is not -1 20176771Sraj * -> aio_cancel() works on fildes used with an aio command 21176771Sraj * 22176771Sraj * we have no way to assert we generate "cancelable" AIO and thus to check 23176771Sraj * if it has been really canceled 24176771Sraj * 25176771Sraj */ 26176771Sraj 27176771Sraj#define _XOPEN_SOURCE 600 28176771Sraj#include <stdio.h> 29176771Sraj#include <sys/types.h> 30176771Sraj#include <unistd.h> 31176771Sraj#include <sys/stat.h> 32176771Sraj#include <fcntl.h> 33176771Sraj#include <string.h> 34176771Sraj#include <errno.h> 35176771Sraj#include <stdlib.h> 36176771Sraj#include <aio.h> 37176771Sraj 38176771Sraj#include "posixtest.h" 39187151Sraj 40187151Sraj#define TNAME "aio_cancel/2-1.c" 41187151Sraj 42190701Smarcelint main() 43187151Sraj{ 44187151Sraj char tmpfname[256]; 45187151Sraj#define BUF_SIZE 1024 46187151Sraj char buf[BUF_SIZE]; 47187151Sraj int fd; 48187151Sraj struct aiocb aiocb; 49176771Sraj 50176771Sraj#if _POSIX_ASYNCHRONOUS_IO != 200112L 51176771Sraj return PTS_UNSUPPORTED; 52176771Sraj#endif 53176771Sraj 54176771Sraj snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_cancel_2_1_%d", 55176771Sraj getpid()); 56176771Sraj unlink(tmpfname); 57187149Sraj fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, 58176771Sraj S_IRUSR | S_IWUSR); 59176771Sraj if (fd == -1) 60176771Sraj { 61176771Sraj printf(TNAME " Error at open(): %s\n", 62176771Sraj strerror(errno)); 63224611Smarcel return PTS_UNRESOLVED; 64176771Sraj } 65176771Sraj 66176771Sraj unlink(tmpfname); 67222813Sattilio 68192532Sraj memset(buf, 0xaa, BUF_SIZE); 69176771Sraj memset(&aiocb, 0, sizeof(struct aiocb)); 70176771Sraj aiocb.aio_fildes = fd; 71176771Sraj aiocb.aio_buf = buf; 72176771Sraj aiocb.aio_nbytes = BUF_SIZE; 73176771Sraj 74176771Sraj if (aio_write(&aiocb) == -1) 75176771Sraj { 76176771Sraj printf(TNAME " Error at aio_write(): %s\n", 77176771Sraj strerror(errno)); 78176771Sraj return PTS_FAIL; 79176771Sraj } 80176771Sraj 81176771Sraj if (aio_cancel(fd, NULL) == -1) 82176771Sraj { 83176771Sraj printf(TNAME " Error at aio_cancel(): %s\n", 84192067Snwhitehorn strerror(errno)); 85176771Sraj return PTS_FAIL; 86176771Sraj } 87176771Sraj 88176771Sraj close(fd); 89176771Sraj printf ("Test PASSED\n"); 90176771Sraj return PTS_PASS; 91176771Sraj} 92176771Sraj