Waterbox: a few small libc changes
This commit is contained in:
parent
ef544cd9ab
commit
ad2fbd03f0
|
@ -0,0 +1,58 @@
|
||||||
|
#define _PDCLIB_EXTENSIONS
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
static size_t mcb(void *p, const char *buf, size_t size)
|
||||||
|
{
|
||||||
|
*(size_t *)p += size;
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t vprintflen(const char *restrict fmt, va_list arg)
|
||||||
|
{
|
||||||
|
size_t ret = 0;
|
||||||
|
_vcbprintf(&ret, mcb, fmt, arg);
|
||||||
|
return ret + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int asprintf(char **strp, const char *restrict fmt, ...)
|
||||||
|
{
|
||||||
|
va_list arg, arg2;
|
||||||
|
va_start(arg, fmt);
|
||||||
|
va_copy(arg2, arg);
|
||||||
|
|
||||||
|
size_t sz = vprintflen(fmt, arg);
|
||||||
|
|
||||||
|
*strp = malloc(sz);
|
||||||
|
if (!strp)
|
||||||
|
{
|
||||||
|
va_end(arg);
|
||||||
|
va_end(arg2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = vsnprintf(*strp, sz, fmt, arg2);
|
||||||
|
va_end(arg);
|
||||||
|
va_end(arg2);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int vasprintf(char **strp, const char *restrict fmt, va_list arg)
|
||||||
|
{
|
||||||
|
va_list arg2;
|
||||||
|
va_copy(arg2, arg);
|
||||||
|
|
||||||
|
size_t sz = vprintflen(fmt, arg);
|
||||||
|
|
||||||
|
*strp = malloc(sz);
|
||||||
|
if (!strp)
|
||||||
|
{
|
||||||
|
va_end(arg2);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = vsnprintf(*strp, sz, fmt, arg2);
|
||||||
|
va_end(arg2);
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -646,6 +646,9 @@ int vsprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, _
|
||||||
*/
|
*/
|
||||||
int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow;
|
int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) _PDCLIB_nothrow;
|
||||||
|
|
||||||
|
int asprintf(char **strp, const char * _PDCLIB_restrict fmt, ...) _PDCLIB_nothrow;
|
||||||
|
int vasprintf(char **strp, const char * _PDCLIB_restrict fmt, _PDCLIB_va_list arg) _PDCLIB_nothrow;
|
||||||
|
|
||||||
/* Character input/output functions */
|
/* Character input/output functions */
|
||||||
|
|
||||||
/* Retrieve the next character from given stream.
|
/* Retrieve the next character from given stream.
|
||||||
|
|
|
@ -278,7 +278,7 @@ struct _PDCLIB_imaxdiv_t
|
||||||
typedef char * _PDCLIB_va_list;
|
typedef char * _PDCLIB_va_list;
|
||||||
#define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) )
|
#define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) )
|
||||||
#define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 )
|
#define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 )
|
||||||
#define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 )
|
#define _PDCLIB_va_end( ap ) ( (ap) = (char *)0, (void)0 )
|
||||||
#define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 )
|
#define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 )
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
Loading…
Reference in New Issue