Commit 46ecc16d authored by Alexandre Julliard's avatar Alexandre Julliard

wmc: Add a copy of the strmake utility function.

parent 86eb9c24
...@@ -138,7 +138,6 @@ void *xmalloc(size_t size) ...@@ -138,7 +138,6 @@ void *xmalloc(size_t size)
void *res; void *res;
assert(size > 0); assert(size > 0);
assert(size < 102400);
res = malloc(size); res = malloc(size);
if(res == NULL) if(res == NULL)
{ {
...@@ -154,7 +153,6 @@ void *xrealloc(void *p, size_t size) ...@@ -154,7 +153,6 @@ void *xrealloc(void *p, size_t size)
void *res; void *res;
assert(size > 0); assert(size > 0);
assert(size < 102400);
res = realloc(p, size); res = realloc(p, size);
if(res == NULL) if(res == NULL)
{ {
...@@ -172,6 +170,25 @@ char *xstrdup(const char *str) ...@@ -172,6 +170,25 @@ char *xstrdup(const char *str)
return strcpy(s, str); return strcpy(s, str);
} }
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 );
}
}
int unistrlen(const WCHAR *s) int unistrlen(const WCHAR *s)
{ {
int n; int n;
......
...@@ -33,6 +33,7 @@ char *xstrdup(const char *str); ...@@ -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 mcy_error(const char *s, ...) __attribute__((format (printf, 1, 2))); int mcy_error(const char *s, ...) __attribute__((format (printf, 1, 2)));
int xyyerror(const char *s, ...) __attribute__((format (printf, 1, 2))); int xyyerror(const char *s, ...) __attribute__((format (printf, 1, 2)));
int mcy_warning(const char *s, ...) __attribute__((format (printf, 1, 2))); int mcy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment