Added snprintf() and vsnprintf() functions.

git-svn-id: svn://kolibrios.org@1914 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
jaeger 2011-03-31 11:06:50 +00:00
parent 9fd32b8cdf
commit a92aa078e6

View File

@ -2,20 +2,41 @@
#include <stdio.h>
#include <limits.h>
#include <libc/file.h>
#include <stdarg.h>
int
vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
{
FILE _strbuf;
int len;
_strbuf._flag = _IOWRT|_IOSTRG;
_strbuf._ptr = str;
_strbuf._cnt = size;
len = _doprnt(fmt, ap, &_strbuf);
*_strbuf._ptr = 0;
return len;
}
int
snprintf(char *str, size_t size, const char *fmt, ...)
{
int len;
va_list va;
va_start(va, fmt);
len = vsnprintf(str, size, fmt, va);
va_end(va);
return len;
}
int
sprintf(char *str, const char *fmt, ...)
{
FILE _strbuf;
int len;
va_list va;
va_start(va, fmt);
_strbuf._flag = _IOWRT|_IOSTRG;
_strbuf._ptr = str;
_strbuf._cnt = INT_MAX;
len = _doprnt(fmt, va, &_strbuf);
len = vsnprintf(str, INT_MAX, fmt, va);
va_end(va);
*_strbuf._ptr = 0;
return len;
}