Subversion Repositories Kolibri OS

Rev

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

  1. #include "sys/ksys.h"
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. 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) {
  11.         errno = ENOMEM;
  12.         return NULL;
  13.     }
  14.  
  15.     _ksys_file_get_info(_name, &info);
  16.  
  17.     out->name = strdup(_name);
  18.     out->position = 0;
  19.     out->error = 0;
  20.     out->eof = 0;
  21.     out->kind = 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; }
  29.     if (strchr(_mode, 'r')) { out->mode |= _STDIO_F_R; }
  30.     if (strchr(_mode, 'w')) { out->mode |= _STDIO_F_W; }
  31.     if (strchr(_mode, '+')) { out->mode |= _STDIO_F_R | _STDIO_F_W; }
  32.  
  33.     if (out->mode & _STDIO_F_A) {
  34.         out->position = info.size;
  35.         out->append_offset = info.size;
  36.     } else if(out->mode & _STDIO_F_W){
  37.         if(_ksys_file_create(_name)){
  38.             return NULL;
  39.         }
  40.     }
  41.     return out;
  42. }
  43.