mirror of https://github.com/ipxe/ipxe.git
parent
dc118c5369
commit
e965f179e1
|
@ -321,9 +321,9 @@ char * strstr ( const char *haystack, const char *needle ) {
|
||||||
*
|
*
|
||||||
* @v dest Destination string
|
* @v dest Destination string
|
||||||
* @v src Source string
|
* @v src Source string
|
||||||
* @ret dest Destination string
|
* @ret dnul Terminating NUL of destination string
|
||||||
*/
|
*/
|
||||||
char * strcpy ( char *dest, const char *src ) {
|
char * stpcpy ( char *dest, const char *src ) {
|
||||||
const uint8_t *src_bytes = ( ( const uint8_t * ) src );
|
const uint8_t *src_bytes = ( ( const uint8_t * ) src );
|
||||||
uint8_t *dest_bytes = ( ( uint8_t * ) dest );
|
uint8_t *dest_bytes = ( ( uint8_t * ) dest );
|
||||||
|
|
||||||
|
@ -333,6 +333,19 @@ char * strcpy ( char *dest, const char *src ) {
|
||||||
if ( ! *dest_bytes )
|
if ( ! *dest_bytes )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return ( ( char * ) dest_bytes );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy string
|
||||||
|
*
|
||||||
|
* @v dest Destination string
|
||||||
|
* @v src Source string
|
||||||
|
* @ret dest Destination string
|
||||||
|
*/
|
||||||
|
char * strcpy ( char *dest, const char *src ) {
|
||||||
|
|
||||||
|
stpcpy ( dest, src );
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ extern char * __pure strchr ( const char *src, int character ) __nonnull;
|
||||||
extern char * __pure strrchr ( const char *src, int character ) __nonnull;
|
extern char * __pure strrchr ( const char *src, int character ) __nonnull;
|
||||||
extern char * __pure strstr ( const char *haystack,
|
extern char * __pure strstr ( const char *haystack,
|
||||||
const char *needle ) __nonnull;
|
const char *needle ) __nonnull;
|
||||||
|
extern char * stpcpy ( char *dest, const char *src ) __nonnull;
|
||||||
extern char * strcpy ( char *dest, const char *src ) __nonnull;
|
extern char * strcpy ( char *dest, const char *src ) __nonnull;
|
||||||
extern char * strncpy ( char *dest, const char *src, size_t max ) __nonnull;
|
extern char * strncpy ( char *dest, const char *src, size_t max ) __nonnull;
|
||||||
extern char * strcat ( char *dest, const char *src ) __nonnull;
|
extern char * strcat ( char *dest, const char *src ) __nonnull;
|
||||||
|
|
|
@ -204,6 +204,24 @@ static void string_test_exec ( void ) {
|
||||||
free ( dup );
|
free ( dup );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Test stpcpy() */
|
||||||
|
{
|
||||||
|
const char longer[12] = "duplicateme";
|
||||||
|
const char shorter[6] = "hello";
|
||||||
|
char dest[12];
|
||||||
|
char *dnul;
|
||||||
|
|
||||||
|
dnul = stpcpy ( dest, longer );
|
||||||
|
ok ( *dnul == '\0' );
|
||||||
|
ok ( dnul == &dest[11] );
|
||||||
|
ok ( memcmp ( dest, longer, 12 ) == 0 );
|
||||||
|
dnul = stpcpy ( dest, shorter );
|
||||||
|
ok ( *dnul == '\0' );
|
||||||
|
ok ( dnul == &dest[5] );
|
||||||
|
ok ( memcmp ( dest, shorter, 6 ) == 0 );
|
||||||
|
ok ( memcmp ( ( dest + 6 ), ( longer + 6 ), 6 ) == 0 );
|
||||||
|
}
|
||||||
|
|
||||||
/* Test strcpy() */
|
/* Test strcpy() */
|
||||||
{
|
{
|
||||||
const char longer[7] = "copyme";
|
const char longer[7] = "copyme";
|
||||||
|
|
Loading…
Reference in New Issue