ISP: Assignment 2
The assignment, except problem 2, is due at the beginning of class on
Monday, October 11. Problem 2 is due October 13.
Please follow the instructions in submitting
your assignment.
- Create a test program that you can run on an unknown architecture
to find out how it handles bit and byte alignment. You should test your
program on Linux and Solaris (SPARC), at least.
The test program should be able to find out:
- Is the machine big endian or little endian?
- How big are the C data types char, short,
int, long and long long?
- How is the following structure laid out in memory:
struct {
int a:1;
int b:9;
int c:6;
short d;
short e;
int f;
}
To present your solution, you may have the program generate ASCII
graphics such as
msb
|...;...|...;...|
eeeee___ffff
or indicate the byte and bit offset numerically (e.g., "a: byte 3, bit
7"). For uniformity, number bits by their power-of-two-exponent, i.e.,
the least significant bit has the number 0, and the most significant bit
in a byte has the number 7. Note that the & operator cannot be used
for bit-fields, so you have to find another way of finding their
location in memory.
- Does the space allocation differ for bit fields on char, short, int
or long? I.e., is
int x:4;
int y:4;
different from
char x:4;
char y:4;
- Do big-endian and little-endian machines order fields in structs the
same way, e.g.,:
union {
struct {
unsigned int x:10;
unsigned int y:6;
} s;
unsigned short z;
} u;
Does x contain the least significant or the most significant
bits of z?
- In this problem, you will explore various aspects of character sets
and internationalization (I18N). Among the platforms
used in class, only Solaris 2.7 currently supports this
functionality.
- Using the iconv() function (not the /usr/bin/iconv
program), convert text passed as a command-line argument between ISO
8859-1 and UCS-4. UCS-4 is the full 32-bit 'universal character code'
or ISO 10646. You can find tables for UCS-4 at unicode.org.
Hint: you may need to do the conversion in two steps. Available
conversions can be deduced from /usr/lib/iconv/.
Print the output to standard out using wprintf(). Hint: ANSI
C allows "wide" character and string constants using the
L"some string"
L'x'
notation.
- Using the strfmon function, display 1234.567 currency units
as british pounds, as U.S. dollars and German Marks, using both the
national and international currency symbols. Your output should look
something like
USD 1,234.57 = $1,234.57
GBP 1,234.57 = £1,234.57
DEM 1.234,57 = DM1,234.57
(Note the rounding taking place.)
You can use the sample 8859-1 and UTF-8 files for
testing.
You can also convert between character sets using the iconv
utility, e.g.,
iconv -f 8859-1 -t UTF-8 8859.txt > utf8.txt
converts from an ISO 8859-1 to a UTF-8 file.
(Note: If you've already done the collation routine, you do not have to
do the modified version. However, collation doesn't seem to be working
yet on Solaris.)
-
Write a test program that checks if your operating system is fully
Y2K-compliant. To determine this, check whether it handles the leap
year computation for the year 2000 correctly. Use the Unix time and
date routines to compute the weekday for February 29, 2000. Check what
happens if you try to compute the weekday for February 29, 1999.
-
Compute file system statistics for your home directory and
recursively the files in the directory tree below that. Compute the
following statistics:
- size of file; show as a histogram (table or graph), with
logarithmically scaled bin sizes (i.e., bin boundaries of 0 bytes, 4
bytes, 16 bytes, 64 bytes, 256 bytes, 1024 bytes, ...) indicating the
frequency of files that fall within a given range of sizes;
- distribution of the age of files (log. histogram, i.e., younger
than 1 hour, 1 day, 1 week, 1 month or 1 year) since modification,
access or last i-node change;
- frequency of different types of file (plain file, block or character
special, directory, socket, etc).
If your CS directory just got setup, it is probably more interesting to
tally results for your machine at work or your Cunix account. Sorry, no
ftw() allowed.
- Stevens, Problem 4.15. Write a program that prints out the date
when the last email arrived and when the user last read mail. On CS
systems, mail boxes are stored in /home/user/.mailspool.
- Stevens, Problem 4.18.
Last updated
by Henning Schulzrinne