1/*
2 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
3 * Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org>
4 *
5 *	This program is free software; you can redistribute it and/or modify it
6 *	under the terms of the GNU General Public License as published by the
7 *	Free Software Foundation version 2 of the License.
8 *
9 *	This program is distributed in the hope that it will be useful, but
10 *	WITHOUT ANY WARRANTY; without even the implied warranty of
11 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 *	General Public License for more details.
13 *
14 *	You should have received a copy of the GNU General Public License along
15 *	with this program; if not, write to the Free Software Foundation, Inc.,
16 *	51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 */
19
20#include <stdlib.h>
21#include <stdio.h>
22#include <string.h>
23#include <ctype.h>
24#include <fcntl.h>
25#include <errno.h>
26#include <sys/types.h>
27
28#include "udev.h"
29
30#ifdef __GLIBC__
31size_t strlcpy(char *dst, const char *src, size_t size)
32{
33	size_t bytes = 0;
34	char *q = dst;
35	const char *p = src;
36	char ch;
37
38	while ((ch = *p++)) {
39		if (bytes+1 < size)
40			*q++ = ch;
41		bytes++;
42	}
43
44	/* If size == 0 there is no space for a final null... */
45	if (size)
46		*q = '\0';
47	return bytes;
48}
49
50size_t strlcat(char *dst, const char *src, size_t size)
51{
52	size_t bytes = 0;
53	char *q = dst;
54	const char *p = src;
55	char ch;
56
57	while (bytes < size && *q) {
58		q++;
59		bytes++;
60	}
61	if (bytes == size)
62		return (bytes + strlen(src));
63
64	while ((ch = *p++)) {
65		if (bytes+1 < size)
66		*q++ = ch;
67		bytes++;
68	}
69
70	*q = '\0';
71	return bytes;
72}
73#endif /* __GLIBC__ */
74