From b6ea3c20fe613652e60051d36e7c5ae035b5faab Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Fri, 28 Dec 2018 21:20:59 +0100 Subject: [PATCH] Stuff --- src/Makefile | 2 +- src/boot/folder.desc | 16 ++++++++-------- src/kaleid/common/folder.desc | 16 ++++++++-------- src/kaleid/common/lib/string.c | 23 ++++++++++++++++++----- src/kaleid/common/sub/memory.c | 9 ++++++--- src/kaleid/kernel/folder.desc | 16 ++++++++-------- src/kaleid/linux/test-common.c | 18 ++++++++++++++++-- 7 files changed, 65 insertions(+), 35 deletions(-) diff --git a/src/Makefile b/src/Makefile index eaa9884..cb8b590 100644 --- a/src/Makefile +++ b/src/Makefile @@ -72,7 +72,7 @@ common: $(COMMDEPS) $(COMMDIR)/lib/string.c $(COMMDIR)/lib/status.c CCC=$(CC2NAME) $(COPTIM) $(CWARNS) $(CINCLUDES) -common-test: +test-common: $(CCC) -c $(COMMDIR)/lib/string.c -o $(COBJDIR)/lib/string.o $(CCC) -c $(COMMDIR)/lib/status.c -o $(COBJDIR)/lib/status.o $(CCC) -c $(COMMDIR)/lib/memory.c -o $(COBJDIR)/lib/memory.o diff --git a/src/boot/folder.desc b/src/boot/folder.desc index d6b3cab..6322bc3 100644 --- a/src/boot/folder.desc +++ b/src/boot/folder.desc @@ -1,11 +1,11 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Folder description - "boot" // -//----------------------------------------------------------------------------// +--------------------------------------------------------------------- + GNU GPL OS/K + + Authors: spectral` + NeoX + + Desc: Folder description - "boot" +--------------------------------------------------------------------- This folder contains the source for OS/K's bootloader. diff --git a/src/kaleid/common/folder.desc b/src/kaleid/common/folder.desc index 651f5a9..ab5d8cc 100644 --- a/src/kaleid/common/folder.desc +++ b/src/kaleid/common/folder.desc @@ -1,11 +1,11 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Folder description - "kaleid/common" // -//----------------------------------------------------------------------------// +--------------------------------------------------------------------- + GNU GPL OS/K + + Authors: spectral` + NeoX + + Desc: Folder description - "kaleid/common" +--------------------------------------------------------------------- This is the folder containing the sources for Kaleid's C runtime library, linked both to the kernel and to the system processes that run outiside the kernel. It can also be compiled for Linux as diff --git a/src/kaleid/common/lib/string.c b/src/kaleid/common/lib/string.c index f81f60c..89cf625 100644 --- a/src/kaleid/common/lib/string.c +++ b/src/kaleid/common/lib/string.c @@ -38,18 +38,31 @@ char *strcpy(char *dest, const char *src) // char *strncpy(char *dest, const char *src, size_t n) { - size_t i; + size_t it; - for (i = 0; i < n && src[i]; i++) { - dest[i] = src[i]; + for (it = 0; it < n && src[it]; i++) { + dest[it] = src[i]; } - while (i < n) dest[i++] = 0; + while (it < n) dest[it++] = 0; return dest; } // -// Reverses a string +// Reverses the string src, putting the result into dest +// +char *strrev(char *dest, const char *src) +{ + size_t m = 0, n = strlen(src); + + dest[n--] = '\0'; + + while (n) dest[m++] = src[n--]; +} + +// +// Reverses a string, modifying it +// Returns a point to said string // char *reverse(char *str) { diff --git a/src/kaleid/common/sub/memory.c b/src/kaleid/common/sub/memory.c index 8a4585a..06407b9 100644 --- a/src/kaleid/common/sub/memory.c +++ b/src/kaleid/common/sub/memory.c @@ -4,9 +4,12 @@ // Authors: spectral` // // NeoX // // // -// Desc: mem*() functions - sub-optimal version // +// Desc: mem*() functions // //----------------------------------------------------------------------------// +// XXX to be improved before being brought back +// to be tested with more alignment sizes + #include "common/memory.h" // to be moved @@ -34,9 +37,9 @@ static inline void *memsetq(void *ptr, ullong uval, size_t qwords) // This is most certainely overkill, but I enjoyed doing this // Alignment stuff barely matters on modern processors // -void *memset(void *ptr, register int val, register size_t bytes) +void *memset(void *ptr, int val, size_t bytes) { - register uchar *uptr = (uchar *)ptr; + uchar *uptr = (uchar *)ptr; const size_t qwords = bytes/QWORD_SIZE; // get rid of everything after the first byte diff --git a/src/kaleid/kernel/folder.desc b/src/kaleid/kernel/folder.desc index 1b37b3a..039b5af 100644 --- a/src/kaleid/kernel/folder.desc +++ b/src/kaleid/kernel/folder.desc @@ -1,11 +1,11 @@ -//----------------------------------------------------------------------------// -// GNU GPL OS/K // -// // -// Authors: spectral` // -// NeoX // -// // -// Desc: Folder description - "kaleid/kernel" // -//----------------------------------------------------------------------------// +--------------------------------------------------------------------- + GNU GPL OS/K + + Authors: spectral` + NeoX + + Desc: Folder description - "kaleid/kernel" +--------------------------------------------------------------------- This folder contains the source of Kaleid's kernel component. diff --git a/src/kaleid/linux/test-common.c b/src/kaleid/linux/test-common.c index 127d07b..d9b3aec 100644 --- a/src/kaleid/linux/test-common.c +++ b/src/kaleid/linux/test-common.c @@ -7,9 +7,8 @@ // Desc: Test file for common/ // //----------------------------------------------------------------------------// -#include #include - +#include #define KEEP_KALCOMM_TYPES_MINIMAL #include "common/common.h" @@ -36,6 +35,21 @@ int main(int argc, char *argv[]) //void *xxx = malloc(sizex); //printf("%p\n",xxx); //memset(xxx, 'x', sizex); + + const char *str = "ceci est un string de test\n"; + char *str2 = malloc((strlen(str) + 3) * sizeof(char)); + + strcpy(str2, str); + + size_t s = strlen(str2); + + printf(reverse(reverse(str2))); + + str2[s] = '\n'; + str2[s+1] = '\0'; + printf(reverse(reverse(str2))); + + free(str2); /*size_t it; for (it = 0; it < sizex; it++) {