Stdio Modules

Due Date:
April 9, 1996
Note that I expect to give your next assignment before Spring break, however.
Deliverables:
When the project is complete, send me an e-mail message telling me the path to the project directory for this assignment.

The project directory is to contain three source files, a Makefile, and a report. In addition, the directory ~/man/man1 is to contain man pages for the executable programs you write for this project, and ~/man/man3 is to contain man pages for the library functions you develop for this assignment.

You may leave a README file in the project directory if you think that one is needed, but I neither expect nor require you to do so.

Requirements:
In addition to the information given here, be sure to consult the Grading Form for this assignment, which includes additional information about the requirements for this project.

Project Description

Your assignment is to write replacement versions of two functions that are part of the standard C I/O library, which will be called "stdio in this assignment. In addition to producing your own versions of these functions, you will use them to perform a timing experiment to determine the optimal buffer size for I/O on this system.

The two functions you are to write are __filbuf(), which is called internally by the stdio function getc(), and fopen(). In addition, you will write a main program which exercises your functions by reading a large data file into memory.

The report, which you are to submit as a text file in the format of a research report, is to summarize your experiments with different buffer sizes for __filbuf(). See the Written Report section below for information on what to put in the report.

You are to do the assignment as a sequence of steps, which are outlined here:

  1. Copy the default Makefile into your project directory, and edit it so that you can make any of four executable programs. One is to be called "stdio", and is to be made by linking the object module for the main program with the standard C library. A second program is to be called "myio" (or something similar), and is to be made by linking three modules: your main program, and separate modules that contain your own versions of __filbuf() and fopen(). The other two programs complete the permutations of combining the standard library functions and the two that you will write for this assignment.

    It is a requirement for this project that the same main module works with both the system-supplied versions of __filbuf() and fopen() and with your own versions. Likewise, your version of __filbuf() must work with the standard library version of fopen() and vice-versa.

  2. Write a main program which calls fopen() to open a data file for reading, reads the contents of the file one byte at a time using getc(), prints the number of bytes read, and exits.

    The program is to accept an optional command line argument specifying the name of the data file that it is to read. The default name for the data file is to be data.file.

  3. Create an RCS subdirectory in your project directory, and put your Makefile and all source files for the assignment under rcs management.

  4. Use calls to the times() system call from your main() to determine the speed with which the data file is read by your program. Display the results as the average number of microseconds of system and user time per byte read. You will need to call sysconf() to determine the resolution of the clock on the system you are using. (It's 100 Hz, but you must use sysconf() to get the value in your program.)

  5. Create a separate source file and write your own implementation of __filbuf(). Your function must use the value of the environment variable BUF_SIZE at execution time to set the size of the buffer that it uses. Use the getenv() library function for this.

    Do some experiments with BUF_SIZE to see how it affects the time it takes to read a data file. You will need a large data file to get a meaningful measure because of the granularity of the system clock.

  6. Create a separate source file and write your own version of fopen(). Make sure it is compatible with both your own version of __filbuf() and with the version supplied with the standard I/O library.

Written Report

Use your version of __filbuf() to investigate the effects of different buffer sizes on the speed with which getc() reads from a file.

The report is a text file (not a word-processing document) that starts with a meaningful title and the author's name centered at the top of the page, followed by four sections with the following names:



Christopher Vickery
Queens College of CUNY