This preview shows page 1. Sign up to view the full content.
Unformatted text preview: nwritten = 0; /* and call write() again */ else return -1; /* errorno set by write() */ } nleft -= nwritten; ptr += nwritten; } return count; } code/src/csapp.c Figure 12.15: readn and writen: Robust versions of read and write Adapted from . 12.4. UNIX FILE I/O 623 Notice that the routines manually restart read or write if they are interrupted by the return from an application signal handler (lines 9-10). Manual restarts are unnecessary on Unix systems, which automatically restart interrupted read and write calls. However, other systems such as Solaris do not restart interrupted system calls, and on these systems we must manually restart them. 12.4.3 Robust Input of Text Lines Using the readline Function
A text line is a sequence of ASCII characters terminated by a newline character. (The newline character is the same as the ASCII line feed character (LF) and has a numeric value of 0x0a.) Many network applications, such as Web clients and servers, communicate using sequences of text lines. For these programs you s...
View Full Document