ack/lang/cem/libcc.ansi/stdio/snprintf.c

31 lines
540 B
C
Raw Normal View History

/*
* sprintf - print formatted output on an array
*/
/* $Id$ */
2018-06-21 20:33:47 +00:00
#include <stdio.h>
#include <stdarg.h>
#include "loc_incl.h"
2018-06-21 20:33:47 +00:00
int snprintf(char* s, size_t len, const char* format, ...)
{
va_list ap;
int retval;
FILE tmp_stream;
va_start(ap, format);
2018-06-21 20:33:47 +00:00
tmp_stream._fd = -1;
tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING;
tmp_stream._buf = (unsigned char*)s;
tmp_stream._ptr = (unsigned char*)s;
tmp_stream._count = len;
retval = _doprnt(format, ap, &tmp_stream);
2018-06-21 20:33:47 +00:00
putc('\0', &tmp_stream);
va_end(ap);
return retval;
}