1 /* bcopy.c -- copy memory. 2 3 Copyright (C) 1992-2021 Free Software Foundation, Inc. 4 5 This file is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published 7 by the Free Software Foundation; either version 3 of the License, 8 or (at your option) any later version. 9 10 This file is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ 17 18 /* Written by David MacKenzie <djm@gnu.ai.mit.edu>. */ 19 20 #include <config.h> 21 22 #include <stddef.h> 23 24 /* Copy LENGTH bytes from SOURCE to DEST. Does not null-terminate. */ 25 26 void 27 bcopy (void const *source0, void *dest0, size_t length) /* */ 28 { 29 char const *source = source0; 30 char *dest = dest0; 31 if (source < dest) 32 /* Moving from low mem to hi mem; start at end. */ 33 for (source += length, dest += length; length; --length) 34 *--dest = *--source; 35 else if (source != dest) 36 /* Moving from hi mem to low mem; start at beginning. */ 37 for (; length; --length) 38 *dest++ = *source++; 39 }