2018-10-22 14:57:25 +03:00
|
|
|
#include "stdio.h"
|
|
|
|
#include "stdarg.h"
|
|
|
|
#include "types.h"
|
2018-10-26 15:56:21 +03:00
|
|
|
#include "string.h"
|
|
|
|
#include "errno.h"
|
2018-10-30 17:33:37 +03:00
|
|
|
#include "unistd.h"
|
2018-10-22 14:57:25 +03:00
|
|
|
#include <Kernel/Syscall.h>
|
2018-10-27 17:43:03 +03:00
|
|
|
#include <AK/printf.cpp>
|
2018-10-22 14:57:25 +03:00
|
|
|
|
2018-10-27 17:43:03 +03:00
|
|
|
extern "C" {
|
2018-10-22 14:57:25 +03:00
|
|
|
|
2018-10-27 17:43:03 +03:00
|
|
|
int putchar(int ch)
|
2018-10-22 14:57:25 +03:00
|
|
|
{
|
2018-10-30 17:33:37 +03:00
|
|
|
write(0, &ch, 1);
|
2018-10-27 17:43:03 +03:00
|
|
|
return (byte)ch;
|
2018-10-22 14:57:25 +03:00
|
|
|
}
|
|
|
|
|
2018-10-30 17:33:37 +03:00
|
|
|
static void sys_putch(char*&, char ch)
|
2018-10-22 14:57:25 +03:00
|
|
|
{
|
2018-10-30 17:33:37 +03:00
|
|
|
putchar(ch);
|
2018-10-22 14:57:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int printf(const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
int ret = printfInternal(sys_putch, nullptr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void buffer_putch(char*& bufptr, char ch)
|
|
|
|
{
|
|
|
|
*bufptr++ = ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sprintf(char* buffer, const char* fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
int ret = printfInternal(buffer_putch, buffer, fmt, ap);
|
|
|
|
buffer[ret] = '\0';
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-10-26 15:56:21 +03:00
|
|
|
void perror(const char* s)
|
|
|
|
{
|
|
|
|
printf("%s: %s\n", s, strerror(errno));
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:57:25 +03:00
|
|
|
}
|
|
|
|
|