#include #include #include #include void aio_test(int fd, char * str) { struct aiocb *iocb; int rval; iocb = calloc(1, sizeof(struct aiocb)); iocb->aio_fildes = fd; iocb->aio_offset = 0; iocb->aio_buf = (void *) malloc(strlen(str)); memcpy((void *)iocb->aio_buf, str, strlen(str)); iocb->aio_nbytes = strlen(str); iocb->aio_sigevent.sigev_notify = SIGEV_NONE; rval = aio_write(iocb); if (rval < 0) perror("aio_write"); } int main(void) { int fd; int oflags; fd = open("/tmp/aio.test", O_WRONLY | O_APPEND | O_CREAT, 0644); if(fd < 0) { perror("open"); exit(1); } if ((oflags = fcntl(fd, F_GETFL, 0)) < 0) { perror("fcntl"); exit(1); } if (!(oflags & O_APPEND)) { printf("O_APPEND is not set\n"); exit(1); } aio_test(fd, "1\n"); aio_test(fd, "2\n"); aio_test(fd, "3\n"); aio_test(fd, "4\n"); aio_test(fd, "5\n"); close(fd); }