diff --git a/include/libmes.h b/include/libmes.h index 01bdf70f..f13d1f84 100644 --- a/include/libmes.h +++ b/include/libmes.h @@ -21,11 +21,35 @@ #ifndef __MES_LIBMES_H #define __MES_LIBMES_H +#ifndef _SIZE_T +#define _SIZE_T +#ifndef __SIZE_T +#define __SIZE_T +#ifndef __MES_SIZE_T +#define __MES_SIZE_T +#undef size_t +typedef unsigned long size_t; +#endif +#endif +#endif + +#ifndef _SSIZE_T +#define _SSIZE_T +#ifndef __SSIZE_T +#define __SSIZE_T +#ifndef __MES_SSIZE_T +#define __MES_SSIZE_T +#undef ssize_t +typedef long ssize_t; +#endif +#endif +#endif + int __mes_debug (); -char const* number_to_ascii (int number, int base, int signed_p); -char const* itoa (int number); -char const* utoa (unsigned number); -char const* itoab (int x, int base); +char const* number_to_ascii (long number, int base, int signed_p); +char const* itoa (long number); +char const* utoa (unsigned long number); +char const* itoab (long x, int base); int _atoi (char const**, int base); int atoi (char const *s); int eputc (int c); @@ -38,5 +62,6 @@ int isdigit (int c); int isspace (int c); int isxdigit (int c); int oputs (char const* s); +ssize_t write (int filedes, void const *buffer, size_t size); #endif //__MES_LIBMES_H diff --git a/lib/libc-mini.c b/lib/libc-mini.c index b4aa79f9..cbf543ca 100644 --- a/lib/libc-mini.c +++ b/lib/libc-mini.c @@ -18,64 +18,10 @@ * along with GNU Mes. If not, see . */ -#include - -#ifndef _SIZE_T -#define _SIZE_T -#ifndef __SIZE_T -#define __SIZE_T -#ifndef __MES_SIZE_T -#define __MES_SIZE_T -#undef size_t -typedef unsigned long size_t; -#endif -#endif -#endif - -#ifndef _SSIZE_T -#define _SSIZE_T -#ifndef __SSIZE_T -#define __SSIZE_T -#ifndef __MES_SSIZE_T -#define __MES_SSIZE_T -#undef ssize_t -typedef long ssize_t; -#endif -#endif -#endif - -ssize_t write (int filedes, void const *buffer, size_t size); - -size_t -strlen (char const* s) -{ - int i = 0; - while (s[i]) i++; - return i; -} - -int -eputs (char const* s) -{ - int i = strlen (s); - write (2, s, i); - return 0; -} - -int -oputs (char const* s) -{ - int i = strlen (s); - write (1, s, i); - return 0; -} - -int -puts (char const* s) -{ - oputs (s); - return oputs ("\n"); -} +#include +#include +#include +#include #if __GNU__ #include @@ -85,12 +31,4 @@ puts (char const* s) #error both __GNU__ and _linux__ are undefined, choose one #endif -void (*__call_at_exit) (void); - -void -exit (int code) -{ - if (__call_at_exit) - (*__call_at_exit) (); - _exit (code); -} +#include diff --git a/lib/mes/eputs.c b/lib/mes/eputs.c new file mode 100644 index 00000000..a22b145d --- /dev/null +++ b/lib/mes/eputs.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +int +eputs (char const* s) +{ + int i = strlen (s); + write (2, s, i); + return 0; +} diff --git a/lib/mes/oputs.c b/lib/mes/oputs.c new file mode 100644 index 00000000..123a8117 --- /dev/null +++ b/lib/mes/oputs.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +int +oputs (char const* s) +{ + int i = strlen (s); + write (1, s, i); + return 0; +} diff --git a/lib/stdlib/exit.c b/lib/stdlib/exit.c new file mode 100644 index 00000000..29be6d12 --- /dev/null +++ b/lib/stdlib/exit.c @@ -0,0 +1,31 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +void (*__call_at_exit) (void); + +void +exit (int code) +{ + if (__call_at_exit) + (*__call_at_exit) (); + _exit (code); +} diff --git a/lib/stdlib/puts.c b/lib/stdlib/puts.c new file mode 100644 index 00000000..be51f47b --- /dev/null +++ b/lib/stdlib/puts.c @@ -0,0 +1,28 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +int +puts (char const* s) +{ + oputs (s); + return oputs ("\n"); +} diff --git a/lib/string/strlen.c b/lib/string/strlen.c new file mode 100644 index 00000000..0f6df8ad --- /dev/null +++ b/lib/string/strlen.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ + +#include + +size_t +strlen (char const* s) +{ + int i = 0; + while (s[i]) + i++; + return i; +}