Home | History | Annotate | Download | only in aio_write
      1 /*
      2  * Copyright (c) 2004, Bull SA. All rights reserved.
      3  * Created by:  Laurent.Vivier (at) 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_write() shall fail or the error status of the operation shall be [EBADF] if:
     13  *	aio_fildes argument is not a valid file descriptor open for writing.
     14  *
     15  * method: Test with an invalid file descriptor (-1)
     16  *
     17  *	- setup an aiocb with an invalid aio_fildes
     18  *	- call aio_write with this aiocb
     19  *	- check return code and errno
     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_write/8-1.c"
     37 
     38 int main(void)
     39 {
     40 #define BUF_SIZE 512
     41 	char buf[BUF_SIZE];
     42 	struct aiocb aiocb;
     43 	int ret = 0;
     44 
     45 	if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L)
     46 		return PTS_UNSUPPORTED;
     47 
     48 	memset(buf, 0xaa, BUF_SIZE);
     49 	memset(&aiocb, 0, sizeof(struct aiocb));
     50 	aiocb.aio_fildes = -1;
     51 	aiocb.aio_buf = buf;
     52 	aiocb.aio_nbytes = BUF_SIZE;
     53 
     54 	/*
     55 	 * EBADF is encountered at a later stage
     56 	 * and should be collected by aio_error()
     57 	 */
     58 
     59 	if (aio_write(&aiocb) != 0) {
     60 		printf(TNAME " bad aio_write return value()\n");
     61 		exit(PTS_FAIL);
     62 	}
     63 
     64 	do {
     65 		usleep(10000);
     66 		ret = aio_error(&aiocb);
     67 	} while (ret == EINPROGRESS);
     68 
     69 	if (ret != EBADF) {
     70 		printf(TNAME " errno is not EBADF %s\n", strerror(errno));
     71 		exit(PTS_FAIL);
     72 	}
     73 
     74 	printf("Test PASSED\n");
     75 	return PTS_PASS;
     76 }
     77