wmc: Add a copy of the strmake utility function.
This commit is contained in:
parent
86eb9c24f1
commit
46ecc16deb
|
@ -138,7 +138,6 @@ void *xmalloc(size_t size)
|
|||
void *res;
|
||||
|
||||
assert(size > 0);
|
||||
assert(size < 102400);
|
||||
res = malloc(size);
|
||||
if(res == NULL)
|
||||
{
|
||||
|
@ -154,7 +153,6 @@ void *xrealloc(void *p, size_t size)
|
|||
void *res;
|
||||
|
||||
assert(size > 0);
|
||||
assert(size < 102400);
|
||||
res = realloc(p, size);
|
||||
if(res == NULL)
|
||||
{
|
||||
|
@ -172,6 +170,25 @@ char *xstrdup(const char *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 n;
|
||||
|
|
|
@ -33,6 +33,7 @@ char *xstrdup(const char *str);
|
|||
#define __attribute__(X)
|
||||
#endif
|
||||
|
||||
char *strmake(const char* fmt, ...) __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 mcy_warning(const char *s, ...) __attribute__((format (printf, 1, 2)));
|
||||
|
|
Loading…
Reference in New Issue