2004-02-24 06:29:32 +03:00
/*
* Copyright ( C ) 2003 Greg Kroah - Hartman < greg @ kroah . com >
2006-08-16 04:04:04 +04:00
* Copyright ( C ) 2005 - 2006 Kay Sievers < kay . sievers @ vrfy . org >
2004-02-24 06:29:32 +03: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 . ,
2006-08-28 02:29:11 +04:00
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2004-02-24 06:29:32 +03:00
*
*/
2003-10-23 10:48:55 +04:00
# include <stdlib.h>
2004-02-24 06:29:32 +03:00
# include <stdio.h>
2003-10-23 10:48:55 +04:00
# include <string.h>
# include <ctype.h>
2004-03-02 09:42:30 +03:00
# include <fcntl.h>
2006-02-15 23:12:49 +03:00
# include <errno.h>
2003-11-24 07:44:41 +03:00
# include <sys/types.h>
2004-02-24 06:29:32 +03:00
2005-03-18 11:27:31 +03:00
# include "udev.h"
2004-02-24 06:29:32 +03:00
2005-03-27 14:39:12 +04:00
# ifdef __GLIBC__
2005-03-07 06:29:43 +03: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 14:39:12 +04:00
if ( bytes + 1 < size )
2005-03-07 06:29:43 +03:00
* q + + = ch ;
bytes + + ;
}
2005-03-29 05:53:45 +04:00
/* If size == 0 there is no space for a final null... */
2005-03-28 02:18:49 +04:00
if ( size )
* q = ' \0 ' ;
2005-03-07 06:29:43 +03: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 14:39:12 +04:00
if ( bytes = = size )
return ( bytes + strlen ( src ) ) ;
2005-03-06 08:16:52 +03:00
2005-03-07 06:29:43 +03:00
while ( ( ch = * p + + ) ) {
2005-03-27 14:39:12 +04:00
if ( bytes + 1 < size )
2005-03-07 06:29:43 +03:00
* q + + = ch ;
bytes + + ;
}
2005-03-29 05:53:45 +04:00
* q = ' \0 ' ;
2005-03-07 06:29:43 +03:00
return bytes ;
}
2006-08-20 20:25:57 +04:00
# endif /* __GLIBC__ */