2020-09-17 19:27:01 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2020-10-14 12:07:29 +02:00
|
|
|
// internal depency
|
|
|
|
// TODO: update path detection
|
|
|
|
#include "../src/stdio/internal/printf.h"
|
|
|
|
|
2020-09-17 19:27:01 +02:00
|
|
|
// FIXME:
|
|
|
|
// if the writte syscall do not return the same
|
|
|
|
// number of bytes that requested, stop the function !
|
|
|
|
static void disp_fflush(struct printf_opt *opt)
|
|
|
|
{
|
|
|
|
if (opt->buffer_cursor != 0) {
|
|
|
|
opt->counter += write(opt->fd, opt->buffer, opt->buffer_cursor);
|
|
|
|
opt->buffer_cursor = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disp_char(struct printf_opt *opt, char n)
|
|
|
|
{
|
|
|
|
// Check if we should force flush the internal buffer
|
|
|
|
if (opt->buffer_cursor >= PRINTF_INTERNAL_BUFFER_SIZE)
|
|
|
|
disp_fflush(opt);
|
|
|
|
|
|
|
|
// Save char
|
|
|
|
opt->buffer[opt->buffer_cursor++] = n;
|
|
|
|
}
|
|
|
|
|
2020-10-14 15:18:10 +02:00
|
|
|
/*
|
|
|
|
** The functions vdprintf() are equivalent to the dprintf() except that they
|
|
|
|
** are called with a va_list instead of a variable number of arguments. These
|
|
|
|
** functions do not call the va_end macro. Because they invoke the va_arg macro,
|
|
|
|
** the value of ap is undefined after the call.
|
|
|
|
*/
|
2020-09-17 19:27:01 +02:00
|
|
|
int vdprintf(int fd, const char *restrict format, va_list ap)
|
|
|
|
{
|
2020-10-21 22:26:47 +02:00
|
|
|
extern int printf_common(struct printf_opt *opt,
|
|
|
|
const char *restrict format);
|
2020-09-17 19:27:01 +02:00
|
|
|
struct printf_opt opt;
|
|
|
|
|
|
|
|
opt.fd = fd;
|
|
|
|
opt.disp_char = &disp_char;
|
|
|
|
opt.disp_fflush = &disp_fflush;
|
|
|
|
va_copy(opt.ap, ap);
|
2020-10-14 12:07:29 +02:00
|
|
|
return (printf_common(&opt, format));
|
2020-09-17 19:27:01 +02:00
|
|
|
}
|