diff options
Diffstat (limited to 'lib/libk')
-rw-r--r-- | lib/libk/endian.h | 8 | ||||
-rw-r--r-- | lib/libk/endian/little.c | 4 | ||||
-rw-r--r-- | lib/libk/stdio.h | 22 | ||||
-rw-r--r-- | lib/libk/stdio/fprintf.c | 5 | ||||
-rw-r--r-- | lib/libk/stdio/printf.c | 5 | ||||
-rw-r--r-- | lib/libk/stdio/vfprintf.c | 5 | ||||
-rw-r--r-- | lib/libk/stdlib.h | 10 | ||||
-rw-r--r-- | lib/libk/stdlib/linked_list_allocator.c | 11 | ||||
-rw-r--r-- | lib/libk/stdlib/memcpy.c | 2 | ||||
-rw-r--r-- | lib/libk/stdlib/memset.c | 3 | ||||
-rw-r--r-- | lib/libk/string.h | 13 |
11 files changed, 30 insertions, 58 deletions
diff --git a/lib/libk/endian.h b/lib/libk/endian.h index 70bc5f7..6aa2669 100644 --- a/lib/libk/endian.h +++ b/lib/libk/endian.h @@ -1,13 +1,11 @@ -//===================================================================== -// spdx-license-identifier: ISC -//===================================================================== +/* spdx-license-identifier: ISC */ #pragma once #include <stdint.h> -// These functions convert the byte encoding of integer values from host byte order to and from little-endian and -// big-endian byte order +/* These functions convert the byte encoding of integer values from host byte order to and from little-endian and + * big-endian byte order */ uint16_t htole16(uint16_t host_16b); uint32_t htole32(uint32_t host_32b); uint64_t htole64(uint64_t host_64b); diff --git a/lib/libk/endian/little.c b/lib/libk/endian/little.c index 042bb55..56a20ad 100644 --- a/lib/libk/endian/little.c +++ b/lib/libk/endian/little.c @@ -1,6 +1,4 @@ -//===================================================================== -// spdx-license-identifier: ISC -//===================================================================== +/* spdx-license-identifier: ISC */ #include "endian.h" diff --git a/lib/libk/stdio.h b/lib/libk/stdio.h index b28eb5e..7a6e663 100644 --- a/lib/libk/stdio.h +++ b/lib/libk/stdio.h @@ -2,22 +2,17 @@ #include <stdarg.h> -///@defgroup libk libk -///@{ -///@defgroup stdio stdio -///@{ - -/// An object type used for streams +/** An object type used for streams */ typedef struct FILE { int id; - /// Function that prints a character to the stream + /** Function that prints a character to the stream */ void (*putc)(const struct FILE *, char); - /// Function that prints a string to the stream + /** Function that prints a string to the stream */ int (*puts)(const struct FILE *, const char *, int); - /// Flush write buffers + /** Flush write buffers */ void (*flush)(const struct FILE *); } FILE; @@ -33,17 +28,14 @@ extern FILE *stderr; * Supports ``%s`` (string), ``%d`` (decimal), ``%u`` (unsigned), ``%x`` (hexadecimal) * @return number of bytes written */ -int printf(const char *restrict format, ...); +int printf(const char *__restrict__ format, ...); /** * Write the formatted string to stream; see printf */ -int fprintf(FILE *restrict stream, const char *restrict format, ...); +int fprintf(FILE *__restrict__ stream, const char *__restrict__ format, ...); /** * Write the formatted string to stream; see printf */ -int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap); - -///@} -///@} +int vfprintf(FILE *__restrict__ stream, const char *__restrict__ format, va_list ap); diff --git a/lib/libk/stdio/fprintf.c b/lib/libk/stdio/fprintf.c index 9a96dc6..c088f54 100644 --- a/lib/libk/stdio/fprintf.c +++ b/lib/libk/stdio/fprintf.c @@ -1,11 +1,12 @@ #include <stdio.h> int -fprintf(FILE *restrict stream, const char *restrict format, ...) +fprintf(FILE *__restrict__ stream, const char *__restrict__ format, ...) { + int c = 0; va_list ap; va_start(ap, format); - int c = vfprintf(stream, format, ap); + c += vfprintf(stream, format, ap); va_end(ap); return c; } diff --git a/lib/libk/stdio/printf.c b/lib/libk/stdio/printf.c index 4efc1ac..4c45593 100644 --- a/lib/libk/stdio/printf.c +++ b/lib/libk/stdio/printf.c @@ -1,11 +1,12 @@ #include <stdio.h> int -printf(const char *restrict format, ...) +printf(const char *__restrict__ format, ...) { + int c = 0; va_list ap; va_start(ap, format); - int c = vfprintf(stdout, format, ap); + c += vfprintf(stdout, format, ap); va_end(ap); return c; } diff --git a/lib/libk/stdio/vfprintf.c b/lib/libk/stdio/vfprintf.c index d24e43e..a48600b 100644 --- a/lib/libk/stdio/vfprintf.c +++ b/lib/libk/stdio/vfprintf.c @@ -4,13 +4,14 @@ static char buffer[3 * sizeof(int) + 2]; int -vfprintf(FILE *restrict stream, const char *restrict format, va_list params) +vfprintf(FILE *__restrict__ stream, const char *__restrict__ format, va_list params) { int written = 0; + int i; int s = 0; int l = 0; - for (int i = 0; format[i] != '\0'; ++i) { + for (i = 0; format[i] != '\0'; ++i) { if (format[i] == '%') { written += stream->puts(stream, &format[s], l); s = i + 2; diff --git a/lib/libk/stdlib.h b/lib/libk/stdlib.h index 84d9b2d..143c931 100644 --- a/lib/libk/stdlib.h +++ b/lib/libk/stdlib.h @@ -2,11 +2,6 @@ #include <stddef.h> -///@defgroup libk libk -///@{ -///@defgroup stdlib stdlib -///@{ - /** * Allocate size bytes and return a pointer to the allocated memory */ @@ -25,7 +20,4 @@ void *memset(void *s, int c, long unsigned n); /** * Copy n bytes from memory area src to memory area dest. The memory areas must not overlap. */ -void *memcpy(void *restrict dest, const void *restrict src, long unsigned n); - -///@} -///@} +void *memcpy(void *__restrict__ dest, const void *__restrict__ src, long unsigned n); diff --git a/lib/libk/stdlib/linked_list_allocator.c b/lib/libk/stdlib/linked_list_allocator.c index 66c63d1..898fd89 100644 --- a/lib/libk/stdlib/linked_list_allocator.c +++ b/lib/libk/stdlib/linked_list_allocator.c @@ -31,13 +31,14 @@ alloc_init(void *mem, size_t size) void * malloc(size_t size) { + struct Chunk *iter; if (begin == NULL) return NULL; - // find free chunk that is at least (size + sizeof(struct Chunk)) - for (struct Chunk *iter = begin; iter != NULL; iter = iter->next) { + /* find free chunk that is at least (size + sizeof(struct Chunk)) */ + for (iter = begin; iter != NULL; iter = iter->next) { if (iter->used != 0 || iter->size < size) continue; - // if there's at least sizeof(struct Chunk) bytes left over, create a new Chunk + /* if there's at least sizeof(struct Chunk) bytes left over, create a new Chunk */ if (iter->size >= (size + 2 * sizeof(struct Chunk))) { struct Chunk *next = (struct Chunk *)((uintptr_t)iter + sizeof(struct Chunk) + size); Chunk_ctor(next, iter->size - size - sizeof(struct Chunk)); @@ -61,14 +62,14 @@ free(void *ptr) struct Chunk *chunk = (struct Chunk *)((uintptr_t)ptr - sizeof(struct Chunk)); chunk->used = 0; - // merge next chunk + /* merge next chunk */ if (chunk->next != NULL && chunk->next->used == 0) { chunk->size += chunk->next->size + sizeof(struct Chunk); chunk->next = chunk->next->next; if (chunk->next != NULL) chunk->next->prev = chunk; } - // merge into prev chunk + /* merge into prev chunk */ if (chunk->prev != NULL && chunk->prev->used == 0) { chunk->prev->size += chunk->size + sizeof(struct Chunk); chunk->prev->next = chunk->next; diff --git a/lib/libk/stdlib/memcpy.c b/lib/libk/stdlib/memcpy.c index 90470d5..db7d21e 100644 --- a/lib/libk/stdlib/memcpy.c +++ b/lib/libk/stdlib/memcpy.c @@ -1,5 +1,5 @@ void * -memcpy(void *restrict dest, const void *restrict src, long unsigned n) +memcpy(void *__restrict__ dest, const void *__restrict__ src, long unsigned n) { char *pDest = (char *)dest; const char *pSrc = (const char *)src; diff --git a/lib/libk/stdlib/memset.c b/lib/libk/stdlib/memset.c index a16bd05..2a86f8e 100644 --- a/lib/libk/stdlib/memset.c +++ b/lib/libk/stdlib/memset.c @@ -1,7 +1,8 @@ void * memset(void *s, int c, long unsigned n) { + unsigned i; char *pDest = (char *)s; - for (unsigned i = 0; i < n; ++i) pDest[i] = (char)c; + for (i = 0; i < n; ++i) pDest[i] = (char)c; return s; } diff --git a/lib/libk/string.h b/lib/libk/string.h index c8196c8..46d8636 100644 --- a/lib/libk/string.h +++ b/lib/libk/string.h @@ -1,17 +1,9 @@ #pragma once -///@defgroup libk libk -///@{ -///@defgroup string string -///@{ - #define OCTAL 8 #define DECIMAL 10 #define HEX 16 -#ifdef __cplusplus -extern "C" { -#endif /** * Convert int into a string */ @@ -20,9 +12,4 @@ char *itoa(char *p, int x, int base); * Convert unsigned int into a string */ char *utoa(char *p, unsigned x, int base); -#ifdef __cplusplus -} -#endif -///@} -///@} |