2004-02-24 04:29:32 +01:00
|
|
|
/*
|
2006-08-16 02:04:04 +02:00
|
|
|
* udev_sysdeps.c - wrapping of libc features and kernel defines
|
2004-02-24 04:29:32 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
|
2006-08-16 02:04:04 +02:00
|
|
|
* Copyright (C) 2005-2006 Kay Sievers <kay.sievers@vrfy.org>
|
2004-02-24 04:29:32 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
2003-10-23 08:48:55 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2004-02-24 04:29:32 +01:00
|
|
|
#include <stdio.h>
|
2003-10-23 08:48:55 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2004-03-02 07:42:30 +01:00
|
|
|
#include <fcntl.h>
|
2006-02-15 21:12:49 +01:00
|
|
|
#include <errno.h>
|
2003-11-24 05:44:41 +01:00
|
|
|
#include <sys/types.h>
|
2004-02-24 04:29:32 +01:00
|
|
|
|
2005-03-18 09:27:31 +01:00
|
|
|
#include "udev.h"
|
2004-02-24 04:29:32 +01:00
|
|
|
|
2005-03-27 12:39:12 +02:00
|
|
|
#ifdef __GLIBC__
|
2005-03-07 04:29:43 +01:00
|
|
|
size_t strlcpy(char *dst, const char *src, size_t size)
|
|
|
|
{
|
|
|
|
size_t bytes = 0;
|
|
|
|
char *q = dst;
|
|
|
|
const char *p = src;
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
while ((ch = *p++)) {
|
2005-03-27 12:39:12 +02:00
|
|
|
if (bytes+1 < size)
|
2005-03-07 04:29:43 +01:00
|
|
|
*q++ = ch;
|
|
|
|
bytes++;
|
|
|
|
}
|
|
|
|
|
2005-03-29 03:53:45 +02:00
|
|
|
/* If size == 0 there is no space for a final null... */
|
2005-03-28 00:18:49 +02:00
|
|
|
if (size)
|
|
|
|
*q = '\0';
|
2005-03-29 03:53:45 +02:00
|
|
|
|
2005-03-07 04:29:43 +01:00
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t strlcat(char *dst, const char *src, size_t size)
|
|
|
|
{
|
|
|
|
size_t bytes = 0;
|
|
|
|
char *q = dst;
|
|
|
|
const char *p = src;
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
while (bytes < size && *q) {
|
|
|
|
q++;
|
|
|
|
bytes++;
|
|
|
|
}
|
2005-03-27 12:39:12 +02:00
|
|
|
if (bytes == size)
|
|
|
|
return (bytes + strlen(src));
|
2005-03-06 06:16:52 +01:00
|
|
|
|
2005-03-07 04:29:43 +01:00
|
|
|
while ((ch = *p++)) {
|
2005-03-27 12:39:12 +02:00
|
|
|
if (bytes+1 < size)
|
2005-03-07 04:29:43 +01:00
|
|
|
*q++ = ch;
|
|
|
|
bytes++;
|
|
|
|
}
|
|
|
|
|
2005-03-29 03:53:45 +02:00
|
|
|
*q = '\0';
|
2005-03-07 04:29:43 +01:00
|
|
|
return bytes;
|
|
|
|
}
|
2006-08-20 18:25:57 +02:00
|
|
|
#endif /* __GLIBC__ */
|