From 3e4a56a05b60469649602a587803bb2414472e60 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 16 Aug 2018 10:50:53 +0200 Subject: [PATCH] mescc: Mes C Library: Explode libc.c. * lib/libc.c: New file, explode from lib/libc.c. * lib/posix/execv.c: Likewise. * lib/posix/isatty.c: Likewise. * lib/posix/wait.c: Likewise. * lib/stdio/fgetc.c: Likewise. * lib/stdio/fputc.c: Likewise. * lib/stdio/fputs.c: Likewise. * lib/stdio/getc.c: Likewise. * lib/stdio/getchar.c: Likewise. * lib/stdio/putc.c: Likewise. * lib/stdio/putchar.c: Likewise. * lib/stdio/ungetc.c: Likewise. * lib/stdlib/free.c: Likewise. * lib/stdlib/getenv.c: Likewise. * lib/stdlib/realloc.c: Likewise. * lib/stdlib/setenv.c: Likewise. * lib/string/strcmp.c: Likewise. * lib/string/strcpy.c: Likewise. * lib/string/strncmp.c: Likewise. * lib/libc.c: Include explodings. --- lib/libc.c | 166 +++++-------------------------------------- lib/posix/execv.c | 27 +++++++ lib/posix/isatty.c | 27 +++++++ lib/posix/wait.c | 27 +++++++ lib/stdio/fgetc.c | 27 +++++++ lib/stdio/fputc.c | 27 +++++++ lib/stdio/fputs.c | 27 +++++++ lib/stdio/getc.c | 27 +++++++ lib/stdio/getchar.c | 27 +++++++ lib/stdio/putc.c | 27 +++++++ lib/stdio/putchar.c | 28 ++++++++ lib/stdio/ungetc.c | 27 +++++++ lib/stdlib/free.c | 26 +++++++ lib/stdlib/getenv.c | 35 +++++++++ lib/stdlib/realloc.c | 33 +++++++++ lib/stdlib/setenv.c | 44 ++++++++++++ lib/string/strcmp.c | 32 +++++++++ lib/string/strcpy.c | 31 ++++++++ lib/string/strncmp.c | 34 +++++++++ 19 files changed, 551 insertions(+), 148 deletions(-) create mode 100644 lib/posix/execv.c create mode 100644 lib/posix/isatty.c create mode 100644 lib/posix/wait.c create mode 100644 lib/stdio/fgetc.c create mode 100644 lib/stdio/fputc.c create mode 100644 lib/stdio/fputs.c create mode 100644 lib/stdio/getc.c create mode 100644 lib/stdio/getchar.c create mode 100644 lib/stdio/putc.c create mode 100644 lib/stdio/putchar.c create mode 100644 lib/stdio/ungetc.c create mode 100644 lib/stdlib/free.c create mode 100644 lib/stdlib/getenv.c create mode 100644 lib/stdlib/realloc.c create mode 100644 lib/stdlib/setenv.c create mode 100644 lib/string/strcmp.c create mode 100644 lib/string/strcpy.c create mode 100644 lib/string/strncmp.c diff --git a/lib/libc.c b/lib/libc.c index 45b9c190..1b7f0ff4 100644 --- a/lib/libc.c +++ b/lib/libc.c @@ -65,154 +65,24 @@ __mes_debug () #include #endif -int -getchar () -{ - return fdgetc (g_stdin); -} +#include +#include +#include +#include +#include +#include +#include +#include -int -putchar (int c) -{ - write (STDOUT, (char*)&c, 1); - return 0; -} +#include +#include +#include -int -fputc (int c, FILE* stream) -{ - return fdputc (c, (int)stream); -} +#include +#include +#include +#include -int -fputs (char const* s, FILE* stream) -{ - return fdputs (s, (int)stream); -} - -int -putc (int c, FILE* stream) -{ - return fdputc (c, (int)stream); -} - -int -getc (FILE *stream) -{ - return fdgetc ((int)stream); -} - -int -fgetc (FILE *stream) -{ - return fdgetc ((int)stream); -} - -void -free (void *ptr) -{ -} - -int -ungetc (int c, FILE *stream) -{ - return fdungetc (c, (int)stream); -} - -int -strcmp (char const* a, char const* b) -{ - while (*a && *b && *a == *b) - { - a++;b++; - } - return *a - *b; -} - -char * -strcpy (char *dest, char const *src) -{ - char *p = dest; - while (*src) *p++ = *src++; - *p = 0; - return dest; -} - -void * -realloc (void *ptr, size_t size) -{ - void *new = malloc (size); - if (ptr && new) - { - memcpy (new, ptr, size); - free (ptr); - } - return new; -} - -int -strncmp (char const* a, char const* b, size_t size) -{ - if (!size) - return 0; - while (*a && *b && *a == *b && --size) - { - a++; - b++; - } - return *a - *b; -} - -char * -getenv (char const* s) -{ - char **p = environ; - int length = strlen (s); - while (*p) - { - if (!strncmp (s, *p, length) && *(*p + length) == '=') return (*p + length + 1); - p++; - } - return 0; -} - -int -setenv (char const* s, char const* v, int overwrite_p) -{ - char **p = environ; - int length = strlen (s); - while (*p) - { - if (!strncmp (s, *p, length) && *(*p + length) == '=') - break; - p++; - } - char *entry = malloc (length + strlen (v) + 2); - int end_p = *p == 0; - *p = entry; - strcpy (entry, s); - strcpy (entry + length, "="); - strcpy (entry + length + 1, v); - *(entry + length + strlen (v) + 2) = 0; - if (end_p) - *++p = 0; - return 0; -} - -int -isatty (int fd) -{ - return ioctl (fd, TCGETS, 0) & 0xf0; -} - -int -wait (int *status_ptr) -{ - return waitpid (-1, status_ptr, 0); -} - -int -execv (char const *file_name, char *const argv[]) -{ - return execve (file_name, argv, environ); -} +#include +#include +#include diff --git a/lib/posix/execv.c b/lib/posix/execv.c new file mode 100644 index 00000000..b5a29bf9 --- /dev/null +++ b/lib/posix/execv.c @@ -0,0 +1,27 @@ +/* -*-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 +execv (char const *file_name, char *const argv[]) +{ + return execve (file_name, argv, environ); +} diff --git a/lib/posix/isatty.c b/lib/posix/isatty.c new file mode 100644 index 00000000..6ee18077 --- /dev/null +++ b/lib/posix/isatty.c @@ -0,0 +1,27 @@ +/* -*-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 +isatty (int fd) +{ + return ioctl (fd, TCGETS, 0) & 0xf0; +} diff --git a/lib/posix/wait.c b/lib/posix/wait.c new file mode 100644 index 00000000..5d1d6f40 --- /dev/null +++ b/lib/posix/wait.c @@ -0,0 +1,27 @@ +/* -*-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 +wait (int *status_ptr) +{ + return waitpid (-1, status_ptr, 0); +} diff --git a/lib/stdio/fgetc.c b/lib/stdio/fgetc.c new file mode 100644 index 00000000..83f2589c --- /dev/null +++ b/lib/stdio/fgetc.c @@ -0,0 +1,27 @@ +/* -*-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 +fgetc (FILE *stream) +{ + return fdgetc ((long)stream); +} diff --git a/lib/stdio/fputc.c b/lib/stdio/fputc.c new file mode 100644 index 00000000..bcadbc3f --- /dev/null +++ b/lib/stdio/fputc.c @@ -0,0 +1,27 @@ +/* -*-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 +fputc (int c, FILE* stream) +{ + return fdputc (c, (long)stream); +} diff --git a/lib/stdio/fputs.c b/lib/stdio/fputs.c new file mode 100644 index 00000000..165f0d2f --- /dev/null +++ b/lib/stdio/fputs.c @@ -0,0 +1,27 @@ +/* -*-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 +fputs (char const* s, FILE* stream) +{ + return fdputs (s, (long)stream); +} diff --git a/lib/stdio/getc.c b/lib/stdio/getc.c new file mode 100644 index 00000000..c32ff7a1 --- /dev/null +++ b/lib/stdio/getc.c @@ -0,0 +1,27 @@ +/* -*-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 +getc (FILE *stream) +{ + return fdgetc ((long)stream); +} diff --git a/lib/stdio/getchar.c b/lib/stdio/getchar.c new file mode 100644 index 00000000..111655dd --- /dev/null +++ b/lib/stdio/getchar.c @@ -0,0 +1,27 @@ +/* -*-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 +getchar () +{ + return fdgetc (g_stdin); +} diff --git a/lib/stdio/putc.c b/lib/stdio/putc.c new file mode 100644 index 00000000..4c585767 --- /dev/null +++ b/lib/stdio/putc.c @@ -0,0 +1,27 @@ +/* -*-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 +putc (int c, FILE* stream) +{ + return fdputc (c, (long)stream); +} diff --git a/lib/stdio/putchar.c b/lib/stdio/putchar.c new file mode 100644 index 00000000..602e430c --- /dev/null +++ b/lib/stdio/putchar.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 +putchar (int c) +{ + write (STDOUT, (char*)&c, 1); + return 0; +} diff --git a/lib/stdio/ungetc.c b/lib/stdio/ungetc.c new file mode 100644 index 00000000..a107a9f6 --- /dev/null +++ b/lib/stdio/ungetc.c @@ -0,0 +1,27 @@ +/* -*-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 +ungetc (int c, FILE *stream) +{ + return fdungetc (c, (long)stream); +} diff --git a/lib/stdlib/free.c b/lib/stdlib/free.c new file mode 100644 index 00000000..e63ac795 --- /dev/null +++ b/lib/stdlib/free.c @@ -0,0 +1,26 @@ +/* -*-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 +free (void *ptr) +{ +} diff --git a/lib/stdlib/getenv.c b/lib/stdlib/getenv.c new file mode 100644 index 00000000..fdf42f5e --- /dev/null +++ b/lib/stdlib/getenv.c @@ -0,0 +1,35 @@ +/* -*-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 + +char * +getenv (char const* s) +{ + char **p = environ; + int length = strlen (s); + while (*p) + { + if (!strncmp (s, *p, length) && *(*p + length) == '=') + return (*p + length + 1); + p++; + } + return 0; +} diff --git a/lib/stdlib/realloc.c b/lib/stdlib/realloc.c new file mode 100644 index 00000000..e8bd20a6 --- /dev/null +++ b/lib/stdlib/realloc.c @@ -0,0 +1,33 @@ +/* -*-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 * +realloc (void *ptr, size_t size) +{ + void *new = malloc (size); + if (ptr && new) + { + memcpy (new, ptr, size); + free (ptr); + } + return new; +} diff --git a/lib/stdlib/setenv.c b/lib/stdlib/setenv.c new file mode 100644 index 00000000..ecaac2c4 --- /dev/null +++ b/lib/stdlib/setenv.c @@ -0,0 +1,44 @@ +/* -*-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 +setenv (char const* s, char const* v, int overwrite_p) +{ + char **p = environ; + int length = strlen (s); + while (*p) + { + if (!strncmp (s, *p, length) && *(*p + length) == '=') + break; + p++; + } + char *entry = malloc (length + strlen (v) + 2); + int end_p = *p == 0; + *p = entry; + strcpy (entry, s); + strcpy (entry + length, "="); + strcpy (entry + length + 1, v); + *(entry + length + strlen (v) + 2) = 0; + if (end_p) + *++p = 0; + return 0; +} diff --git a/lib/string/strcmp.c b/lib/string/strcmp.c new file mode 100644 index 00000000..12e39233 --- /dev/null +++ b/lib/string/strcmp.c @@ -0,0 +1,32 @@ +/* -*-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 +strcmp (char const* a, char const* b) +{ + while (*a && *b && *a == *b) + { + a++; + b++; + } + return *a - *b; +} diff --git a/lib/string/strcpy.c b/lib/string/strcpy.c new file mode 100644 index 00000000..b0e696c2 --- /dev/null +++ b/lib/string/strcpy.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 + +char * +strcpy (char *dest, char const *src) +{ + char *p = dest; + while (*src) + *p++ = *src++; + *p = 0; + return dest; +} diff --git a/lib/string/strncmp.c b/lib/string/strncmp.c new file mode 100644 index 00000000..81ffd106 --- /dev/null +++ b/lib/string/strncmp.c @@ -0,0 +1,34 @@ +/* -*-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 +strncmp (char const* a, char const* b, size_t size) +{ + if (!size) + return 0; + while (*a && *b && *a == *b && --size) + { + a++; + b++; + } + return *a - *b; +}