Alexandre Julliard : wrc: Copy the strmake utility function from winegcc.
Alexandre Julliard
julliard at winehq.org
Thu Dec 30 10:49:55 CST 2010
Module: wine
Branch: master
Commit: 5fabc5cca7179dac98c0413b8c8945ae38bf3ef0
URL: http://source.winehq.org/git/wine.git/?a=commit;h=5fabc5cca7179dac98c0413b8c8945ae38bf3ef0
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Dec 29 19:54:54 2010 +0100
wrc: Copy the strmake utility function from winegcc.
---
tools/wrc/genres.c | 19 ++-----------------
tools/wrc/utils.c | 19 +++++++++++++++++++
tools/wrc/utils.h | 1 +
tools/wrc/wrc.c | 7 +------
4 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/tools/wrc/genres.c b/tools/wrc/genres.c
index 7871c79..3d40180 100644
--- a/tools/wrc/genres.c
+++ b/tools/wrc/genres.c
@@ -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)
{
- int nlen;
- char *buf;
- 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;
+ char *buf = prep_nid_for_label(nid);
+ return strmake( "_%s_%s_%d", base, buf, lan ? MAKELANGID(lan->id, lan->sub) : 0);
}
/*
diff --git a/tools/wrc/utils.c b/tools/wrc/utils.c
index c9445b3..5adebba 100644
--- a/tools/wrc/utils.c
+++ b/tools/wrc/utils.c
@@ -192,6 +192,25 @@ void *xrealloc(void *p, size_t size)
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 *s;
diff --git a/tools/wrc/utils.h b/tools/wrc/utils.h
index ced55ab..19daa09 100644
--- a/tools/wrc/utils.h
+++ b/tools/wrc/utils.h
@@ -33,6 +33,7 @@ char *xstrdup(const char *str);
#define __attribute__(X)
#endif
+char *strmake(const char* fmt, ...) __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)));
void internal_error(const char *file, int line, const char *s, ...) __attribute__((format (printf, 3, 4), noreturn));
diff --git a/tools/wrc/wrc.c b/tools/wrc/wrc.c
index 99285db..bbeba83 100644
--- a/tools/wrc/wrc.c
+++ b/tools/wrc/wrc.c
@@ -270,12 +270,7 @@ static int load_file( const char *input_name, const char *output_name )
exit(0);
}
- if (output_name && output_name[0])
- {
- name = xmalloc( strlen(output_name) + 8 );
- strcpy( name, output_name );
- strcat( name, ".XXXXXX" );
- }
+ if (output_name && output_name[0]) name = strmake( "%s.XXXXXX", output_name );
else name = xstrdup( "wrc.XXXXXX" );
if ((fd = mkstemps( name, 0 )) == -1)
More information about the wine-cvs
mailing list