This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Functions | |
int | getinput (char *buffer, int maxchars) |
|
Definition at line 60 of file getinput.c. Referenced by main().
00061 { 00062 int flags; 00063 int nchars; 00064 int index = 0; 00065 00066 /* save the flags */ 00067 flags = fcntl(STDIN_FILENO, F_GETFL); 00068 00069 /* make terminal non-blocking */ 00070 fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); 00071 00072 /* read the outstanding chars, one by one, until newline or no more */ 00073 while (1 == (nchars = read(STDIN_FILENO, &buffer[index], 1))) 00074 { 00075 if (buffer[index++] == '\n') 00076 { 00077 buffer[index] = 0; /* null terminate */ 00078 break; 00079 } 00080 } 00081 00082 /* restore the terminal */ 00083 fcntl(STDIN_FILENO, F_SETFL, flags); 00084 00085 if (nchars == -1) 00086 { 00087 return -1; /* nothing new */ 00088 } 00089 00090 if (nchars == 0) 00091 { 00092 return 0; /* end of file */ 00093 } 00094 00095 return index; 00096 } |