matos/core/klibc.h

66 lines
3.0 KiB
C
Raw Normal View History

2018-07-20 15:41:58 +02:00
#pragma once
2021-10-07 21:23:32 +02:00
#include "assert.h"
#include "stdarg.h"
2024-01-29 23:27:10 +01:00
#include "stddef.h"
2021-01-23 00:42:09 +01:00
#include "minmax.h"
2018-07-20 15:41:58 +02:00
#define islower(c) (('a' <= (c)) && ((c) <= 'z'))
#define isupper(c) (('A' <= (c)) && ((c) <= 'Z'))
#define isdigit(c) (('0' <= (c)) && ((c) <= '9'))
#define isspace(c) \
(((c) == ' ') || ((c) == '\t') || ((c) == '\f') || ((c) == '\n') || ((c) == '\r') || \
((c) == '\v'))
#define isprint(c) ((' ' <= (c)) && ((c) <= '~'))
2018-11-22 17:41:18 +01:00
2023-03-05 20:34:24 +01:00
/** compares the first @param n bytes (each interpreted as
* unsigned char) of the memory areas @param s1 and @param s2.
*/
2023-11-08 21:52:55 +01:00
__attribute__ ((access (read_only, 1, 3), access (read_only, 2, 3))) int memcmp(const void *s1, const void *s2, size_t n);
2023-03-05 20:34:24 +01:00
/**
* copies n bytes from memory area src to memory area dest. The memory areas may overlap
*/
2023-11-08 21:52:55 +01:00
__attribute__ ((access (write_only, 1, 3), access (read_only, 2, 3))) void *memmove(void *dest, const void *src, size_t n);
__attribute__ ((access (write_only, 1, 3), access (read_only, 2, 3))) void *memcpy(void *dest, const void *src, size_t n);
__attribute__ ((access (write_only, 1, 3))) void *memset(void *s, int c, size_t n);
2021-01-23 21:21:13 +01:00
char *itoa(long long int value, char *str, int base);
2021-11-08 22:30:41 +01:00
int atoi(const char *str);
2018-11-20 17:03:57 +01:00
void reverse(char s[]);
2024-05-23 00:21:41 +02:00
size_t strlen(const char s[]);
2023-11-08 21:52:55 +01:00
__attribute__ ((access (read_only, 1, 2))) unsigned int strnlen(const char *s, size_t count);
2020-04-23 00:49:09 +02:00
int strcmp(const char s1[], const char s2[]);
2023-11-08 21:52:55 +01:00
__attribute__ ((access (read_only, 2), access (write_only, 1, 3))) char *strzcpy(char *dst, const char *src, int len);
2021-01-24 22:20:43 +01:00
int puts(const char *str);
int putc(const char str);
int vsnprintf(char *str, size_t size, const char *format, va_list ap) __attribute__ ((__format__ (printf, 3, 0)));
int vprintf(const char *format, va_list ap) __attribute__ ((__format__ (printf, 1, 0)));
int printf(const char *format, ...) __attribute__ ((__format__ (printf, 1, 2)));
2021-01-25 10:17:19 +01:00
// Could be used after malloc is available
int asprintf(char **strp, const char *fmt, ...) __attribute__ ((__format__ (printf, 2, 3)));
int vasprintf(char **strp, const char *fmt, va_list ap) __attribute__ ((__format__ (printf, 2, 0)));
2021-01-25 10:17:19 +01:00
/*
* Dummy printk for disabled debugging statements to use whilst maintaining
* gcc's format checking.
*/
#define no_printf(fmt, ...) \
({ \
if (0) \
printf(fmt, ##__VA_ARGS__); \
0; \
})
2020-08-28 22:38:05 +02:00
#ifndef pr_fmt
#define pr_fmt(fmt) fmt
#endif
#ifdef DEBUG
#define pr_devel(fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__)
#else
#define pr_devel(fmt, ...) no_printf(pr_fmt(fmt), ##__VA_ARGS__)
#endif
#define pr_info(fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__)
2021-08-19 16:44:47 +02:00
#define pr_err(fmt, ...) {printf(pr_fmt(fmt), ##__VA_ARGS__); assert(0);}