1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00

Main: split libc into separate source files

This commit is contained in:
Alex Kotov 2022-06-08 06:25:57 +03:00
parent 044e3a24c2
commit 055235b32e
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 40 additions and 27 deletions

View file

@ -70,7 +70,10 @@ if WITH_FRAMEBUFFER
libkernaux_a_SOURCES += src/framebuffer.c libkernaux_a_SOURCES += src/framebuffer.c
endif endif
if WITH_LIBC if WITH_LIBC
libkernaux_a_SOURCES += libc/src/main.c libkernaux_a_SOURCES += \
libc/src/ctype.c \
libc/src/stdlib.c \
libc/src/string.c
endif endif
if WITH_MBR if WITH_MBR
libkernaux_a_SOURCES += src/mbr.c libkernaux_a_SOURCES += src/mbr.c

15
libc/src/ctype.c Normal file
View file

@ -0,0 +1,15 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <ctype.h>
int isdigit(const int c)
{
return (unsigned)c - '0' < 10;
}
int isspace(const int c)
{
return c == ' ' || (unsigned)c - '\t' < 5;
}

20
libc/src/stdlib.c Normal file
View file

@ -0,0 +1,20 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
int atoi(const char *str)
{
while (isspace(*str)) ++str;
bool is_negative = false;
switch (*str) {
case '-': is_negative = true; // fall through
case '+': ++str;
}
int result = 0;
while (isdigit(*str)) result = 10 * result - (*str++ - '0');
return is_negative ? result : -result;
}

View file

@ -2,34 +2,9 @@
#include "config.h" #include "config.h"
#endif #endif
#include <ctype.h> #include <stddef.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
int atoi(const char *str)
{
while (isspace(*str)) ++str;
bool is_negative = false;
switch (*str) {
case '-': is_negative = true; // fall through
case '+': ++str;
}
int result = 0;
while (isdigit(*str)) result = 10 * result - (*str++ - '0');
return is_negative ? result : -result;
}
int isdigit(const int c)
{
return (unsigned)c - '0' < 10;
}
int isspace(const int c)
{
return c == ' ' || (unsigned)c - '\t' < 5;
}
int memcmp(const void *s1, const void *s2, size_t n) int memcmp(const void *s1, const void *s2, size_t n)
{ {
for (const unsigned char *p1 = s1, *p2 = s2; n--; ++p1, ++p2) { for (const unsigned char *p1 = s1, *p2 = s2; n--; ++p1, ++p2) {