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:
parent
044e3a24c2
commit
055235b32e
4 changed files with 40 additions and 27 deletions
|
@ -70,7 +70,10 @@ if WITH_FRAMEBUFFER
|
|||
libkernaux_a_SOURCES += src/framebuffer.c
|
||||
endif
|
||||
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
|
||||
if WITH_MBR
|
||||
libkernaux_a_SOURCES += src/mbr.c
|
||||
|
|
15
libc/src/ctype.c
Normal file
15
libc/src/ctype.c
Normal 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
20
libc/src/stdlib.c
Normal 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;
|
||||
}
|
|
@ -2,34 +2,9 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.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)
|
||||
{
|
||||
for (const unsigned char *p1 = s1, *p2 = s2; n--; ++p1, ++p2) {
|
Loading…
Reference in a new issue