source: rtems/cpukit/rtems/src/statustoerrno.c

Last change on this file was b3b6d21e, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 22:28:59

cpukit/rtems/src/[s-z]*.c: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSImplClassic
7 *
8 * @brief This source file contains the implementation of
9 *   rtems_status_code_to_errno().
10 */
11
12/*  COPYRIGHT (c) 1989-2013.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include <rtems/rtems/statusimpl.h>
38#include <errno.h>
39
40static const int status_code_to_errno [RTEMS_STATUS_CODES_LAST + 1] = {
41  [RTEMS_SUCCESSFUL]               = 0,
42  [RTEMS_TASK_EXITTED]             = EIO,
43  [RTEMS_MP_NOT_CONFIGURED]        = EIO,
44  [RTEMS_INVALID_NAME]             = EINVAL,
45  [RTEMS_INVALID_ID]               = EIO,
46  [RTEMS_TOO_MANY]                 = EIO,
47  [RTEMS_TIMEOUT]                  = ETIMEDOUT,
48  [RTEMS_OBJECT_WAS_DELETED]       = EIO,
49  [RTEMS_INVALID_SIZE]             = EIO,
50  [RTEMS_INVALID_ADDRESS]          = EIO,
51  [RTEMS_INVALID_NUMBER]           = EBADF,
52  [RTEMS_NOT_DEFINED]              = EIO,
53  [RTEMS_RESOURCE_IN_USE]          = EBUSY,
54  [RTEMS_UNSATISFIED]              = ENODEV,
55  [RTEMS_INCORRECT_STATE]          = EIO,
56  [RTEMS_ALREADY_SUSPENDED]        = EIO,
57  [RTEMS_ILLEGAL_ON_SELF]          = EIO,
58  [RTEMS_ILLEGAL_ON_REMOTE_OBJECT] = EIO,
59  [RTEMS_CALLED_FROM_ISR]          = EIO,
60  [RTEMS_INVALID_PRIORITY]         = EIO,
61  [RTEMS_INVALID_CLOCK]            = EINVAL,
62  [RTEMS_INVALID_NODE]             = EINVAL,
63  [RTEMS_NOT_CONFIGURED]           = ENOSYS,
64  [RTEMS_NOT_OWNER_OF_RESOURCE]    = EPERM,
65  [RTEMS_NOT_IMPLEMENTED]          = ENOSYS,
66  [RTEMS_INTERNAL_ERROR]           = EIO,
67  [RTEMS_NO_MEMORY]                = ENOMEM,
68  [RTEMS_IO_ERROR]                 = EIO,
69  [RTEMS_INTERRUPTED]              = EINTR,
70  [RTEMS_PROXY_BLOCKING]           = EIO
71};
72
73int rtems_status_code_to_errno(rtems_status_code sc)
74{
75  if (sc == RTEMS_SUCCESSFUL) {
76    return 0;
77  } else {
78    int eno = EINVAL;
79
80    if ((unsigned) sc <= RTEMS_STATUS_CODES_LAST) {
81      eno = status_code_to_errno [sc];
82    }
83
84    errno = eno;
85
86    return -1;
87  }
88}
Note: See TracBrowser for help on using the repository browser.