Rev 8687 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8687 | Rev 8730 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | #include "stddef.h" |
|
1 | #include "sys/ksys.h" |
2 | #include "sys/ksys.h" |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include |
5 | #include |
6 | #include |
Line -... | Line 7... | ||
- | 7 | ||
- | 8 | #define CREATE_FILE() if(_ksys_file_create(_name)){ \ |
|
- | 9 | errno= EIO; \ |
|
- | 10 | free(out); \ |
|
- | 11 | out = NULL; \ |
|
- | 12 | } |
|
6 | 13 | ||
7 | FILE *freopen(const char *restrict _name, const char *restrict _mode, FILE *restrict out) { |
14 | FILE *freopen(const char *restrict _name, const char *restrict _mode, FILE *restrict out) { |
8 | static ksys_bdfe_t info; |
- | |
9 | info.size=0; |
- | |
10 | if (!out) { |
15 | if(!_name || !_mode || !out){ |
11 | errno = ENOMEM; |
16 | errno = EINVAL; |
12 | return NULL; |
17 | return NULL; |
Line -... | Line 18... | ||
- | 18 | } |
|
- | 19 | ||
13 | } |
20 | if (strchr(_mode, 'r')) { out->mode = _FILEMODE_R; } |
Line 14... | Line 21... | ||
14 | 21 | if (strchr(_mode, 'a')) { out->mode = _FILEMODE_A; } |
|
15 | _ksys_file_get_info(_name, &info); |
22 | if (strchr(_mode, 'w')) { out->mode = _FILEMODE_W; } |
16 | - | ||
17 | out->name = strdup(_name); |
23 | |
18 | out->position = 0; |
24 | ksys_bdfe_t info; |
19 | out->error = 0; |
25 | int no_file = _ksys_file_get_info(_name, &info); |
20 | out->eof = 0; |
- | |
21 | out->kind = 0; |
26 | out->eof=0; |
22 | out->orientation = 0; |
- | |
23 | out->mode = 0; |
- | |
24 | out->start_size = info.size; |
- | |
25 | - | ||
26 | if (strchr(_mode, 'b')) { out->mode |= _STDIO_F_B; } |
- | |
27 | if (strchr(_mode, 'x')) { out->mode |= _STDIO_F_X; } |
- | |
28 | if (strchr(_mode, 'a')) { out->mode |= _STDIO_F_A; } |
- | |
Line 29... | Line 27... | ||
29 | if (strchr(_mode, 'r')) { out->mode |= _STDIO_F_R; } |
27 | out->error=0; |
- | 28 | out->position=0; |
|
- | 29 | out->name = strdup(_name); |
|
- | 30 | ||
- | 31 | switch (out->mode) { |
|
30 | if (strchr(_mode, 'w')) { out->mode |= _STDIO_F_W; } |
32 | case _FILEMODE_A : |
- | 33 | if(no_file){ |
|
- | 34 | CREATE_FILE(); |
|
31 | if (strchr(_mode, '+')) { out->mode |= _STDIO_F_R | _STDIO_F_W; } |
35 | } |
- | 36 | out->position = info.size; |
|
32 | 37 | break; |
|
33 | if (out->mode & _STDIO_F_A) { |
38 | case _FILEMODE_W : |
- | 39 | CREATE_FILE(); |
|
34 | out->position = info.size; |
40 | break; |
35 | out->append_offset = info.size; |
41 | case _FILEMODE_R : |
- | 42 | if(no_file){ |
|
- | 43 | free(out); |
|
- | 44 | out = NULL; |
|
- | 45 | } |
|
- | 46 | break; |
|
36 | } else if(out->mode & _STDIO_F_W){ |
47 | default: |
37 | if(_ksys_file_create(_name)){ |
48 | free(out); |
38 | return NULL; |
49 | out = NULL; |