From 573896cc1cdc9c10e98a9ab7f1311ea7e9e0d7be Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 30 Jun 2018 13:11:03 +0200 Subject: [PATCH] core: Prepare for the Hurd. * lib/linux/libc.c: Move from lib/linux.c. * lib/linux/gcc.c: Move from lib/linux-gcc.c. * lib/linux/gnu.c: Move from lib/linux+gnu.c. * lib/linux/libc.c: Move from lib/linux.c. * lib/linux/mes.c: Move from lib/linux-mes.c. * lib/linux/mini-gcc.c: Move from lib/linux-mini-gcc.c. * lib/linux/mini-mes.c: Move from lib/linux-mini-mes.c. * lib/linux/tcc.c: Move from lib/linux+tcc.c. * lib/linux/crt0.c: Move from lib/crt0.c. * lib/linux/crt1.c: Move from lib/crt1.c. * lib/linux/crti.c: Move from lib/crti.c. * lib/linux/crtn.c: Move from lib/crtn.c. * build-aux/build-cc.sh: Update for new layout. * build-aux/build-cc32.sh: Likewise. * build-aux/build-mes.sh: Likewise. * build-aux/cc-mes.sh: Likewise. * build-aux/cc32-mes.sh: Likewise. * lib/string/argz-count.c: New file taken from GNU C Library, relicensed. * lib/string/argz-extract.c: New file taken from GNU C Library, relicensed. * include/argz.h: New file. * lib/string/memcpy.c: New file, extract from libc. * lib/assert/assert.c: Likewise. --- AUTHORS | 2 +- build-aux/build-cc32.sh | 8 +-- build-aux/build-mes.sh | 8 +-- build-aux/cc-mes.sh | 2 +- build-aux/cc32-mes.sh | 2 +- include/argz.h | 42 +++++++++++++++ include/errno.h | 3 ++ lib/assert/assert.c | 10 ++++ lib/binutils.c | 2 +- lib/libc+gnu.c | 14 ++++- lib/libc+tcc.c | 9 +++- lib/libc-mini.c | 42 +++++++-------- lib/libc.c | 62 ++++++---------------- lib/libg.c | 10 +++- lib/{ => linux}/crt0.c | 0 lib/{ => linux}/crt1.c | 0 lib/{ => linux}/crti.c | 0 lib/{ => linux}/crtn.c | 0 lib/{linux-gcc.c => linux/gcc.c} | 0 lib/{linux+gnu.c => linux/gnu.c} | 0 lib/linux/libc-mini.c | 43 +++++++++++++++ lib/{linux.c => linux/libc.c} | 12 +++++ lib/{linux-mes.c => linux/mes.c} | 0 lib/{linux-mini-gcc.c => linux/mini-gcc.c} | 0 lib/{linux-mini-mes.c => linux/mini-mes.c} | 0 lib/{linux+tcc.c => linux/tcc.c} | 0 lib/m4.c | 10 +--- lib/stdlib/abort.c | 29 ++++++++++ lib/{ => stdlib}/alloca.c | 0 lib/stdlib/malloc.c | 33 ++++++++++++ lib/string/argz-count.c | 44 +++++++++++++++ lib/string/argz-extract.c | 42 +++++++++++++++ lib/string/memcpy.c | 29 ++++++++++ 33 files changed, 363 insertions(+), 95 deletions(-) create mode 100644 include/argz.h create mode 100644 lib/assert/assert.c rename lib/{ => linux}/crt0.c (100%) rename lib/{ => linux}/crt1.c (100%) rename lib/{ => linux}/crti.c (100%) rename lib/{ => linux}/crtn.c (100%) rename lib/{linux-gcc.c => linux/gcc.c} (100%) rename lib/{linux+gnu.c => linux/gnu.c} (100%) create mode 100644 lib/linux/libc-mini.c rename lib/{linux.c => linux/libc.c} (95%) rename lib/{linux-mes.c => linux/mes.c} (100%) rename lib/{linux-mini-gcc.c => linux/mini-gcc.c} (100%) rename lib/{linux-mini-mes.c => linux/mini-mes.c} (100%) rename lib/{linux+tcc.c => linux/tcc.c} (100%) create mode 100644 lib/stdlib/abort.c rename lib/{ => stdlib}/alloca.c (100%) create mode 100644 lib/stdlib/malloc.c create mode 100644 lib/string/argz-count.c create mode 100644 lib/string/argz-extract.c create mode 100644 lib/string/memcpy.c diff --git a/AUTHORS b/AUTHORS index fdad0bd2..dad7087f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,7 +3,7 @@ Main author All files except the imported files listed below Jeremiah Orians -lib/libc.c (fopen) +lib/libc+tcc.c (fopen) scaffold/tests/98-fopen.c Han-Wen Nienhuys diff --git a/build-aux/build-cc32.sh b/build-aux/build-cc32.sh index bec1fdd3..3df24aa9 100755 --- a/build-aux/build-cc32.sh +++ b/build-aux/build-cc32.sh @@ -71,10 +71,10 @@ CC32_CFLAGS=${CC32_CFLAGS-" -Wno-incompatible-pointer-types "} -ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/crt0 -ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/crt1 -ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/crti -ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/crtn +ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/linux/crt0 +ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/linux/crt1 +ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/linux/crti +ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/linux/crtn ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libc-mini ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libc ARCHDIR=1 NOLINK=1 sh build-aux/cc32-mes.sh lib/libgetopt diff --git a/build-aux/build-mes.sh b/build-aux/build-mes.sh index cca170da..1461fdc1 100755 --- a/build-aux/build-mes.sh +++ b/build-aux/build-mes.sh @@ -105,10 +105,10 @@ if [ ! -d "$MES_SEED" ] \ fi MES_ARENA=100000000 -ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/crt0 -ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/crt1 -ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/crti -ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/crtn +ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/linux/crt0 +ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/linux/crt1 +ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/linux/crti +ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/linux/crtn ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/libc-mini ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/libc ARCHDIR=1 NOLINK=1 bash build-aux/cc-mes.sh lib/libgetopt diff --git a/build-aux/cc-mes.sh b/build-aux/cc-mes.sh index 25537608..079212f1 100755 --- a/build-aux/cc-mes.sh +++ b/build-aux/cc-mes.sh @@ -57,7 +57,7 @@ if [ -z "$ARCHDIR" ]; then p="mes-" else b=${c##*/} - d=${c%/*} + d=${c%%/*} o="$d/x86-mes/$b" mkdir -p $d/x86-mes fi diff --git a/build-aux/cc32-mes.sh b/build-aux/cc32-mes.sh index a6066a13..2ac327d9 100755 --- a/build-aux/cc32-mes.sh +++ b/build-aux/cc32-mes.sh @@ -63,7 +63,7 @@ if [ -z "$ARCHDIR" ]; then p="$a-" else b=${c##*/} - d=${c%/*} + d=${c%%/*} o="$d/$arch/$b" mkdir -p $d/$arch fi diff --git a/include/argz.h b/include/argz.h new file mode 100644 index 00000000..2904ee21 --- /dev/null +++ b/include/argz.h @@ -0,0 +1,42 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * 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. + * + * 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 Mes. If not, see . + */ +#ifndef __MES_ARGZ_H +#define __MES_ARGZ_H 1 + +#if WITH_GLIBC +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#undef __MES_ARGZ_H +#include_next + +#else // ! WITH_GLIBC + +#ifndef libc_hidden_def +#define libc_hidden_def(x) +#define weak_alias(x,y) +#endif + +size_t __argz_count (char const *argz, size_t len); +void __argz_extract (char const *argz, size_t len, char **argv); + +#endif // ! WITH_GLIBC + +#endif // __MES_ARGZ_H diff --git a/include/errno.h b/include/errno.h index 49c515c7..78ceabe7 100644 --- a/include/errno.h +++ b/include/errno.h @@ -27,6 +27,9 @@ #undef __MES_ERRNO_H #include_next #else // ! WITH_GLIBC + +typedef int error_t; + int errno; #define ENOENT 2 #define EINTR 4 diff --git a/lib/assert/assert.c b/lib/assert/assert.c new file mode 100644 index 00000000..c72177bd --- /dev/null +++ b/lib/assert/assert.c @@ -0,0 +1,10 @@ +void +assert_fail (char* s) +{ + eputs ("assert fail: "); + eputs (s); + eputs ("\n"); + char *fail = s; + fail = 0; + *fail = 0; +} diff --git a/lib/binutils.c b/lib/binutils.c index f05869e3..857b2ff6 100644 --- a/lib/binutils.c +++ b/lib/binutils.c @@ -244,7 +244,7 @@ sbrk (intptr_t delta) { if (delta >= 0) return malloc (delta); - return g_brk; + return __brk; } // binutils 2.30 diff --git a/lib/libc+gnu.c b/lib/libc+gnu.c index abdedd34..98160b0b 100644 --- a/lib/libc+gnu.c +++ b/lib/libc+gnu.c @@ -19,9 +19,19 @@ */ #include -#include + +#if __GNU__ +#include +#elif __linux__ +#include +#else +#error both __GNU__ and _linux__ are undefined, choose one +#endif + #include #include #include -#include +#if !__GNU__ +#include +#endif #include diff --git a/lib/libc+tcc.c b/lib/libc+tcc.c index 9ae88558..877fed81 100644 --- a/lib/libc+tcc.c +++ b/lib/libc+tcc.c @@ -36,7 +36,14 @@ #include #include -#include + +#if __GNU__ +#include +#elif __linux__ +#include +#else +#error both __GNU__ and _linux__ are undefined, choose one +#endif #if __MESC__ diff --git a/lib/libc-mini.c b/lib/libc-mini.c index 2e9539ce..aa7a2b5c 100644 --- a/lib/libc-mini.c +++ b/lib/libc-mini.c @@ -20,17 +20,29 @@ #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); @@ -65,15 +77,13 @@ puts (char const* s) return oputs ("\n"); } -#if __MESC__ - -#include - -#else // !__MESC__ - -#include - -#endif // !__MESC__ +#if __GNU__ +#include +#elif __linux__ +#include +#else +#error both __GNU__ and _linux__ are undefined, choose one +#endif void (*__call_at_exit) (void); @@ -84,17 +94,3 @@ exit (int code) (*__call_at_exit) (); _exit (code); } - -ssize_t -write (int filedes, void const *buffer, size_t size) -{ - int r = _write (filedes, buffer, size); - if (r < 0) - { - errno = -r; - r = -1; - } - else - errno = 0; - return r; -} diff --git a/lib/libc.c b/lib/libc.c index 4c53ba2c..3efe18e6 100644 --- a/lib/libc.c +++ b/lib/libc.c @@ -29,21 +29,16 @@ #include #include -#if __MESC__ - -#include - -#else // !__MESC__ - -#include - -#include - -#endif // !__MESC__ - #include #include -#include + +#if __GNU__ +#include +#elif __linux__ +#include +#else +#error both __GNU__ and _linux__ are undefined, choose one +#endif int g_stdin = 0; @@ -63,6 +58,13 @@ __mes_debug () return __mes_debug; } + +#if !___GNU__ +#include +#include +#include +#endif + int getchar () { @@ -94,17 +96,6 @@ putc (int c, FILE* stream) return fdputc (c, (int)stream); } -void -assert_fail (char* s) -{ - eputs ("assert fail: "); - eputs (s); - eputs ("\n"); - char *fail = s; - fail = 0; - *fail = 0; -} - int getc (FILE *stream) { @@ -147,29 +138,6 @@ strcpy (char *dest, char const *src) return dest; } -char *g_brk = 0; - -void * -malloc (size_t size) -{ - if (!g_brk) - g_brk = brk (0); - if (brk (g_brk + size) == (void*)-1) - return 0; - char *p = g_brk; - g_brk += size; - return p; -} - -void * -memcpy (void *dest, void const *src, size_t n) -{ - char* p = dest; - char const* q = src; - while (n--) *p++ = *q++; - return dest; -} - void * realloc (void *ptr, size_t size) { diff --git a/lib/libg.c b/lib/libg.c index b892ca06..7628c8b6 100644 --- a/lib/libg.c +++ b/lib/libg.c @@ -37,7 +37,15 @@ #define sscanf _sscanf #include -#include + +#if __GNU__ +#include +#elif __linux__ +#include +#else +#error both __GNU__ and _linux__ are undefined, choose one +#endif + #include #include #include diff --git a/lib/crt0.c b/lib/linux/crt0.c similarity index 100% rename from lib/crt0.c rename to lib/linux/crt0.c diff --git a/lib/crt1.c b/lib/linux/crt1.c similarity index 100% rename from lib/crt1.c rename to lib/linux/crt1.c diff --git a/lib/crti.c b/lib/linux/crti.c similarity index 100% rename from lib/crti.c rename to lib/linux/crti.c diff --git a/lib/crtn.c b/lib/linux/crtn.c similarity index 100% rename from lib/crtn.c rename to lib/linux/crtn.c diff --git a/lib/linux-gcc.c b/lib/linux/gcc.c similarity index 100% rename from lib/linux-gcc.c rename to lib/linux/gcc.c diff --git a/lib/linux+gnu.c b/lib/linux/gnu.c similarity index 100% rename from lib/linux+gnu.c rename to lib/linux/gnu.c diff --git a/lib/linux/libc-mini.c b/lib/linux/libc-mini.c new file mode 100644 index 00000000..cd9e2d88 --- /dev/null +++ b/lib/linux/libc-mini.c @@ -0,0 +1,43 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * 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. + * + * 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 Mes. If not, see . + */ + +#if __MESC__ + +#include + +#else // !__MESC__ + +#include + +#endif // !__MESC__ + +ssize_t +write (int filedes, void const *buffer, size_t size) +{ + int r = _write (filedes, buffer, size); + if (r < 0) + { + errno = -r; + r = -1; + } + else + errno = 0; + return r; +} diff --git a/lib/linux.c b/lib/linux/libc.c similarity index 95% rename from lib/linux.c rename to lib/linux/libc.c index 454aa7b2..0b6ad18f 100644 --- a/lib/linux.c +++ b/lib/linux/libc.c @@ -38,6 +38,18 @@ #define SYS_ioctl 0x36 #define SYS_fsync 0x76 +#if __MESC__ + +#include + +#else // !__MESC__ + +#include + +#include + +#endif // !__MESC__ + int fork () { diff --git a/lib/linux-mes.c b/lib/linux/mes.c similarity index 100% rename from lib/linux-mes.c rename to lib/linux/mes.c diff --git a/lib/linux-mini-gcc.c b/lib/linux/mini-gcc.c similarity index 100% rename from lib/linux-mini-gcc.c rename to lib/linux/mini-gcc.c diff --git a/lib/linux-mini-mes.c b/lib/linux/mini-mes.c similarity index 100% rename from lib/linux-mini-mes.c rename to lib/linux/mini-mes.c diff --git a/lib/linux+tcc.c b/lib/linux/tcc.c similarity index 100% rename from lib/linux+tcc.c rename to lib/linux/tcc.c diff --git a/lib/m4.c b/lib/m4.c index b9c79ac0..f29a4c73 100644 --- a/lib/m4.c +++ b/lib/m4.c @@ -20,15 +20,7 @@ #include -int -abort () -{ - static int stub = 0; - if (__mes_debug () && !stub) - eputs ("abort stub\n"); - stub = 1; - return 0; -} +#include "stdlib/abort.c" int atof (int x) diff --git a/lib/stdlib/abort.c b/lib/stdlib/abort.c new file mode 100644 index 00000000..2231c516 --- /dev/null +++ b/lib/stdlib/abort.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * 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. + * + * 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 Mes. If not, see . + */ + +void +abort (void) +{ +#if __i386__ + asm ("hlt"); +#else + asm ("break 0"); +#endif +} diff --git a/lib/alloca.c b/lib/stdlib/alloca.c similarity index 100% rename from lib/alloca.c rename to lib/stdlib/alloca.c diff --git a/lib/stdlib/malloc.c b/lib/stdlib/malloc.c new file mode 100644 index 00000000..ca15261d --- /dev/null +++ b/lib/stdlib/malloc.c @@ -0,0 +1,33 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * 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. + * + * 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 Mes. If not, see . + */ + +char *__brk = 0; + +void * +malloc (size_t size) +{ + if (!__brk) + __brk = brk (0); + if (brk (__brk + size) == (void*)-1) + return 0; + char *p = __brk; + __brk += size; + return p; +} diff --git a/lib/string/argz-count.c b/lib/string/argz-count.c new file mode 100644 index 00000000..2cd01752 --- /dev/null +++ b/lib/string/argz-count.c @@ -0,0 +1,44 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright (C) 1995-2018 Free Software Foundation, Inc. + * + * 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 . + */ + +/* Taken from GNU C Library + * Routines for dealing with '\0' separated arg vectors. + * Written by Miles Bader +*/ + +#include +#include + +/* Returns the number of strings in ARGZ. */ +size_t +__argz_count (const char *argz, size_t len) +{ + size_t count = 0; + while (len > 0) + { + size_t part_len = strlen(argz); + argz += part_len + 1; + len -= part_len + 1; + count++; + } + return count; +} +libc_hidden_def (__argz_count) +weak_alias (__argz_count, argz_count) diff --git a/lib/string/argz-extract.c b/lib/string/argz-extract.c new file mode 100644 index 00000000..163a2750 --- /dev/null +++ b/lib/string/argz-extract.c @@ -0,0 +1,42 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright (C) 1995-2018 Free Software Foundation, Inc. + * + * 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 . + */ + +/* Taken from GNU C Library + * Routines for dealing with '\0' separated arg vectors. + * Written by Miles Bader +*/ + +#include + +/* Puts pointers to each string in ARGZ, plus a terminating 0 element, into + ARGV, which must be large enough to hold them all. */ +void +__argz_extract (const char *argz, size_t len, char **argv) +{ + while (len > 0) + { + size_t part_len = strlen (argz); + *argv++ = (char *) argz; + argz += part_len + 1; + len -= part_len + 1; + } + *argv = 0; +} +weak_alias (__argz_extract, argz_extract) diff --git a/lib/string/memcpy.c b/lib/string/memcpy.c new file mode 100644 index 00000000..330311f3 --- /dev/null +++ b/lib/string/memcpy.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * Mes --- Maxwell Equations of Software + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * + * This file is part of Mes. + * + * 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. + * + * 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 Mes. If not, see . + */ + +void * +memcpy (void *dest, void const *src, size_t n) +{ + char* p = dest; + char const* q = src; + while (n--) + *p++ = *q++; + return dest; +}