Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions components/libc/include/ctype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef __CTYPE_H
#define __CTYPE_H

#ifdef __cplusplus
extern "C" {
#endif

int iscntrl(int c);

int isblank(int c);

int isspace(int c);

int isupper(int c);

int islower(int c);

int isalpha(int c);

int isdigit(int c);

int isxdigit(int c);

int isalnum(int c);

int ispunct(int c);

int isgraph(int c);

int isprint(int c);

int tolower(int c);

int toupper(int c);

#ifdef __cplusplus
}
#endif

#endif /* __CTYPE_H */

5 changes: 4 additions & 1 deletion components/libc/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

#include <stdarg.h>
#include <stddef.h>
#include "hal_sys_uart.h"

#ifdef __cplusplus
extern "C" {
#endif

int putchar(int c);

int puts(const char *str);

/**
* @brief Formatted output to stdout
* @param fmt Format string
Expand Down
49 changes: 49 additions & 0 deletions components/libc/include/stdlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef __STDLIB_H
#define __STDLIB_H

#include <stddef.h>
#include <stdarg.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
void* start;
void* end;
} area_t;

extern const area_t heap;

__attribute__ ((__noreturn__))
void halt(int code);

#ifndef NULL
#define NULL 0
#endif

#define RAND_MAX 0x7fffffff;

void srand(unsigned int seed);

int rand(void);

void *malloc(size_t size);

void free(void *ptr);

int abs(int x);

int atoi(const char *nptr);

__attribute__ ((__noreturn__))
void exit(int code);

__attribute__ ((__noreturn__))
void abort(void);

#ifdef __cplusplus
}
#endif

#endif /* __STDLIB_H */
2 changes: 1 addition & 1 deletion components/libc/include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void* memset(void* s, int c, size_t n);
*/
size_t strlen(const char* s);

size_t memcmp(const void* ptr1, const void* ptr2, size_t num);
int memcmp(const void* ptr1, const void* ptr2, size_t num);

char* strchr(const char* str, int c);

Expand Down
68 changes: 68 additions & 0 deletions components/libc/src/ctype.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "ctype.h"

int iscntrl(int c) {
return (c >= '\0' && c <= '\x1f') || (c == '\x7f');
}

int isblank(int c) {
return (c == '\t' || c == ' ');
}

int isspace(int c) {
return (c == ' ' || (c >= '\t' && c <= '\r'));
}

int isupper(int c) {
return (c >= 'A' && c <= 'Z');
}

int islower(int c) {
return (c >= 'a' && c <= 'z');
}

int isalpha(int c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}

int isdigit(int c) {
return (c >= '0' && c <= '9');
}

int isxdigit(int c) {
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');
}

int isalnum(int c) {
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}

int ispunct(int c) {
return (c >= '!' && c <= '/') ||
(c >= ':' && c <= '@') ||
(c >= '[' && c <= '`') ||
(c >= '{' && c <= '~');
}

int isgraph(int c) {
return (c >= '!' && c <= '~');
}

int isprint(int c) {
return (c >= ' ' && c <= '~');
}

int tolower(int c) {
if (isupper(c)) {
return c - 'A' + 'a';
} else {
return c;
}
}

int toupper(int c) {
if (islower(c)) {
return c - 'a' + 'A';
} else {
return c;
}
}
Loading