getline.c (284B)
1 #include <os9/os9.h> 2 3 #include <libk.h> 4 5 int 6 getline(Chan *c, char *line, int size) 7 { 8 int n, r; 9 char ch; 10 11 for (ch = n = 0; n < size-1 && ch != '\n'; ++n) { 12 if ((r = chanread(c, &ch, 1)) < 0) 13 return -1; 14 if (r == 0) 15 break; 16 line[n] = ch; 17 } 18 line[n] = '\0'; 19 20 return n; 21 }