1 /*
2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "los_mux.h"
32 #include "los_queue.h"
33 #include "los_sem.h"
34 #include "los_task.h"
35 #include <errno.h>
36
map_errno(UINT32 err)37 INT32 map_errno(UINT32 err)
38 {
39 if (err == LOS_OK) {
40 return 0;
41 }
42 switch (err) {
43 case LOS_ERRNO_QUEUE_INVALID:
44 case LOS_ERRNO_QUEUE_WRITE_PTR_NULL:
45 case LOS_ERRNO_QUEUE_WRITESIZE_ISZERO:
46 case LOS_ERRNO_QUEUE_SIZE_TOO_BIG:
47 case LOS_ERRNO_QUEUE_CREAT_PTR_NULL:
48 case LOS_ERRNO_QUEUE_PARA_ISZERO:
49 case LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG:
50 case LOS_ERRNO_TSK_ID_INVALID:
51 case LOS_ERRNO_TSK_PTR_NULL:
52 case LOS_ERRNO_TSK_NAME_EMPTY:
53 case LOS_ERRNO_TSK_ENTRY_NULL:
54 case LOS_ERRNO_TSK_PRIOR_ERROR:
55 case LOS_ERRNO_TSK_STKSZ_TOO_LARGE:
56 case LOS_ERRNO_TSK_STKSZ_TOO_SMALL:
57 case LOS_ERRNO_TSK_NOT_CREATED:
58 case OS_ERROR:
59 case LOS_ERRNO_SEM_INVALID:
60 case LOS_ERRNO_SEM_UNAVAILABLE:
61 errno = EINVAL;
62 break;
63 case LOS_ERRNO_QUEUE_ISFULL:
64 case LOS_ERRNO_QUEUE_ISEMPTY:
65 errno = EAGAIN;
66 break;
67 case LOS_ERRNO_QUEUE_CREATE_NO_MEMORY:
68 case LOS_ERRNO_TSK_TCB_UNAVAILABLE:
69 case LOS_ERRNO_SEM_ALL_BUSY:
70 errno = ENOSPC;
71 break;
72 case LOS_ERRNO_QUEUE_TIMEOUT:
73 case LOS_ERRNO_SEM_TIMEOUT:
74 errno = ETIMEDOUT;
75 break;
76 case LOS_ERRNO_QUEUE_CB_UNAVAILABLE:
77 errno = ENFILE;
78 break;
79 case LOS_ERRNO_QUEUE_READ_IN_INTERRUPT:
80 case LOS_ERRNO_QUEUE_WRITE_IN_INTERRUPT:
81 case LOS_ERRNO_SEM_PEND_INTERR:
82 errno = EINTR;
83 break;
84 case LOS_ERRNO_TSK_NO_MEMORY:
85 case LOS_ERRNO_SEM_OVERFLOW:
86 errno = ENOMEM;
87 break;
88 case LOS_ERRNO_SEM_PENDED:
89 errno = EBUSY;
90 break;
91 case LOS_ERRNO_SEM_PEND_IN_LOCK:
92 errno = EPERM;
93 break;
94 default:
95 errno = EINVAL;
96 break;
97 }
98 return errno;
99 }
100
101