source: rtems/cpukit/posix/src/aio_read.c @ be1b8a7

4.115
Last change on this file since be1b8a7 was a1b47528, checked in by Sebastian Huber <sebastian.huber@…>, on 07/18/13 at 12:13:24

posix: Include missing header files

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Asynchronously reads Data from a File
5 * @ingroup POSIXAPI
6 */
7
8/*
9 * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com>
10 *
11 * The license and distribution terms for this file may be
12 * found in the file LICENSE in this distribution or at
13 * http://www.rtems.com/license/LICENSE.
14 */
15
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <aio.h>
22#include <errno.h>
23#include <fcntl.h>
24#include <rtems/posix/aio_misc.h>
25#include <rtems/system.h>
26#include <rtems/seterr.h>
27#include <stdlib.h>
28#include <limits.h>
29
30/*
31 *  aio_read
32 *
33 * Asynchronous write to a file
34 *
35 *  Input parameters:
36 *        aiocbp - asynchronous I/O control block
37 *
38 *  Output parameters:
39 *        -1 - request could not pe enqueued
40 *           - FD not opened for write
41 *           - invalid aio_reqprio or aio_offset or
42 *             aio_nbytes
43 *           - not enough memory
44 *         0 - otherwise
45 */
46
47int
48aio_read (struct aiocb *aiocbp)
49{
50  rtems_aio_request *req;
51  int mode;
52
53  mode = fcntl (aiocbp->aio_fildes, F_GETFL);
54  if (!(((mode & O_ACCMODE) == O_RDONLY) || ((mode & O_ACCMODE) == O_RDWR)))
55    rtems_aio_set_errno_return_minus_one (EBADF, aiocbp);
56 
57  if (aiocbp->aio_reqprio < 0 || aiocbp->aio_reqprio > AIO_PRIO_DELTA_MAX)
58    rtems_aio_set_errno_return_minus_one (EINVAL, aiocbp);
59 
60  if (aiocbp->aio_offset < 0)
61    rtems_aio_set_errno_return_minus_one (EINVAL, aiocbp);
62
63  req = malloc (sizeof (rtems_aio_request));
64  if (req == NULL)
65    rtems_aio_set_errno_return_minus_one (EAGAIN, aiocbp);
66
67  req->aiocbp = aiocbp;
68  req->aiocbp->aio_lio_opcode = LIO_READ;
69
70  return rtems_aio_enqueue (req);
71}
Note: See TracBrowser for help on using the repository browser.