/programs/develop/ktcc/trunk/libc.obj/include/stdio.h |
---|
50,7 → 50,6 |
#define _FILEMODE_R 1 << 0 // Read |
#define _FILEMODE_W 1 << 1 // Write |
#define _FILEMODE_A 1 << 2 // Append |
#define _FILEMODE_PLUS 1 << 3 // Plus |
typedef struct FILE_s { |
char *name; |
/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h |
---|
43,7 → 43,6 |
extern void _FUNC(__assert_fail)(const char *expr, const char *file, int line, const char *func); |
extern void _FUNC(qsort)(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *)); |
extern double _FUNC(strtod)(const char *s, char **sret); |
extern double _FUNC(atof)(const char *ascii); |
#endif |
/programs/develop/ktcc/trunk/libc.obj/source/stdio/fread.c |
---|
24,7 → 24,7 |
return nmemb; |
} |
if(stream->mode != _FILEMODE_W && stream->mode != _FILEMODE_A){ |
if(stream->mode & _FILEMODE_R){ |
if(!stream->__ungetc_emu_buff){ |
((char*) ptr)[0]=(char)stream->__ungetc_emu_buff; |
//debug_printf("Ungetc: %x\n", ((char*) ptr)[0]); |
/programs/develop/ktcc/trunk/libc.obj/source/stdio/freopen.c |
---|
1,62 → 1,53 |
#include <stddef.h> |
#include <sys/ksys.h> |
#include "stddef.h" |
#include "sys/ksys.h" |
#include <errno.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <sys/dirent.h> |
static FILE* _set_errno(FILE *out, int err){ |
errno = err; |
if(out){ |
free(out->name); |
free(out); |
#define CREATE_FILE() if(_ksys_file_create(_name)){ \ |
errno= EIO; \ |
free(out); \ |
out = NULL; \ |
} |
out = NULL; |
return out; |
} |
static void _create_file(char *name, FILE *out){ |
if(_ksys_file_create(name)){ |
_set_errno(out, EIO); |
} |
} |
FILE *freopen(const char *restrict _name, const char *restrict _mode, FILE *restrict out) { |
if(!_name || !_mode || !out){ |
return _set_errno(out, EINVAL); |
errno = EINVAL; |
return NULL; |
} |
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); |
if(!no_file && info.attributes & IS_FOLDER){ |
return _set_errno(out, EISDIR); |
} |
out->eof=0; |
out->error=0; |
out->position=0; |
out->name = strdup(_name); |
if (strchr(_mode, 'r')) { out->mode = _FILEMODE_R; } |
if (strchr(_mode, 'w')) { out->mode = _FILEMODE_W; } |
if (strchr(_mode, 'a')) { out->mode = _FILEMODE_A; } |
if (strchr(_mode, '+')) { out->mode |= _FILEMODE_PLUS; } |
if(out->mode & _FILEMODE_A){ |
switch (out->mode) { |
case _FILEMODE_A : |
if(no_file){ |
_create_file(out->name, out); |
CREATE_FILE(); |
} |
out->position = info.size; |
}else if(out->mode & _FILEMODE_W){ |
_create_file(out->name, out); |
}else if((out->mode & _FILEMODE_R)){ |
break; |
case _FILEMODE_W : |
CREATE_FILE(); |
break; |
case _FILEMODE_R : |
if(no_file){ |
_set_errno(out, ENOENT); |
free(out); |
out = NULL; |
} |
}else{ |
_set_errno(out, EINVAL); |
break; |
default: |
free(out); |
out = NULL; |
break; |
} |
return out; |
} |
/programs/develop/ktcc/trunk/libc.obj/source/stdio/fclose.c |
---|
1,9 → 1,7 |
#include "stddef.h" |
#include <stdio.h> |
#include <stdlib.h> |
int fclose(FILE *stream) { |
free(stream); |
stream = NULL; |
return 0; |
} |
/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt |
---|
63,7 → 63,6 |
srand |
rand |
qsort |
strtod |
__assert_fail |
!____STRING____ |
!memcpy |
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtod.c |
---|
File deleted |
\ No newline at end of file |
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atof.c |
---|
1,7 → 1,8 |
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ |
#include <stdlib.h> |
double atof(const char *ascii) |
double |
atof(const char *ascii) |
{ |
return strtod(ascii, 0); |
} |
/programs/develop/ktcc/trunk/libc.obj/source/libc.c |
---|
100,7 → 100,6 |
#include "stdlib/rand.c" |
#include "stdlib/qsort.c" |
#include "stdlib/assert.c" |
#include "stdlib/strtod.c" |
#include "stdlib/atof.c" |
#include "math/acosh.c" |