Commit | Line | Data |
---|---|---|
2660663f MS |
1 | /* |
2 | * Copyright (C) 2006 Atmark Techno, Inc. | |
3 | * | |
4 | * This file is subject to the terms and conditions of the GNU General Public | |
5 | * License. See the file "COPYING" in the main directory of this archive | |
6 | * for more details. | |
7 | */ | |
8 | ||
9 | #include <linux/string.h> | |
10 | #include <asm/uaccess.h> | |
11 | ||
12 | #include <asm/bug.h> | |
13 | ||
14 | long strnlen_user(const char __user *src, long count) | |
15 | { | |
16 | return strlen(src) + 1; | |
17 | } | |
18 | ||
19 | #define __do_strncpy_from_user(dst, src, count, res) \ | |
20 | do { \ | |
21 | char *tmp; \ | |
22 | strncpy(dst, src, count); \ | |
23 | for (tmp = dst; *tmp && count > 0; tmp++, count--) \ | |
24 | ; \ | |
25 | res = (tmp - dst); \ | |
26 | } while (0) | |
27 | ||
28 | long __strncpy_from_user(char *dst, const char __user *src, long count) | |
29 | { | |
30 | long res; | |
31 | __do_strncpy_from_user(dst, src, count, res); | |
32 | return res; | |
33 | } | |
34 | ||
35 | long strncpy_from_user(char *dst, const char __user *src, long count) | |
36 | { | |
37 | long res = -EFAULT; | |
38 | if (access_ok(VERIFY_READ, src, 1)) | |
39 | __do_strncpy_from_user(dst, src, count, res); | |
40 | return res; | |
41 | } |