lib: move lib headers into lib directory
This commit is contained in:
parent
2f20777a47
commit
a10509f1e5
20 changed files with 13 additions and 24 deletions
17
include/lib/assert.h
Normal file
17
include/lib/assert.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _ASSERT_H_
|
||||
#define _ASSERT_H_
|
||||
|
||||
#ifdef KDEBUG
|
||||
#define assert(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
kprintf(LOG_ERROR "assertion failed: %s, file %s, line %d\n", #expr, __FILE__, __LINE__); \
|
||||
yield(); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define assert(expr) ((void)0)
|
||||
#endif
|
||||
|
||||
#endif /* _ASSERT_H_ */
|
||||
19
include/lib/errno.h
Normal file
19
include/lib/errno.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _ERRNO_H_
|
||||
#define _ERRNO_H_
|
||||
|
||||
#define ENOMEM 1
|
||||
#define ENOENT 2
|
||||
#define EINVAL 3
|
||||
#define EBADF 4
|
||||
#define ENOTDIR 5
|
||||
#define EISDIR 6
|
||||
#define ENOSPC 7
|
||||
#define EEXIST 8
|
||||
#define ENOEXEC 9
|
||||
#define EFAULT 10
|
||||
#define EAGAIN 11
|
||||
|
||||
const char *strerror(int errnum);
|
||||
|
||||
#endif /* _ERRNO_H_ */
|
||||
26
include/lib/math.h
Normal file
26
include/lib/math.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _MATH_H_
|
||||
#define _MATH_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
size_t log2(size_t n);
|
||||
size_t npow2(size_t n);
|
||||
void bitmap_set(char *bitmap, size_t n, uint64_t b);
|
||||
void bitmap_clear(char *bitmap, size_t n);
|
||||
uint8_t bitmap_get(char *bitmap, size_t n);
|
||||
|
||||
#define MIN(a, b) ({ \
|
||||
typeof(a) _a = (a); \
|
||||
typeof(b) _b = (b); \
|
||||
_a < _b ? _a : _b; \
|
||||
})
|
||||
|
||||
#define MAX(a, b) ({ \
|
||||
typeof(a) _a = (a); \
|
||||
typeof(b) _b = (b); \
|
||||
_a > _b ? _a : _b; \
|
||||
})
|
||||
|
||||
#endif /* _MATH_H_ */
|
||||
25
include/lib/stdio.h
Normal file
25
include/lib/stdio.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _STDIO_H_
|
||||
#define _STDIO_H_
|
||||
|
||||
#define COL_RED_BLACK "\e[31m"
|
||||
#define COL_YELLOW_BLACK "\e[33m"
|
||||
#define COL_GREEN_BLACK "\e[32m"
|
||||
#define COL_MAGENTA_BLACK "\e[35m"
|
||||
|
||||
#define COL_RESET "\e[m"
|
||||
|
||||
#define LOG_ERROR "[" COL_RED_BLACK "ERR" COL_RESET "] "
|
||||
#define LOG_WARN "[" COL_YELLOW_BLACK "WRN" COL_RESET "] "
|
||||
#define LOG_DEBUG "[" COL_MAGENTA_BLACK "DBG" COL_RESET "] "
|
||||
#define LOG_SUCCESS "[" COL_GREEN_BLACK "RDY" COL_RESET "] "
|
||||
#define LOG_INFO "[LOG] "
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int kprintf(const char *restrict fmt, ...);
|
||||
int snprintf(char *str, const char *restrict fmt, size_t size, ...);
|
||||
int vsnprintf(char *str, const char *restrict fmt, size_t size, va_list args);
|
||||
|
||||
#endif /* _SDTIO_H_ */
|
||||
29
include/lib/string.h
Normal file
29
include/lib/string.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _STRING_H_
|
||||
#define _STRING_H_
|
||||
|
||||
#ifndef __ASM__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <kernel/lock.h>
|
||||
|
||||
void *memcpy(void *dest, const void *src, size_t num);
|
||||
int memcmp(const void *aa, const void *bb, size_t num);
|
||||
int strcmp(const char *a, const char *b);
|
||||
int strncmp(const char *a, const char *b, size_t n);
|
||||
void *memset(void *str, int c, size_t n);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strncpy(char *dest, const char *src, size_t n);
|
||||
char *strtok(char *str, const char *delim, char **llast);
|
||||
bool strempty(const char *s);
|
||||
char **strsplit(const char *str, char delim, int *num);
|
||||
size_t strlen(const char *c);
|
||||
int atoi(const char *a);
|
||||
|
||||
extern spinlock_t strtok_lock;
|
||||
|
||||
#endif /* __ASM__ */
|
||||
#endif /* _STRING_H_ */
|
||||
Loading…
Reference in a new issue