NAME
read - read from a file descriptor
SYNOPSIS
#include
ssize_t read(int fd, void *buf, size_t count);
size_t and ssize_t are both int
fd: STDIN_FILENO for standard in (keyboard, effectively 0)
There are three numbers: the buff size (bSize), the acceptance count size (cSize) and the actually input size (iSize). When (iSize < cSize): if the input is terminated by Enter, then add one to the number of letters; if the input is terminated by ctrl+d, then no extra letter is appended. For example, user input: $ABC
with an Enter, then iSize == 4, and the buffer stores ASCII (* means garbage integers):
65 66 67 10 * * *user input: $ABC
with a ctrl+d, then iSzie == 3, and the buffer stores ASCII:
65 66 67 * * *When (iSize > cSize), the exceeding input is ignored and resultant iSize == cSize When (bSize < cSize), danger! The system does not perform boundary check! So one can input long enough to write out of the buffer's boundary and no warnings given. This probably won't corrupt immediately, but it still can cause fatal error potentially at any time! When a read() function is encountered, the system waits for the input. And every call of read(), the buf is overwritten.
No comments:
Post a Comment