olibc/src/stdio.c

45 lines
746 B
C

#include <liblinux.h>
#include <stdio.h>
int putchar(int c) {
sys_write(stdout, &c, 1);
return (unsigned char)c;
}
int puts(const char *s) {
int i = 0;
while(s[i] != '\0') {
putchar(s[i]);
i++;
}
putchar('\n');
return 1; // FIXME
}
void put_int(long long value) { // FIXME: delete this after implemented printf
if (value == 0)
putchar('0');
if (value < 0) {
putchar('-');
value *= (-1);
}
long long power = 1;
while (value > power)
power *= 10;
if (power >= 10)
power /= 10;
while (value != 0) {
int digit = (int)(value / power);
putchar('0' + digit);
if (digit != 0)
value = value - digit * power;
if (power != 1)
power /= 10;
}
putchar('\n');
}