Blame src/internal/ntux_dprintf_impl.c
|
|
81d6fb |
#include <psxabi/sys_sysapi.h>
|
|
|
81d6fb |
#include <psxabi/sys_errno.h>
|
|
|
471bb0 |
#include <psxxfi/xfi_base.h>
|
|
|
81d6fb |
|
|
|
81d6fb |
#include <ntux/ntux.h>
|
|
|
81d6fb |
#include "ntux_driver_impl.h"
|
|
|
81d6fb |
#include "ntux_nolibc_impl.h"
|
|
|
81d6fb |
#include "ntux_errinfo_impl.h"
|
|
|
81d6fb |
|
|
|
81d6fb |
#include <stdio.h>
|
|
|
81d6fb |
#include <stdlib.h>
|
|
|
81d6fb |
#include <unistd.h>
|
|
|
81d6fb |
|
|
|
81d6fb |
int ntux_dprintf(int fd, const char * fmt, ...)
|
|
|
81d6fb |
{
|
|
|
81d6fb |
int ret;
|
|
|
81d6fb |
int cnt;
|
|
|
81d6fb |
int size;
|
|
|
81d6fb |
va_list ap;
|
|
|
81d6fb |
char * ch;
|
|
|
81d6fb |
char * buf;
|
|
|
81d6fb |
char chbuf[2048];
|
|
|
81d6fb |
|
|
|
81d6fb |
va_start(ap,fmt);
|
|
|
81d6fb |
|
|
|
81d6fb |
size = sizeof(chbuf);
|
|
|
471bb0 |
buf = ((cnt = __xfi_vsnprintf(chbuf,size,fmt,ap)) < size)
|
|
|
81d6fb |
? chbuf : calloc(1, cnt + 1);
|
|
|
81d6fb |
|
|
|
81d6fb |
va_end(ap);
|
|
|
81d6fb |
|
|
|
81d6fb |
if (buf == chbuf) {
|
|
|
81d6fb |
(void)0;
|
|
|
81d6fb |
|
|
|
81d6fb |
} else if (buf) {
|
|
|
81d6fb |
va_start(ap,fmt);
|
|
|
471bb0 |
__xfi_vsprintf(buf,fmt,ap);
|
|
|
81d6fb |
va_end(ap);
|
|
|
81d6fb |
|
|
|
81d6fb |
} else {
|
|
|
81d6fb |
return -1;
|
|
|
81d6fb |
}
|
|
|
81d6fb |
|
|
|
81d6fb |
ret = 0;
|
|
|
81d6fb |
ch = buf;
|
|
|
81d6fb |
|
|
|
81d6fb |
for (; cnt && ret>=0; ) {
|
|
|
81d6fb |
ret = __sys_write(fd,ch,cnt);
|
|
|
81d6fb |
|
|
|
81d6fb |
while ((ret < 0) && (ret == -EINTR))
|
|
|
81d6fb |
ret = __sys_write(fd,ch,cnt);
|
|
|
81d6fb |
|
|
|
81d6fb |
ch += ret;
|
|
|
81d6fb |
cnt -= ret;
|
|
|
81d6fb |
}
|
|
|
81d6fb |
|
|
|
81d6fb |
ret = (ret < 0) ? -1 : ch - buf;
|
|
|
81d6fb |
|
|
|
81d6fb |
if (buf != chbuf)
|
|
|
81d6fb |
free(buf);
|
|
|
81d6fb |
|
|
|
81d6fb |
return ret;
|
|
|
81d6fb |
}
|