2007-04-05 02:32:49 +08:00
|
|
|
/* Copyright 2005, 2007 Shaun Jackman
|
|
|
|
* Permission to use, copy, modify, and distribute this software
|
|
|
|
* is freely granted, provided that this notice is preserved.
|
|
|
|
*/
|
2007-05-04 10:55:16 +08:00
|
|
|
/* doc in diprintf.c */
|
2007-04-05 02:32:49 +08:00
|
|
|
|
|
|
|
#include <_ansi.h>
|
|
|
|
#include <reent.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdarg.h>
|
2008-03-08 00:45:04 +08:00
|
|
|
#include "local.h"
|
2007-04-05 02:32:49 +08:00
|
|
|
|
|
|
|
int
|
2017-12-04 11:43:30 +08:00
|
|
|
_vdiprintf_r (struct _reent *ptr,
|
2017-12-04 09:31:41 +08:00
|
|
|
int fd,
|
|
|
|
const char *format,
|
2007-04-05 02:32:49 +08:00
|
|
|
va_list ap)
|
|
|
|
{
|
|
|
|
char *p;
|
2007-05-04 10:55:16 +08:00
|
|
|
char buf[512];
|
|
|
|
size_t n = sizeof buf;
|
2007-04-05 02:32:49 +08:00
|
|
|
|
|
|
|
_REENT_SMALL_CHECK_INIT (ptr);
|
2007-05-04 10:55:16 +08:00
|
|
|
p = _vasniprintf_r (ptr, buf, &n, format, ap);
|
|
|
|
if (!p)
|
|
|
|
return -1;
|
2007-04-05 02:32:49 +08:00
|
|
|
n = _write_r (ptr, fd, p, n);
|
2007-05-04 10:55:16 +08:00
|
|
|
if (p != buf)
|
|
|
|
_free_r (ptr, p);
|
2007-04-05 02:32:49 +08:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef _REENT_ONLY
|
|
|
|
|
|
|
|
int
|
2017-12-04 11:43:30 +08:00
|
|
|
vdiprintf (int fd,
|
2017-12-04 09:31:41 +08:00
|
|
|
const char *format,
|
2007-04-05 02:32:49 +08:00
|
|
|
va_list ap)
|
|
|
|
{
|
|
|
|
return _vdiprintf_r (_REENT, fd, format, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! _REENT_ONLY */
|