155714Skris/*- 255714Skris * Copyright (c) 2014 Andrew Turner 355714Skris * All rights reserved. 455714Skris * 555714Skris * Redistribution and use in source and binary forms, with or without 655714Skris * modification, are permitted provided that the following conditions 755714Skris * are met: 8296465Sdelphij * 1. Redistributions of source code must retain the above copyright 955714Skris * notice, this list of conditions and the following disclaimer. 1055714Skris * 2. Redistributions in binary form must reproduce the above copyright 1155714Skris * notice, this list of conditions and the following disclaimer in the 1255714Skris * documentation and/or other materials provided with the distribution. 1355714Skris * 1455714Skris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15296465Sdelphij * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1655714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1755714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1855714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1955714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2055714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2155714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22296465Sdelphij * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2355714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2455714Skris * SUCH DAMAGE. 2555714Skris */ 2655714Skris 2755714Skris#include <sys/cdefs.h> 2855714Skris__FBSDID("$FreeBSD$"); 2955714Skris 3055714Skris#include <sys/param.h> 3155714Skris#include <sys/systm.h> 3255714Skris 3355714Skrisint 3455714Skriscopystr(const void * __restrict kfaddr, void * __restrict kdaddr, size_t len, 3555714Skris size_t * __restrict lencopied) 3655714Skris{ 37296465Sdelphij const char *src; 3855714Skris size_t pos; 3955714Skris char *dst; 40296465Sdelphij int error; 4155714Skris 4255714Skris error = ENAMETOOLONG; 4355714Skris src = kfaddr; 4455714Skris dst = kdaddr; 4555714Skris for (pos = 0; pos < len; pos++) { 4655714Skris dst[pos] = src[pos]; 4755714Skris if (src[pos] == '\0') { 4855714Skris /* Increment pos to hold the number of bytes copied */ 4955714Skris pos++; 5055714Skris error = 0; 5155714Skris break; 52296465Sdelphij } 5355714Skris } 5455714Skris 5555714Skris if (lencopied != NULL) 5655714Skris *lencopied = pos; 5755714Skris 5855714Skris return (error); 5955714Skris} 6055714Skris