Added some string.h functions and fixed up (formatting a bit broken :p)

This commit is contained in:
NeGate 2022-06-02 19:36:04 -04:00
parent 843f13b504
commit e93d2070ff
8 changed files with 145 additions and 41 deletions

View File

@ -1,6 +1,5 @@
#include<_platform.h>
#include<locale.h>
#include <_platform.h>
#include <locale.h>
extern int main();

View File

@ -1,10 +1,57 @@
#include <string.h>
int strcmp(const char *s1, const char *s2)
{
while(*s1 != 0 && *s2 != 0) {
if(*s1 != *s2) break;
void *memcpy(void *restrict s1, const void *restrict s2, size_t n) {
const unsigned char *restrict c2 = s2;
unsigned char *restrict c1 = s1;
while (n--) {
*c1++ = *c2++;
}
return s1;
}
int memcmp(const void *s1, const void *s2, size_t n) {
const unsigned char *u1 = s1;
const unsigned char *u2 = s2;
for (; n--; u1++, u2++) {
if (*u1 != *u2) return *u1 - *u2;
}
if(*s1 > *s2) return 1;
if(*s1 < *s2) return -1;
return 0;
}
void *memset(void *s, int c, size_t n) {
unsigned char *restrict buf = s;
while (n--) {
*buf++ = c;
}
return s;
}
int strcmp(const char *s1, const char *s2) {
while (*s1 != 0 && *s2 != 0) {
if (*s1 != *s2) break;
}
if(*s1 > *s2) return 1;
if(*s1 < *s2) return -1;
return 0;
}
size_t strlen(const char *s) {
size_t i = 0;
while (s[i]) {
i++;
}
return i;
}
// __STDC_WANT_LIB_EXT1__
size_t strnlen_s(const char *s, size_t maxsize) {
size_t i = 0;
while (s[i] && i < maxsize) {
i++;
}
return i;
}

View File

@ -24,18 +24,15 @@ char *strerror(int errnum);
size_t strlen(const char *s);
#if __STDC_WANT_LIB_EXT1__
errno_t memcpy_s(void * restrict s1, rsize_t s1max, const void * restrict s2, rsize_t n);
errno_t memmove_s(void *s1, rsize_t s1max, const void *s2, rsize_t n);
errno_t strcpy_s(char * restrict s1, rsize_t s1max, const char * restrict s2);
errno_t strncpy_s(char * restrict s1, rsize_t s1max,
const char * restrict s2, rsize_t n);
errno_t strcat_s(char * restrict s1, rsize_t s1max, const char * restrict s2);
errno_t strncat_s(char * restrict s1, rsize_t s1max,
const char * restrict s2, rsize_t n);
char *strtok_s(char * restrict s1, rsize_t * restrict s1max,
const char * restrict s2, char ** restrict ptr);
errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n);
errno_t strerror_s(char *s, rsize_t maxsize, errno_t errnum);
size_t strerrorlen_s(errno_t errnum);
size_t strnlen_s(const char *s, size_t maxsize);
#endif
errno_t memcpy_s(void * restrict s1, rsize_t s1max, const void * restrict s2, rsize_t n);
errno_t memmove_s(void *s1, rsize_t s1max, const void *s2, rsize_t n);
errno_t strcpy_s(char * restrict s1, rsize_t s1max, const char * restrict s2);
errno_t strncpy_s(char * restrict s1, rsize_t s1max,const char * restrict s2, rsize_t n);
errno_t strcat_s(char * restrict s1, rsize_t s1max, const char * restrict s2);
errno_t strncat_s(char * restrict s1, rsize_t s1max, const char * restrict s2, rsize_t n);
char *strtok_s(char * restrict s1, rsize_t * restrict s1max, const char * restrict s2, char ** restrict ptr);
errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n);
errno_t strerror_s(char *s, rsize_t maxsize, errno_t errnum);
size_t strerrorlen_s(errno_t errnum);
size_t strnlen_s(const char *s, size_t maxsize);
#endif

View File

@ -1,6 +1,6 @@
GNUFLAGS=-Werror -Wall -Iinc -Icode
CLFLAGS=/I:inc /link /incremental:no /subsystem:windows /nodefaultlib kernel32.lib
GNUFLAGS=-g -gcodeview -Werror -Wall -Iinc -Icode
CLFLAGS=/Zi /I:inc /link /incremental:no /subsystem:windows /nodefaultlib kernel32.lib
CC=clang
CFLAGS=$(GNUFLAGS)

63
project.4coder Normal file
View File

@ -0,0 +1,63 @@
version(1);
project_name = "Ciabatta";
patterns = {
"*.c",
"*.cpp",
"*.ds",
"*.h",
"*.bat",
"*.vert",
"*.frag",
"*.geom",
"*.sh",
"*.4coder",
};
blacklist_patterns = {
".*",
};
load_paths = {
{
{ {"."}, .recursive = true, .relative = true }, .os = "win"
},
};
command_list = {
{
.name = "build",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = true,
.cmd = {
{ "make", .os = "win" },
},
},
{
.name = "bake",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = true,
.cmd = {
{ "test\\bake.bat", .os = "win" },
},
},
{
.name = "debug",
.out = "*compilation*",
.footer_panel = true,
.save_dirty_files = true,
.cursor_at_end = true,
.cmd = {
{ "remedybg.exe test.rdbg", .os = "win" },
},
},
};
fkey_command[1] = "build";
fkey_command[2] = "bake";
fkey_command[3] = "debug";

View File

@ -6,10 +6,10 @@ inctoarg > temp
set /P includes=<temp
del temp
cl /Z7 /X /c /I ..\inc %includes% /nologo /GS- /Gm- /GR- /EHa- /Oi /W4 test.c
cl /Zi /X /c /I ..\inc %includes% /nologo /GS- /Gm- /GR- /EHa- /Oi /W4 test.c
::clang -c -Wall test.c -otest1.obj
link /nologo test.obj /nodefaultlib user32.lib kernel32.lib ..\ciabatta.lib -subsystem:console
link /nologo test.obj /nodefaultlib user32.lib kernel32.lib ..\ciabatta.lib -debug -subsystem:console
::link /nologo test1.obj /nodefaultlib user32.lib kernel32.lib ..\lib\ciabatta.lib -subsystem:console
popd

View File

@ -1,13 +1,12 @@
#include<stdio.h>
#include<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int main() {
char *include = getenv("INCLUDE");
printf(" ");
while(*include != 0) {
while (*include != 0) {
printf("-I \"");
while(*include != ';' && *include != 0) {
while (*include != ';' && *include != 0) {
if (*include == '\\') {
printf("/");
} else {
@ -15,7 +14,7 @@ int main()
}
*include++;
}
if(*include == ';') {
if (*include == ';') {
++include;
}
printf("\" ");

View File

@ -1,10 +1,9 @@
#include <assert.h>
#include <ctype.h>
int main()
{
for(char c = 'a'; c != 'z'; ++c) {
assert(isupper(toupper(c)));
int main(void) {
for (char c = 'a'; c != 'z'; ++c) {
assert(isupper(toupper(c)));
}
return 0;
}
}