Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. FILE *freopen(const char *restrict _name, const char *restrict _mode, FILE *restrict out) {
  6.     ksys_bdfe_t info;
  7.     if (_ksys_file_get_info(_name, &info)) {
  8.         return NULL;
  9.     }
  10.  
  11.     if (!out) {
  12.         return NULL;
  13.     }
  14.  
  15.     out->name = strdup(_name);
  16.     out->position = 0;
  17.     out->error = 0;
  18.     out->eof = 0;
  19.     out->kind = 0;
  20.     out->orientation = 0;
  21.     out->mode = 0;
  22.  
  23.     if (strchr(_mode, 'b')) { out->mode |= _STDIO_F_B; }
  24.     if (strchr(_mode, 'x')) { out->mode |= _STDIO_F_X; }
  25.     if (strchr(_mode, 'a')) { out->mode |= _STDIO_F_A; }
  26.     if (strchr(_mode, 'r')) { out->mode |= _STDIO_F_R; }
  27.     if (strchr(_mode, 'w')) { out->mode |= _STDIO_F_W; }
  28.     if (strchr(_mode, '+')) { out->mode |= _STDIO_F_R | _STDIO_F_W; }
  29.  
  30.     if (out->mode & _STDIO_F_A) {
  31.         out->position = info.size;
  32.         out->append_offset = info.size;
  33.     }
  34.  
  35.     return out;
  36. }
  37.