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_return() shall return the status associated with aiocbp. 13 * 14 * method: 15 * 16 * - open a file 17 * - fill in an aiocb for writing 18 * - call aio_write using this aiocb 19 * - call aio_return to get the aiocb status (number of bytes written) 20 * 21 */ 22 23#define _XOPEN_SOURCE 600 24#include <stdio.h> 25#include <sys/types.h> 26#include <unistd.h> 27#include <sys/stat.h> 28#include <fcntl.h> 29#include <string.h> 30#include <errno.h> 31#include <stdlib.h> 32#include <aio.h> 33 34#include "posixtest.h" 35 36#define TNAME "aio_return/1-1.c" 37#define BUF_SIZE 111 38 39int main(void) 40{ 41 char tmpfname[256]; 42 char buf[BUF_SIZE]; 43 struct aiocb aiocb; 44 int fd, retval; 45 46 if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L) 47 return PTS_UNSUPPORTED; 48 49 snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_return_1_1_%d", 50 getpid()); 51 unlink(tmpfname); 52 fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); 53 54 if (fd == -1) { 55 printf(TNAME " Error at open(): %s\n", strerror(errno)); 56 return PTS_UNRESOLVED; 57 } 58 59 unlink(tmpfname); 60 61 memset(buf, 0xaa, BUF_SIZE); 62 memset(&aiocb, 0, sizeof(struct aiocb)); 63 aiocb.aio_fildes = fd; 64 aiocb.aio_buf = buf; 65 aiocb.aio_nbytes = BUF_SIZE; 66 67 if (aio_write(&aiocb) == -1) { 68 close(fd); 69 printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); 70 return PTS_FAIL; 71 } 72 73 do { 74 usleep(10000); 75 retval = aio_error(&aiocb); 76 } while (retval == EINPROGRESS); 77 78 retval = aio_return(&aiocb); 79 80 if (retval == -1) { 81 close(fd); 82 printf(TNAME " Error at aio_return(): %s\n", 83 strerror(aio_error(&aiocb))); 84 return PTS_FAIL; 85 } else if (retval != BUF_SIZE) { 86 close(fd); 87 printf(TNAME "aio_return didn't return expected size: %d\n", 88 retval); 89 return PTS_FAIL; 90 } 91 92 close(fd); 93 printf("Test PASSED\n"); 94 return PTS_PASS; 95} 96