feat: refactor to use gcc types

This commit is contained in:
2021-02-12 22:16:03 +01:00
parent 555c1177a6
commit 8f615b259c
33 changed files with 419 additions and 361 deletions

View File

@@ -5,7 +5,7 @@
#include "kprintf.h"
#include "libc.h"
#include <libc/string.h>
#include <libc/va_list.h>
#include <stdarg.h>
#include <kprint.h>
#include <libk.h>
#include <types.h>
@@ -13,32 +13,32 @@
/*
* Integer to string
*/
void print_int(u32 value, u32 width, char *buf, u32 *ptr, u8 base) {
// u32 in binary is 32 digits, so never longer than 33 digits
void print_int(uint32_t value, uint32_t width, char *buf, uint32_t *ptr, uint8_t base) {
// uint32_t in binary is 32 digits, so never longer than 33 digits
char msg[33];
itoa(value, msg, base);
u32 digits = strlen(msg);
uint32_t digits = strlen(msg);
if (digits < width) {
for (u32 i = 0; i < (width - digits); ++i) {
for (uint32_t i = 0; i < (width - digits); ++i) {
buf[*ptr] = '0';
*ptr += 1;
}
}
for (u32 i = 0; i < digits; ++i) {
for (uint32_t i = 0; i < digits; ++i) {
buf[*ptr] = msg[i];
*ptr += 1;
}
}
u32 vasprintf(char *buf, const char *fmt, va_list args) {
u32 ptr = 0;
uint32_t vasprintf(char *buf, const char *fmt, va_list args) {
uint32_t ptr = 0;
for (int i = 0; i < strlen(fmt); ++i) {
if (fmt[i] != '%') {
buf[ptr++] = fmt[i];
continue;
}
++i;
u32 arg_width = 0;
uint32_t arg_width = 0;
while (fmt[i] >= '0' && fmt[i] <= '9') {
arg_width *= 10;
arg_width += fmt[i] - '0';
@@ -56,10 +56,10 @@ u32 vasprintf(char *buf, const char *fmt, va_list args) {
buf[ptr++] = (char) va_arg(args, int);
break;
case 'x':
print_int((u32) va_arg(args, u32), arg_width, buf, &ptr, 16);
print_int((uint32_t) va_arg(args, uint32_t), arg_width, buf, &ptr, 16);
break;
case 'd':
print_int((u32) va_arg(args, u32), arg_width, buf, &ptr, 10);
print_int((uint32_t) va_arg(args, uint32_t), arg_width, buf, &ptr, 10);
break;
case '%':
buf[ptr++] = '%';

View File

@@ -8,7 +8,7 @@
#include <types.h>
#include "libc.h"
int memcpy(u8 *dst, const u8 *src, int amount) {
int memcpy(uint8_t *dst, const uint8_t *src, int amount) {
for (int i = 0; i < amount; i++) {
dst[i] = src[i];
}

View File

@@ -10,7 +10,7 @@
#include <types.h>
int memcpy(u8 *dst, const u8 *src, int amount);
int memcpy(uint8_t *dst, const uint8_t *src, int amount);
int memset(char *dst, char data, int amount);

View File

@@ -6,7 +6,7 @@
#define NEW_KERNEL_RINGQUEUE_H
#include <types.h>
#include <libc/stdbool.h>
#include <stdbool.h>
void *create_buffer(int count, int object_size);

View File

@@ -1,5 +0,0 @@
//
// Created by rick on 31-01-21.
//
#include "stdbool.h"

View File

@@ -1,15 +0,0 @@
//
// Created by rick on 31-01-21.
//
#ifndef NEW_KERNEL_STDBOOL_H
#define NEW_KERNEL_STDBOOL_H
#define TRUE 1
#define true 1
#define FALSE 0
#define false 0
typedef unsigned char bool;
#endif //NEW_KERNEL_STDBOOL_H

View File

@@ -1,14 +0,0 @@
//
// Created by rick on 06-02-21.
//
#ifndef NEW_KERNEL_VA_LIST_H
#define NEW_KERNEL_VA_LIST_H
typedef __builtin_va_list va_list;
#define va_start(ap, last) __builtin_va_start(ap, last)
#define va_end(ap) __builtin_va_end(ap)
#define va_arg(ap, type) __builtin_va_arg(ap,type)
#define va_copy(dest, src) __builtin_va_copy(dest,src)
#endif //NEW_KERNEL_VA_LIST_H