wrc: Copy the strmake utility function from winegcc.

This commit is contained in:
Alexandre Julliard 2010-12-29 19:54:54 +01:00
parent 18a3b3f2f7
commit 5fabc5cca7
4 changed files with 23 additions and 23 deletions

View File

@ -1741,23 +1741,8 @@ char *prep_nid_for_label(const name_id_t *nid)
*/ */
char *make_c_name(const char *base, const name_id_t *nid, const language_t *lan) char *make_c_name(const char *base, const name_id_t *nid, const language_t *lan)
{ {
int nlen; char *buf = prep_nid_for_label(nid);
char *buf; return strmake( "_%s_%s_%d", base, buf, lan ? MAKELANGID(lan->id, lan->sub) : 0);
char *ret;
char lanbuf[6];
sprintf(lanbuf, "%d", lan ? MAKELANGID(lan->id, lan->sub) : 0);
buf = prep_nid_for_label(nid);
nlen = strlen(buf) + strlen(lanbuf);
nlen += strlen(base) + 4; /* three time '_' and '\0' */
ret = xmalloc(nlen);
strcpy(ret, "_");
strcat(ret, base);
strcat(ret, "_");
strcat(ret, buf);
strcat(ret, "_");
strcat(ret, lanbuf);
return ret;
} }
/* /*

View File

@ -192,6 +192,25 @@ void *xrealloc(void *p, size_t size)
return res; return res;
} }
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 );
}
}
char *xstrdup(const char *str) char *xstrdup(const char *str)
{ {
char *s; char *s;

View File

@ -33,6 +33,7 @@ char *xstrdup(const char *str);
#define __attribute__(X) #define __attribute__(X)
#endif #endif
char *strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2 )));
int parser_error(const char *s, ...) __attribute__((format (printf, 1, 2))); int parser_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2))); int parser_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
void internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4), noreturn)); void internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4), noreturn));

View File

@ -270,12 +270,7 @@ static int load_file( const char *input_name, const char *output_name )
exit(0); exit(0);
} }
if (output_name && output_name[0]) if (output_name && output_name[0]) name = strmake( "%s.XXXXXX", output_name );
{
name = xmalloc( strlen(output_name) + 8 );
strcpy( name, output_name );
strcat( name, ".XXXXXX" );
}
else name = xstrdup( "wrc.XXXXXX" ); else name = xstrdup( "wrc.XXXXXX" );
if ((fd = mkstemps( name, 0 )) == -1) if ((fd = mkstemps( name, 0 )) == -1)