00001 00007 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00008 00009 #define NULL 0 00010 extern int getc(int); 00011 00018 char *fgets(int dev, char *s, int n) 00019 { 00020 int c = 0; 00021 char *cs; 00022 cs = s; 00023 00024 /* Read characters until maximum read length, */ 00025 /* end of line, or end of file */ 00026 while ((--n>0) && ((c = getc(dev))>=0)) 00027 { 00028 *cs++ = c; 00029 if (('\n' == c) || ('\r' == c)) 00030 { break; } 00031 } 00032 00033 /* Check for EOF or empty string */ 00034 if ((c<0) && (cs==s)) 00035 { return NULL; } 00036 00037 /* Terminate string and return */ 00038 *cs++ = '\0'; 00039 return s; 00040 }