As usual, keep a log in the file lab5.txt of what you do in the lab so that you can reproduce the results later. This should not merely be a transcript of what you typed: it should be more like a true lab notebook, in which you briefly note down what you did and what happened.
You're helping to maintain coreutils, but a recent version has a bug in its implementation of the ls program. (Actually, it has two bad bugs, but for now we'll just look at the first one.)
The bug is that ls -t mishandles files whose time stamps are very far in the past. It seems to act as if they are in the future. For example:
$ touch -d '1918-11-11 11:00 GMT' wwi-armistice $ touch now $ sleep 1 $ touch now1 $ ls -lt wwi-armistice now now1 -rw-r--r-- 1 eggert eggert 0 Nov 11 1918 wwi-armistice -rw-r--r-- 1 eggert eggert 0 Feb 5 15:57 now1 -rw-r--r-- 1 eggert eggert 0 Feb 5 15:57 now
Use a debugger to figure out what went wrong and to fix the corresponding source file.
Construct a patch file lab5.patch containing your fixes, in the form of a ChangeLog entry followed by a diff -u patch.
Write a program binsort that takes a single argument N (where N is a positive decimal integer), reads N-byte records from standard input, sorts them, and outputs the result to standard output. If standard input ends in a partial record that contains fewer than N bytes, binsort should treat it as if it were padded with trailing null ('\0') bytes.
Use lexicographic byte comparison to compare each record, in the style of the memcmp function. Use <stdio.h> functions to do I/O. Use malloc, realloc and free to allocate enough storage to hold all the input, and use qsort to sort the data. Accept any positive decimal integer string N that strtoul would. If the program encounters an error of any kind (including input, output or memory allocation failures, missing or extra arguments, a N that is not a positive integer or is too large to be represented), it should report the error to stderr and exit with status 1; otherwise, the program should succeed and exit with status 0. The program need not report stderr output errors.
For example, assuming your source code has no lines longer than 100 bytes, the command:
awk '{printf "%-100s\n", $0}' binsort.c | ./binsort 101 | sed 's/ *$//'
should output something that is nearly equivalent to the output of the command sort binsort.c.
Submit the following files.
All files should be ASCII text files, with no carriage returns, and with no more than 200 columns per line. The C source file should contain no more than 132 columns per line. The shell commands
expand lab5.txt lab5.patch | awk '/\r/ || 200 < length' expand binsort.c | awk '/\r/ || 132 < length'
should output nothing.