aboutsummaryrefslogtreecommitdiff
path: root/arch/microblaze/lib/uaccess.c
blob: 8eb9df5a26c9f53ad53a298330039e1e88898295 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * Copyright (C) 2006 Atmark Techno, Inc.
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */

#include <linux/string.h>
#include <asm/uaccess.h>

#include <asm/bug.h>

long strnlen_user(const char __user *src, long count)
{
	return strlen(src) + 1;
}

#define __do_strncpy_from_user(dst, src, count, res)			\
	do {								\
		char *tmp;						\
		strncpy(dst, src, count);				\
		for (tmp = dst; *tmp && count > 0; tmp++, count--)	\
			;						\
		res = (tmp - dst);					\
	} while (0)

long __strncpy_from_user(char *dst, const char __user *src, long count)
{
	long res;
	__do_strncpy_from_user(dst, src, count, res);
	return res;
}

long strncpy_from_user(char *dst, const char __user *src, long count)
{
	long res = -EFAULT;
	if (access_ok(VERIFY_READ, src, 1))
		__do_strncpy_from_user(dst, src, count, res);
	return res;
}