This preview shows page 1. Sign up to view the full content.
Unformatted text preview: but unfortunately programmers rarely check for this error. In Section 12.6.2 we will see that threaded programs that close already closed descriptors can suffer from a subtle race condition that sometimes causes a thread to catastrophically close another thread’s open descriptor. The bottom line: always check return codes, even for seemingly innocuous functions such as close. 12.4.7 Other Unix I/O Functions
Unix provides two additional I/O functions, open and lseek. The open function creates new ﬁles and opens existing ﬁles. In each case, it returns a descriptor that can be used by other Unix ﬁle I/O routines. We will not describe open in any more depth because a clear understanding requires numerous details about Unix ﬁle systems that are not relevant to network programming. The lseek function modiﬁes the current ﬁle position. Since it is illegal to change the current ﬁle position of a socket, we will not discuss this function either. 12.4.8 Unix I/O vs. Standard I/O
The ANSII C standard deﬁnes a set of input and output functions, known as the standard I/O library, that provide a higher-level and more convenient alternative to the underlying Unix I/O functions. Functions such as fopen, fclose, fseek, fread, fwrite, fgetc, fputc, fgets, fputs, fscanf, and...
View Full Document
- Spring '10
- The American