kolibri-libc:

- Added ungetc, tollower and toupper to export
- Fixed ungetc emu
- Fixed file io functions
- Update file_io test 

git-svn-id: svn://kolibrios.org@8730 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat
2021-05-23 15:28:07 +00:00
parent c09b0569fc
commit ffca41d7f9
18 changed files with 130 additions and 82 deletions

View File

@@ -1,42 +1,53 @@
#include "stddef.h"
#include "sys/ksys.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CREATE_FILE() if(_ksys_file_create(_name)){ \
errno= EIO; \
free(out); \
out = NULL; \
}
FILE *freopen(const char *restrict _name, const char *restrict _mode, FILE *restrict out) {
static ksys_bdfe_t info;
info.size=0;
if (!out) {
errno = ENOMEM;
if(!_name || !_mode || !out){
errno = EINVAL;
return NULL;
}
_ksys_file_get_info(_name, &info);
if (strchr(_mode, 'r')) { out->mode = _FILEMODE_R; }
if (strchr(_mode, 'a')) { out->mode = _FILEMODE_A; }
if (strchr(_mode, 'w')) { out->mode = _FILEMODE_W; }
ksys_bdfe_t info;
int no_file = _ksys_file_get_info(_name, &info);
out->eof=0;
out->error=0;
out->position=0;
out->name = strdup(_name);
out->position = 0;
out->error = 0;
out->eof = 0;
out->kind = 0;
out->orientation = 0;
out->mode = 0;
out->start_size = info.size;
if (strchr(_mode, 'b')) { out->mode |= _STDIO_F_B; }
if (strchr(_mode, 'x')) { out->mode |= _STDIO_F_X; }
if (strchr(_mode, 'a')) { out->mode |= _STDIO_F_A; }
if (strchr(_mode, 'r')) { out->mode |= _STDIO_F_R; }
if (strchr(_mode, 'w')) { out->mode |= _STDIO_F_W; }
if (strchr(_mode, '+')) { out->mode |= _STDIO_F_R | _STDIO_F_W; }
if (out->mode & _STDIO_F_A) {
out->position = info.size;
out->append_offset = info.size;
} else if(out->mode & _STDIO_F_W){
if(_ksys_file_create(_name)){
return NULL;
switch (out->mode) {
case _FILEMODE_A :
if(no_file){
CREATE_FILE();
}
out->position = info.size;
break;
case _FILEMODE_W :
CREATE_FILE();
break;
case _FILEMODE_R :
if(no_file){
free(out);
out = NULL;
}
break;
default:
free(out);
out = NULL;
break;
}
return out;
}
}