From bf9646609ea447b8d390b69c3bdfcf9e8e18e0e9 Mon Sep 17 00:00:00 2001 From: bumbread Date: Sun, 24 Jul 2022 20:31:35 +1100 Subject: [PATCH] Some err handling and ++todo --- src/win/win_stdio.c | 5 ++++- test/test_io.c | 43 +++++++++++-------------------------------- todo | 10 ++++++++++ 3 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/win/win_stdio.c b/src/win/win_stdio.c index 149fde8..7f7158c 100644 --- a/src/win/win_stdio.c +++ b/src/win/win_stdio.c @@ -168,6 +168,9 @@ FILE *fopen(const char *restrict name, const char *restrict mode) { } break; } HANDLE handle = CreateFileA(name, access, share, NULL, disp, flags, NULL); + if(handle == INVALID_HANDLE_VALUE) { + return NULL; + } FILE *stream = create_stream(handle, io_mode, bt_mode); void *buffer_data = malloc(BUFSIZ); stream->buffer = (stream_buffer_t) {1, _IOFBF, BUFSIZ, buffer_data}; @@ -406,6 +409,6 @@ int puts(char const *str) { return putchar('\n'); } -char *gets(char str) { +char *gets(char *str) { return fgets(str, 0x7fffffff, stdin); } diff --git a/test/test_io.c b/test/test_io.c index 31a53f1..69e56cb 100644 --- a/test/test_io.c +++ b/test/test_io.c @@ -1,38 +1,17 @@ -#include #include - -void demo_scanf(const char* fmt, FILE* s) -{ - while (*fmt != '\0') { - if (*fmt == '%') { - int c; - switch (*++fmt) { - case 'u': - while (isspace(c=getc(s))) {} - unsigned int num = 0; - while (isdigit(c)) { - num = num*10 + c-'0'; - c = getc(s); - } - printf("%%u scanned %u\n", num); - ungetc(c, s); - break; - case 'c': - c = getc(s); - printf("%%c scanned '%c'\n", c); - break; - } - } else { - ++fmt; - } - } -} - + int main(void) { - printf("Please enter a string: "); - fflush(stdout); - demo_scanf("%u%c", stdin); + char const *filename = "todo"; + FILE *f = fopen(filename, "rb"); + if(f == NULL) { + printf("File %s doesn't exist\n", filename); + return 1; + } + int c; + while((c=fgetc(f)) != EOF) { + putchar(c); + } return 0; } diff --git a/todo b/todo index 85eee1a..0a7b346 100644 --- a/todo +++ b/todo @@ -2,6 +2,8 @@ general: * Start writing documentation concerning various implementation defined behaviours of the library. +* Ok I just realised that I assumed that wchar_t is a 16-bit string in + a bunch of places. math.h: * exp @@ -33,6 +35,14 @@ stdio.h: with a buffer would increase performance. * Formatted scan * %s precision should specify how much characters to *write* +* %Ls this is an actual weird territory. If (wchar_t *) is a unicode string + then to determine it's "width" (to figure out field padding) would require + to use a Unicode composition algorithm. But the problem is that windows + Unicode rendering advances text by 2 units, even if it's 1 graphical + character that was composed from 2 unicode characters. The question + becomes: do we implement the thing correctly by using a more complex + solution, or do we succumb to windows' bullshittery. I guess the answer is + obvious. That's why I wrote this todo item :D stdlib.h: * Strtod base 16 must be correctly rounded