xref: /illumos-gate/usr/src/lib/libfakekernel/common/copy.c (revision 45ede40b2394db7967e59f19288fae9b62efd4aa)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
14  */
15 
16 
17 #include <sys/types.h>
18 #include <sys/time.h>
19 #include <sys/systm.h>
20 #include <sys/errno.h>
21 
22 int
23 copyin(const void *u, void *k, size_t s)
24 {
25 	bcopy(u, k, s);
26 	return (0);
27 }
28 
29 int
30 copyout(const void *k, void *u, size_t s)
31 {
32 	bcopy(k, u, s);
33 	return (0);
34 }
35 
36 int
37 copyinstr(const char *src, char *dst, size_t max_len, size_t *copied)
38 {
39 	return (copystr(src, dst, max_len, copied));
40 }
41 
42 int
43 copystr(const char *src, char *dst, size_t max_len, size_t *outlen)
44 {
45 	size_t copied;
46 
47 	if (max_len == 0)
48 		return (ENAMETOOLONG);
49 
50 	copied = strlcpy(dst, src, max_len) + 1;
51 	if (copied >= max_len)
52 		return (ENAMETOOLONG);
53 
54 	if (outlen != NULL)
55 		*outlen = copied;
56 
57 	return (0);
58 }
59 
60 void
61 ovbcopy(const void *src, void *dst, size_t len)
62 {
63 	(void) memmove(dst, src, len);
64 }
65 
66 /* ARGSUSED */
67 int
68 ddi_copyin(const void *buf, void *kernbuf, size_t size, int flags)
69 {
70 	return (copyin(buf, kernbuf, size));
71 }
72 
73 /* ARGSUSED */
74 int
75 ddi_copyout(const void *buf, void *kernbuf, size_t size, int flags)
76 {
77 	return (copyout(buf, kernbuf, size));
78 }
79