- ar_hdr
- header1, file1, header2, file2, header3, file3 ...
- Symbol table (if archive contains object files (a.out(4))
- Format of symbol table
- number of symbols (4 bytes)
- array of offsets: length = 4 bytes * number_of_symbols
- name string table: names with end of string (EOS) on end strung together
- length of names <= 15, if not first archive file is long_name_table
- AR - Implementation
- use ASCII files so that you can look at the archive using more
- Incremental development
- print arguments: options, archiveName, files
- open archive and read through it, writing headers.
- translate ar date to unix time
- add on to end of archive
- delete from archive
- replace in archive
- ???
- open, read, unlink
- off_t lseek(int fd, off_t offset, int whence)
- SEEK_SET
- SEEK_CUR
- SEEK_END
- int truncate(char *path, int length)
- int rename(char *from, char *to)
- int sprintf ( char *s, char *format [, arg ] ... )
- Time revisited
- file times - (long) number of seconds since the epoch Jan 1, 1970 UTC
- UTC Universal Coordinated Time roughly equivalent to GMT and Zulu
- processing times are different
- File Time Data Structures
- time_t defined in /usr/include/time.h
- timeval, timezone and tm structures
struct timeval {
long tv_sec; /* seconds since Jan. 1, 1970 */
long tv_usec; /* and microseconds */
};
struct timezone {
int tz_minuteswest; /* of Greenwich */
int tz_dsttime; /* type of dst correction to apply */
};
struct tm {
int tm_sec; /* seconds (0 - 59) */
int tm_min; /* minutes (0 - 59) */
int tm_hour; /* hours (0 - 23) */
int tm_mday; /* day of month (1 - 31) */
int tm_mon; /* month of year (0 - 11) */
int tm_year; /* year - 1900 */
int tm_wday; /* day of week (Sunday = 0) */
int tm_yday; /* day of year (0 - 365) */
int tm_isdst; /* flag: daylight savings time in
effect */
long tm_gmtoff; /* offset from GMT in seconds */
char *tm_zone; /* abbreviation of timezone name */
- File Time system calls and functions
- Timing Tasks
- time command
- time function
#include "sys/times.h"
clock_t times(struct tms *buffer)
struct tms {
clock_t tms_utime; /* user time */
clock_t tms_stime; /* system time */
clock_t tms_cutime; /* user time, children */
clock_t tms_cstime; /* system time, children */
};
clock_t - measured in 1/60ths of a second
- Make - a system for maintaining programs that consist of multiple source files
- make specification files
- specification captures dependencies
- builds a tree
- performs minimal recompilation
- Make Advantages
- Make saves time - both typing and recompilation
- The Makefile documents the dependencies.
- For distribution of software one can `make' and `make install' a package with knowing anything about it.
- Makefiles - Make Specification Files
Definitions of the form
name=value
Target Groups of the form
target_1 : $dependency~list_1$
cmdlist_1
target_2 : dependency~list_2
cmdlist_2
...
- A Simple Makefile
# Makefile Example
prog: main.o routines.o
cc -o prog main.o routines.o
# Each command line starts with a \tab
main.o: main.c defs.h
cc -c main.c
routines.o: routines.c defs.h
cc -c routines.c
- Make Tree (forest)
- Macros - Builtin Rules
- # Another Makefile Example
FILES = Makefile defs.h main.c routines.c
OBJS = main.o routines.o
LIBES = -lm
CFLAGS = -g
LP = /fac/matthews/bin/p2c
INSTALL_DIR = /fac/matthews/bin
prog: main.o routines.o
$(CC) $(CFLAGS) $(OBJS) $(LIBES) -o prog
$(OBJS): defs.h
cleanup:
-rm *.o
-du
install: prog
mv prog $(INSTALL_DIR)
print: $(FILES)
pr $? > /tmp/manton && $(LP) /tmp/manton
-rm /tmp/manton
touch print
- Make Implementation Algorithm
Procedure newest(target)
If target is not in the target tree then
If file exists return(modification_time)
Else return(FAIL)
Else
min = modification_time of target
Foreach child in the dependency list Do
child_time = newest(child)
If child_time < min Then min = child_time
End
If min < modification_time of target Then
build(target)
min = now
EndIf
End
End
Begin {Main}
Parse Specification File
Build Dependency Tree
newest(target)
End