Compare commits

..

5 Commits

6 changed files with 57 additions and 7 deletions
apps
kernel/src
arch/x86_64
fs/devices
thread
libc

@ -3,4 +3,10 @@
int main(int argc, char** argv)
{
printf("Hello world! argc=%d, argv[0]=%s, argv[1]=%s, argv[2]=%s\n", argc, argv[0], argv[1], argv[2]);
char buf[1024];
char* rc = fgets(buf, sizeof(buf), stdin);
if (!rc) perror("fgets");
fputs(buf, stdout);
}

@ -126,11 +126,7 @@ void io_thread()
while (!scancode_queue.try_pop(scancode)) { kernel_sleep(10); }
char key;
if (Keyboard::decode_scancode(scancode).try_set_value(key))
{
TextConsole::putchar(key);
ConsoleDevice::did_press_key(key);
}
if (Keyboard::decode_scancode(scancode).try_set_value(key)) { ConsoleDevice::did_press_key(key); }
}
}

@ -46,7 +46,7 @@ void ConsoleDevice::did_press_key(char key)
return;
}
g_temp_input.try_append(key).value();
g_temp_input.try_append((u8)key).value();
if (key == '\n')
{

@ -52,7 +52,7 @@ bool FileDescriptor::should_append()
bool FileDescriptor::should_block()
{
return flags & O_NONBLOCK;
return !(flags & O_NONBLOCK);
}
bool FileDescriptor::is_readable()

@ -81,6 +81,18 @@ extern "C"
/* Write a string to stream. */
int fputs(const char* str, FILE* stream);
/* Read a character from stream. */
int fgetc(FILE* stream);
/* Read a character from stream. */
int getc(FILE* stream);
/* Read a character from standard input. */
int getchar();
/* Read a line from stream. */
char* fgets(char* buf, size_t size, FILE* stream);
/* Clear the error and end-of-file indicators in stream. */
void clearerr(FILE* stream);

@ -187,6 +187,42 @@ extern "C"
return (rc < 0) ? -1 : 0;
}
int fgetc(FILE* stream)
{
u8 value;
ssize_t rc = read(stream->_fd, &value, 1);
if (rc <= 0) return EOF;
return value;
}
int getc(FILE* stream)
{
return fgetc(stream);
}
int getchar()
{
return fgetc(stdin);
}
char* fgets(char* buf, size_t size, FILE* stream)
{
size_t i = 0;
while (i + 1 < size)
{
int c = fgetc(stream);
if (c == EOF) break;
buf[i++] = (char)c;
if (c == '\n') break;
}
if (i == 0) return NULL;
buf[i] = 0;
return buf;
}
void clearerr(FILE* stream)
{
stream->_eof = stream->_err = 0;