source: rtems/cpukit/posix/src/aio_write.c @ 77fbbd6

5
Last change on this file since 77fbbd6 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Function queues I/O request described by buffer pointed by aiocb
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.org/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_write
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 be 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_write (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_WRONLY) || ((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_WRITE;
69
70  return rtems_aio_enqueue (req);
71}
Note: See TracBrowser for help on using the repository browser.