source: rtems/cpukit/libcsupport/src/posix_devctl.c @ 80cf60e

5
Last change on this file since 80cf60e was 80cf60e, checked in by Sebastian Huber <sebastian.huber@…>, on 04/15/20 at 07:48:32

Canonicalize config.h include

Use the following variant which was already used by most source files:

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 2016, 2020 Joel Sherrill <joel@rtems.org>.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#ifdef HAVE_CONFIG_H
28#include "config.h"
29#endif
30
31#define _POSIX_26_C_SOURCE
32
33#include <devctl.h>
34#include <sys/ioctl.h>
35#include <rtems/seterr.h>
36
37#include  <unistd.h>
38
39int posix_devctl(
40  int              fd,
41  int              dcmd,
42  void *__restrict dev_data_ptr,
43  size_t           nbyte,
44  int *__restrict  dev_info_ptr
45)
46{
47  /*
48   * The POSIX 1003.26 standard allows for library implementations
49   * that implement posix_devctl() using ioctl(). In this case,
50   * the extra parameters are largely ignored.
51   *
52   * The FACE Technical Standard requires only that FIONBIO
53   * be supported for sockets.
54   *
55   * This method appears to be rarely implemented and there are
56   * no known required use cases for this method beyond those
57   * from the FACE Technical Standard.
58   */
59
60  /*
61   * POSIX 1003.26 mentions that nbyte must be non-negative but this
62   * doesn't make sense because size_t is guaranteed to be unsigned.
63   */
64
65  /*
66   * Since this is implemented on top of ioctl(), the device information
67   * is not going to be passed down. Fill it in with zero so the behavior
68   * is defined.
69   */
70  if (dev_info_ptr != NULL) {
71    *dev_info_ptr = 0;
72  }
73
74  /*
75   * The FACE Technical Standard Edition 3.0 and newer requires the SOCKCLOSE
76   * ioctl command. This is because the Security Profile does not include
77   * close() and applications need a way to close sockets. Closing sockets is
78   * a minimum requirement so using close() in the implementation meets that
79   * requirement but also lets the application close other file types.
80   */
81  if (dcmd == SOCKCLOSE ) {
82    return close(fd);
83  }
84
85  return ioctl(fd, dcmd, dev_data_ptr);
86}
Note: See TracBrowser for help on using the repository browser.