2005-09-30 21:13:37 +04:00
/*
* Copyright ( C ) 2005 by Volker Lendecke
*
* Test harness for sprintf_append
*/
# include "includes.h"
2011-10-26 10:21:04 +04:00
# include "torture/proto.h"
2005-09-30 21:13:37 +04:00
2011-10-26 10:21:04 +04:00
bool run_local_sprintf_append ( int dummy )
2005-09-30 21:13:37 +04:00
{
TALLOC_CTX * mem_ctx ;
char * string = NULL ;
2011-10-26 10:13:16 +04:00
ssize_t len = 0 ;
size_t bufsize = 4 ;
2005-09-30 21:13:37 +04:00
int i ;
mem_ctx = talloc_init ( " t_strappend " ) ;
if ( mem_ctx = = NULL ) {
fprintf ( stderr , " talloc_init failed \n " ) ;
2011-10-26 10:21:04 +04:00
return false ;
2005-09-30 21:13:37 +04:00
}
sprintf_append ( mem_ctx , & string , & len , & bufsize , " " ) ;
assert ( strlen ( string ) = = len ) ;
sprintf_append ( mem_ctx , & string , & len , & bufsize , " " ) ;
assert ( strlen ( string ) = = len ) ;
sprintf_append ( mem_ctx , & string , & len , & bufsize ,
" 01234567890123456789012345678901234567890123456789 \n " ) ;
assert ( strlen ( string ) = = len ) ;
2011-10-26 10:13:36 +04:00
for ( i = 0 ; i < ( 10000 ) ; i + + ) {
2005-09-30 21:13:37 +04:00
if ( i % 1000 = = 0 ) {
2011-10-26 10:13:16 +04:00
printf ( " %d %lld \r " , i , ( long long int ) bufsize ) ;
2005-09-30 21:13:37 +04:00
fflush ( stdout ) ;
}
sprintf_append ( mem_ctx , & string , & len , & bufsize , " %d \n " , i ) ;
2011-10-26 10:21:04 +04:00
if ( strlen ( string ) ! = len ) {
fprintf ( stderr , " sprintf_append failed: strlen(string) %lld != len %lld \n " ,
( long long int ) strlen ( string ) , ( long long int ) len ) ;
return false ;
}
2005-09-30 21:13:37 +04:00
}
talloc_destroy ( mem_ctx ) ;
2011-10-26 10:21:04 +04:00
return true ;
2005-09-30 21:13:37 +04:00
}