winebuild: Copy the strmake function from winegcc to simplify string formatting.
This commit is contained in:
parent
a4704d3d14
commit
84f4046481
|
@ -199,6 +199,7 @@ extern void *xrealloc (void *ptr, size_t size);
|
|||
extern char *xstrdup( const char *str );
|
||||
extern char *strupper(char *s);
|
||||
extern int strendswith(const char* str, const char* end);
|
||||
extern char *strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2 )));
|
||||
extern DECLSPEC_NORETURN void fatal_error( const char *msg, ... )
|
||||
__attribute__ ((__format__ (__printf__, 1, 2)));
|
||||
extern DECLSPEC_NORETURN void fatal_perror( const char *msg, ... )
|
||||
|
|
|
@ -193,8 +193,7 @@ static char *try_library_path( const char *path, const char *name )
|
|||
char *buffer;
|
||||
int fd;
|
||||
|
||||
buffer = xmalloc( strlen(path) + strlen(name) + 9 );
|
||||
sprintf( buffer, "%s/lib%s.def", path, name );
|
||||
buffer = strmake( "%s/lib%s.def", path, name );
|
||||
|
||||
/* check if the file exists */
|
||||
if ((fd = open( buffer, O_RDONLY )) != -1)
|
||||
|
@ -564,8 +563,7 @@ void read_undef_symbols( DLLSPEC *spec, char **argv )
|
|||
|
||||
name = ldcombine_files( spec, argv );
|
||||
|
||||
cmd = xmalloc( strlen(prog) + strlen(name) + 5 );
|
||||
sprintf( cmd, "%s -u %s", prog, name );
|
||||
cmd = strmake( "%s -u %s", prog, name );
|
||||
if (!(f = popen( cmd, "r" )))
|
||||
fatal_error( "Cannot execute '%s'\n", cmd );
|
||||
|
||||
|
@ -1188,9 +1186,9 @@ static void output_external_link_imports( DLLSPEC *spec )
|
|||
|
||||
for (i = pos = 0; i < ext_link_imports.count; i++)
|
||||
{
|
||||
char buffer[256];
|
||||
sprintf( buffer, "__wine_spec_ext_link_%s", ext_link_imports.names[i] );
|
||||
char *buffer = strmake( "__wine_spec_ext_link_%s", ext_link_imports.names[i] );
|
||||
output_import_thunk( buffer, ".L__wine_spec_external_links", pos );
|
||||
free( buffer );
|
||||
pos += get_ptr_size();
|
||||
}
|
||||
output_function_size( "__wine_spec_external_link_thunks" );
|
||||
|
|
|
@ -195,14 +195,15 @@ static void output_resident_name( const char *string, int ordinal )
|
|||
*/
|
||||
static const char *get_callfrom16_name( const ORDDEF *odp )
|
||||
{
|
||||
static char buffer[80];
|
||||
static char *buffer;
|
||||
|
||||
sprintf( buffer, "%s_%s_%s",
|
||||
(odp->type == TYPE_PASCAL) ? "p" :
|
||||
(odp->type == TYPE_VARARGS) ? "v" : "c",
|
||||
(odp->flags & FLAG_REGISTER) ? "regs" :
|
||||
(odp->flags & FLAG_RET16) ? "word" : "long",
|
||||
odp->u.func.arg_types );
|
||||
free( buffer );
|
||||
buffer = strmake( "%s_%s_%s",
|
||||
(odp->type == TYPE_PASCAL) ? "p" :
|
||||
(odp->type == TYPE_VARARGS) ? "v" : "c",
|
||||
(odp->flags & FLAG_REGISTER) ? "regs" :
|
||||
(odp->flags & FLAG_RET16) ? "word" : "long",
|
||||
odp->u.func.arg_types );
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -301,13 +302,13 @@ static int get_function_argsize( const ORDDEF *odp )
|
|||
*/
|
||||
static void output_call16_function( ORDDEF *odp )
|
||||
{
|
||||
char name[256];
|
||||
char *name;
|
||||
int i, pos, stack_words;
|
||||
const char *args = odp->u.func.arg_types;
|
||||
int argsize = get_function_argsize( odp );
|
||||
int needs_ldt = strchr( args, 'p' ) || strchr( args, 't' );
|
||||
|
||||
sprintf( name, ".L__wine_spec_call16_%s", get_relay_name(odp) );
|
||||
name = strmake( ".L__wine_spec_call16_%s", get_relay_name(odp) );
|
||||
|
||||
output( "\t.align %d\n", get_alignment(4) );
|
||||
output( "\t%s\n", func_declaration(name) );
|
||||
|
@ -406,6 +407,7 @@ static void output_call16_function( ORDDEF *odp )
|
|||
output( "\tret\n" );
|
||||
output_cfi( ".cfi_endproc" );
|
||||
output_function_size( name );
|
||||
free( name );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -119,6 +119,25 @@ int strendswith(const char* str, const char* end)
|
|||
return l >= m && strcmp(str + l - m, end) == 0;
|
||||
}
|
||||
|
||||
char *strmake( const char* fmt, ... )
|
||||
{
|
||||
int n;
|
||||
size_t size = 100;
|
||||
va_list ap;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
char *p = xmalloc( size );
|
||||
va_start( ap, fmt );
|
||||
n = vsnprintf( p, size, fmt, ap );
|
||||
va_end( ap );
|
||||
if (n == -1) size *= 2;
|
||||
else if ((size_t)n >= size) size = n + 1;
|
||||
else return p;
|
||||
free( p );
|
||||
}
|
||||
}
|
||||
|
||||
void fatal_error( const char *msg, ... )
|
||||
{
|
||||
va_list valist;
|
||||
|
@ -210,14 +229,7 @@ char *find_tool( const char *name, const char * const *names )
|
|||
unsigned int i, len;
|
||||
struct stat st;
|
||||
|
||||
if (target_alias)
|
||||
{
|
||||
file = xmalloc( strlen(target_alias) + strlen(name) + 2 );
|
||||
strcpy( file, target_alias );
|
||||
strcat( file, "-" );
|
||||
strcat( file, name );
|
||||
return file;
|
||||
}
|
||||
if (target_alias) return strmake( "%s-%s", target_alias, name );
|
||||
|
||||
if (!dirs)
|
||||
{
|
||||
|
@ -548,10 +560,7 @@ FILE *open_input_file( const char *srcdir, const char *name )
|
|||
|
||||
if (!file && srcdir)
|
||||
{
|
||||
fullname = xmalloc( strlen(srcdir) + strlen(name) + 2 );
|
||||
strcpy( fullname, srcdir );
|
||||
strcat( fullname, "/" );
|
||||
strcat( fullname, name );
|
||||
fullname = strmake( "%s/%s", srcdir, name );
|
||||
file = fopen( fullname, "r" );
|
||||
}
|
||||
else fullname = xstrdup( name );
|
||||
|
@ -708,16 +717,19 @@ const char *make_c_identifier( const char *str )
|
|||
*/
|
||||
const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec )
|
||||
{
|
||||
static char buffer[256];
|
||||
static char *buffer;
|
||||
|
||||
free( buffer );
|
||||
if (odp->name || odp->export_name)
|
||||
{
|
||||
char *p;
|
||||
sprintf( buffer, "__wine_stub_%s", odp->name ? odp->name : odp->export_name );
|
||||
buffer = strmake( "__wine_stub_%s", odp->name ? odp->name : odp->export_name );
|
||||
/* make sure name is a legal C identifier */
|
||||
for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
|
||||
if (!*p) return buffer;
|
||||
free( buffer );
|
||||
}
|
||||
sprintf( buffer, "__wine_stub_%s_%d", make_c_identifier(spec->file_name), odp->ordinal );
|
||||
buffer = strmake( "__wine_stub_%s_%d", make_c_identifier(spec->file_name), odp->ordinal );
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -819,15 +831,15 @@ unsigned int get_ptr_size(void)
|
|||
/* return the assembly name for a C symbol */
|
||||
const char *asm_name( const char *sym )
|
||||
{
|
||||
static char buffer[256];
|
||||
static char *buffer;
|
||||
|
||||
switch (target_platform)
|
||||
{
|
||||
case PLATFORM_APPLE:
|
||||
case PLATFORM_WINDOWS:
|
||||
if (sym[0] == '.' && sym[1] == 'L') return sym;
|
||||
buffer[0] = '_';
|
||||
strcpy( buffer + 1, sym );
|
||||
free( buffer );
|
||||
buffer = strmake( "_%s", sym );
|
||||
return buffer;
|
||||
default:
|
||||
return sym;
|
||||
|
@ -837,23 +849,25 @@ const char *asm_name( const char *sym )
|
|||
/* return an assembly function declaration for a C function name */
|
||||
const char *func_declaration( const char *func )
|
||||
{
|
||||
static char buffer[256];
|
||||
static char *buffer;
|
||||
|
||||
switch (target_platform)
|
||||
{
|
||||
case PLATFORM_APPLE:
|
||||
return "";
|
||||
case PLATFORM_WINDOWS:
|
||||
sprintf( buffer, ".def _%s; .scl 2; .type 32; .endef", func );
|
||||
free( buffer );
|
||||
buffer = strmake( ".def _%s; .scl 2; .type 32; .endef", func );
|
||||
break;
|
||||
default:
|
||||
free( buffer );
|
||||
switch(target_cpu)
|
||||
{
|
||||
case CPU_ARM:
|
||||
sprintf( buffer, ".type %s,%%function", func );
|
||||
buffer = strmake( ".type %s,%%function", func );
|
||||
break;
|
||||
default:
|
||||
sprintf( buffer, ".type %s,@function", func );
|
||||
buffer = strmake( ".type %s,@function", func );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -913,20 +927,22 @@ void output_gnu_stack_note(void)
|
|||
/* return a global symbol declaration for an assembly symbol */
|
||||
const char *asm_globl( const char *func )
|
||||
{
|
||||
static char buffer[256];
|
||||
static char *buffer;
|
||||
|
||||
free( buffer );
|
||||
switch (target_platform)
|
||||
{
|
||||
case PLATFORM_APPLE:
|
||||
sprintf( buffer, "\t.globl _%s\n\t.private_extern _%s\n_%s:", func, func, func );
|
||||
return buffer;
|
||||
buffer = strmake( "\t.globl _%s\n\t.private_extern _%s\n_%s:", func, func, func );
|
||||
break;
|
||||
case PLATFORM_WINDOWS:
|
||||
sprintf( buffer, "\t.globl _%s\n_%s:", func, func );
|
||||
return buffer;
|
||||
buffer = strmake( "\t.globl _%s\n_%s:", func, func );
|
||||
break;
|
||||
default:
|
||||
sprintf( buffer, "\t.globl %s\n\t.hidden %s\n%s:", func, func, func );
|
||||
return buffer;
|
||||
buffer = strmake( "\t.globl %s\n\t.hidden %s\n%s:", func, func, func );
|
||||
break;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
const char *get_asm_ptr_keyword(void)
|
||||
|
|
Loading…
Reference in New Issue