sprintf.c
546 Bytes
/* sprintf function */
/*
* THIS SHOULD BE IN libc, NOT rmon!
*
*/
#include <string.h>
#include "xstdio.h"
#include "os.h"
static void *proutSprintf(void *, const char *, size_t);
int sprintf(char *s, const char *fmt, ...)
{
/* print formatted to string */
int ans;
va_list ap;
va_start(ap, fmt);
ans = _Printf(&proutSprintf, s, fmt, ap);
if (0 <= ans)
s[ans] = '\0';
va_end(ap);
return (ans);
}
static void *proutSprintf(void *s, const char *buf, size_t n)
{
/* write to string */
return ((char *) memcpy(s, buf, n) + n);
}