Subversion Repositories Kolibri OS

Rev

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

  1. #include <stdio.h>
  2.  
  3. char * fgets ( char * str, int num, FILE * file )
  4. // need to ignore \r\n in text mode
  5. {
  6.         int rd = 0;
  7.         char c;
  8.  
  9.     if(!file || !str)
  10.     {
  11.         errno = E_INVALIDPTR;
  12.         return NULL;
  13.     }
  14.  
  15.  
  16.         while (rd < num - 1)
  17.         {
  18.                 c = fgetc(file);
  19.                 if (EOF == c) break;
  20.                 if ('\n' == c)
  21.                 {
  22.                         str[rd++] = c;
  23.                         break;
  24.                 }
  25.                 else
  26.                         str[rd++] = c;
  27.         }
  28.         if (0 == rd) return NULL;
  29.         else
  30.         {
  31.                 str[rd] = '\0';
  32.                 return str;
  33.         }
  34. }
  35.