kgets.c (251B)
1 #include <os9/os9.h> 2 3 #include <libk.h> 4 5 char * 6 kgets(char *s, int n) 7 { 8 int ch = 0; 9 char *t = s; 10 11 while (--n > 0 && (ch = getch()) != EOF) { 12 if ((*t++ = ch) == '\n') 13 break; 14 } 15 if (ch == EOF && s == t) 16 return NULL; 17 *t = '\0'; 18 19 return s; 20 }