errno: add strerror function
This commit is contained in:
parent
69ad7ea220
commit
9aea93214a
2 changed files with 20 additions and 8 deletions
|
|
@ -1,5 +1,4 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
#ifndef _ERRNO_H_
|
||||
#define _ERRNO_H_
|
||||
|
||||
|
|
@ -8,12 +7,6 @@
|
|||
#define EINVAL 3
|
||||
#define EBADF 4
|
||||
|
||||
static const char *errno_str[] = {
|
||||
[0] = "Success",
|
||||
[ENOMEM] = "Out of memory",
|
||||
[ENOENT] = "No such file or directory",
|
||||
[EINVAL] = "Invalid argument",
|
||||
[EBADF] = "Bad file descriptor",
|
||||
};
|
||||
const char *strerror(int errnum);
|
||||
|
||||
#endif /* _ERRNO_H_ */
|
||||
|
|
|
|||
19
lib/errno.c
Normal file
19
lib/errno.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <errno.h>
|
||||
#include <kernel/common.h>
|
||||
|
||||
static const char *errno_str[] = {
|
||||
[0] = "Success",
|
||||
[ENOMEM] = "Out of memory",
|
||||
[ENOENT] = "No such file or directory",
|
||||
[EINVAL] = "Invalid argument",
|
||||
[EBADF] = "Bad file descriptor",
|
||||
};
|
||||
|
||||
inline const char *strerror(int errnum)
|
||||
{
|
||||
if (errnum < 0 || (size_t)errnum >= ARRAY_SIZE(errno_str))
|
||||
return "Unknown error";
|
||||
|
||||
return errno_str[errnum];
|
||||
}
|
||||
Loading…
Reference in a new issue