1 /*
2  * Copyright (c) 2006-2024, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2024-09-22     Meco Man     the first version
9  */
10 
11 #ifndef __RT_KERRNO_H__
12 #define __RT_KERRNO_H__
13 
14 #include <rtconfig.h>
15 #include <rttypes.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #if defined(RT_USING_LIBC) && !defined(RT_USING_NANO)
22 /* POSIX error code compatible */
23 #define RT_EOK                          0               /**< There is no error */
24 #define RT_ERROR                        255             /**< A generic/unknown error happens */
25 #define RT_ETIMEOUT                     ETIMEDOUT       /**< Timed out */
26 #define RT_EFULL                        ENOSPC          /**< The resource is full */
27 #define RT_EEMPTY                       ENODATA         /**< The resource is empty */
28 #define RT_ENOMEM                       ENOMEM          /**< No memory */
29 #define RT_ENOSYS                       ENOSYS          /**< Function not implemented */
30 #define RT_EBUSY                        EBUSY           /**< Busy */
31 #define RT_EIO                          EIO             /**< IO error */
32 #define RT_EINTR                        EINTR           /**< Interrupted system call */
33 #define RT_EINVAL                       EINVAL          /**< Invalid argument */
34 #define RT_ENOENT                       ENOENT          /**< No entry */
35 #define RT_ENOSPC                       ENOSPC          /**< No space left */
36 #define RT_EPERM                        EPERM           /**< Operation not permitted */
37 #define RT_EFAULT                       EFAULT          /**< Bad address */
38 #define RT_ENOBUFS                      ENOBUFS         /**< No buffer space is available */
39 #define RT_ESCHEDISR                    253             /**< scheduler failure in isr context */
40 #define RT_ESCHEDLOCKED                 252             /**< scheduler failure in critical region */
41 #define RT_ETRAP                        254             /**< Trap event */
42 #else
43 #define RT_EOK                          0               /**< There is no error */
44 #define RT_ERROR                        1               /**< A generic/unknown error happens */
45 #define RT_ETIMEOUT                     2               /**< Timed out */
46 #define RT_EFULL                        3               /**< The resource is full */
47 #define RT_EEMPTY                       4               /**< The resource is empty */
48 #define RT_ENOMEM                       5               /**< No memory */
49 #define RT_ENOSYS                       6               /**< Function not implemented */
50 #define RT_EBUSY                        7               /**< Busy */
51 #define RT_EIO                          8               /**< IO error */
52 #define RT_EINTR                        9               /**< Interrupted system call */
53 #define RT_EINVAL                       10              /**< Invalid argument */
54 #define RT_ENOENT                       11              /**< No entry */
55 #define RT_ENOSPC                       12              /**< No space left */
56 #define RT_EPERM                        13              /**< Operation not permitted */
57 #define RT_ETRAP                        14              /**< Trap event */
58 #define RT_EFAULT                       15              /**< Bad address */
59 #define RT_ENOBUFS                      16              /**< No buffer space is available */
60 #define RT_ESCHEDISR                    17              /**< scheduler failure in isr context */
61 #define RT_ESCHEDLOCKED                 18              /**< scheduler failure in critical region */
62 #endif /* defined(RT_USING_LIBC) && !defined(RT_USING_NANO) */
63 
64 rt_err_t rt_get_errno(void);
65 void rt_set_errno(rt_err_t no);
66 int *_rt_errno(void);
67 const char *rt_strerror(rt_err_t error);
68 #if !defined(RT_USING_NEWLIBC) && !defined(_WIN32)
69 #ifndef errno
70 #define errno    *_rt_errno()
71 #endif
72 #endif /* !defined(RT_USING_NEWLIBC) && !defined(_WIN32) */
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif
79