This commit is contained in:
bumbread 2022-06-24 13:43:47 +11:00
parent 29a98bf8a3
commit 1e58a85f02
5 changed files with 28 additions and 4 deletions

View File

@ -4,5 +4,6 @@
#define EDOM 1 #define EDOM 1
#define EILSEQ 2 #define EILSEQ 2
#define ERANGE 3 #define ERANGE 3
#define EIO 4
extern _Thread_local int errno; extern _Thread_local int errno;

View File

@ -216,6 +216,7 @@ char *strerror(int errnum) {
case EDOM: return "Value is out of domain of the function"; case EDOM: return "Value is out of domain of the function";
case EILSEQ: return "Illegal byte sequence"; case EILSEQ: return "Illegal byte sequence";
case ERANGE: return "Value is out of range"; case ERANGE: return "Value is out of range";
case EIO: return "I/O error";
} }
return "Unkown error"; return "Unkown error";
} }

View File

@ -75,7 +75,7 @@ size_t c16rtomb(
char16_t c16, char16_t c16,
mbstate_t *restrict ps mbstate_t *restrict ps
) { ) {
if(*s == NULL) { if(s == NULL) {
*ps = (mbstate_t) {0}; *ps = (mbstate_t) {0};
return 0; return 0;
} }
@ -178,7 +178,7 @@ size_t c32rtomb(
char32_t c32, char32_t c32,
mbstate_t *restrict ps mbstate_t *restrict ps
) { ) {
if(*s == NULL) { if(s == NULL) {
*ps = (mbstate_t) {0}; *ps = (mbstate_t) {0};
return 0; return 0;
} }

View File

@ -6,6 +6,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <threads.h> #include <threads.h>
#include <uchar.h> #include <uchar.h>
#include <errno.h>
enum str_type { enum str_type {
STR_R, STR_R,
@ -69,6 +70,7 @@ static inline FILE *new_file(
file_list_last->next = file; file_list_last->next = file;
file->prev = file_list_last; file->prev = file_list_last;
file->next = NULL; file->next = NULL;
file_list_last = file;
} }
else { else {
file_list_last = file; file_list_last = file;
@ -94,6 +96,7 @@ static inline void dispose_file(FILE *file) {
if(next == NULL) file_list_last = prev; if(next == NULL) file_list_last = prev;
free(file); free(file);
mtx_unlock(&lock); mtx_unlock(&lock);
mtx_destroy(&lock);
} }
void _setup_io() { void _setup_io() {
@ -147,15 +150,27 @@ int setvbuf(
} }
int fflush(FILE *stream) { int fflush(FILE *stream) {
if(mode == _IOFBF) { if(stream->mode == _IOFBF) {
} }
else if(mode == _IONBF) { else if(stream->mode == _IONBF) {
} }
return 0; return 0;
} }
int fputc(int c, FILE *stream) {
mtx_lock(&stream->lock);
DWORD written;
BOOL ok = WriteFile(stream->handle, &c, 1, &written, NULL);
mtx_unlock(&stream->lock);
if(!ok) {
errno = EIO;
return EOF;
}
return c;
}
void setbuf(FILE *restrict stream, char *restrict buf) { void setbuf(FILE *restrict stream, char *restrict buf) {
if(buf != NULL) if(buf != NULL)
setvbuf(stream, buf, _IOFBF, BUFSIZ); setvbuf(stream, buf, _IOFBF, BUFSIZ);

7
test/test_io.c Normal file
View File

@ -0,0 +1,7 @@
#include <stdio.h>
int main() {
fputc('Z', stdout);
return 0;
}