Portability Library
Paul DuBois
dubois@primate.wisc.edu
http://www.primate.wisc.edu/people/dubois/
16 January 1997

This library provides a consistent interface across systems to
operations that tend to vary in ugly ways for different UNIX systems,
such as file locking and directory reading.  By using the library,
programs can use a set of function names that don't vary across
systems.

I figured, why write the code to make these decisions in different
programs?  Why not figure it out once and package it up in a library
so any program can use the functions?

AcquireLock() may not work very well over an NFS link, but I figure
that if you're trying to do NFS locking, you deserve what you get.

ReadDir() - the character string returned should be copied by the calling
program if it is to be modified or accessed beyond the next ReadDir()
call.

CloseDir() is, strictly speaking, normally not necessary.  ReadDir()
closes the directory automatically when it reaches the end of the
directory you're reading.  If you call OpenDir() without closing the
previous directory, OpenDir() will close it for you.

It's preferable to use the opendir() method rather than the scandir()
method if possible:
- it maps more closely to the interface provided.
- it uses less memory (scandir allocates memory to hold all of the names).

If the scandir() method is used and a program does a lot of directory
scans, I suspect the program could run out of memory eventually.  There
is nothing about needing to free the memory pointed to by the directory
structure, but I find that executing many scandir()'s increase the running
image size.  On the other hand passing the structure to free() doesn't
keep the size from increasing, so I'm not sure what has to be freed.  I
suppose you have to walk through the structure and free individual entries,
but I've never tried it.
