- Do problem 1 on page 140 of the text.
- Modify the code for comreadline from Figure 9.8 so it
handles tabs. Assume that the output device does not understand tabs,
so you must echo 1 or more space characters every time tab is pressed.
Assume that tab stops are set every 8 spaces (the classic UNIX default).
Note that hitting erase when the character being erased is a tab is a
particularly challenge. That counts as part b of this question.
- Consider f, a pointer to an open-file object (a structure),
where f->put is the pointer to the function that implements
the put method for that particular file. In an object oriented
programming language like C++ or Java, a call to this method would be written
as f.put(c). In C, this is written (*f->put)(f,c)
Why is it necessary to pass the pointer f to the put
method in addition to using f to find the pointer that was needed
to call put?
Note: The above question has a specific answer, in the context of input-output
drivers, as well as a general answer that applies generally to object-oriented
programming, independent of the application demain.
- The Unix device independent I/O model is based on two basic system
functions, read() and write(). You can read the manual
pages for these using the man command, but note, you will have
to type man 2 write to get the documentation for the system function
from part 2 of the manual (the part that documents system functions).
Suppose you are writing to a block-sequential DMA device such as a
high-speed tape backup on a UNIX system. The block size on the device
is 512 bytes, but your software uses a buffer of 1000 bytes. Explain why
the operating system cannot do output directly from the user's bufer, but
must copy from the user's buffer to a system buffer before doing output to
the device. Make careful use of the relevant terminology from Chapter 9.