[net.unix-wizards] dir.h

CHUQUI@MIT-MC (03/01/83)

From:  Charles F. Von Rospach <CHUQUI @ MIT-MC>

One of the people at the office here just noticed something wierd.

The directory structure (dir.h) has a string in it for the filename. This
string is 14 characters long, so when you get a 14 character Unix filename, it 
loses the null, making it hard to work with. Has anyone else seen this? Is 
this really a problem, or are we missing something?

chuck (chuqui at mit-mc)

guy (03/28/83)

1) Yes, it's a minor nuisance, but it doesn't take much code to get around.
"strncpy"ing the name to a 14+1 character buffer and setting buffer[14] to
'\0' will suffice.

2) 4.2BSD has a different directory structure.  The people who did it point
out that there should really be a standard library routine to read directories,
pass over empty entries, etc., so that only one small piece of code in the
system knows about directory formats.  It could return a structure containing
an I-number and a null-terminated entry name; the exact format (size of I-number
and entry name) would be system-dependent.  That way, code could be written
to port to versions of UNIX with different directory structures, and even to
some non-UNIX operating systems that are gracious enough to let user programs
read directories.  Unfortunately, only 4.2BSD systems (and systems which have
received the V7/32V/4.1BSD/USG UNIX versions of these routines and installed
them) have these routines.  Still, even if you don't have them you can write
your own, and thus would only have to solve this problem once.

						Guy Harris
						RLG Corporation
						seismo!rlgvax!guy

dan@BBN-UNIX (03/28/83)

From:  Dan Franklin <dan@BBN-UNIX>

Yes, the fact that entries in directories don't necessarily end with a null
is a real problem, and one which the standard Bell software expends some
effort to get around--any other programs which read directories should, too.
Actually, programs which work with directories should use the Berkeley
directory manipulation library routines; whether the program is going to
be brought up on Berkeley Unix or not, these will make life significantly
easier.  Messages about obtaining them have already appeared on this list.

	Dan Franklin (dan@bbn-unix.arpa)

rcj (03/29/83)

Funny this should come up, I ran into the dir.h problem just yesterday.
I solved the problem by doing a read of (sizeof(dirbuf) - 1) bytes
(dirbuf being my directory structure) instead of a read of sizeof(dirbuf)
bytes.  This gave the required null, but also would not distinguish
filenames that were non-unique to 13 characters.  If anyone has any
brilliant solutions other than a mod to dir.h, I would like to hear
them.

Thanks,

The MAD Programmer
alias:  Curtis Jackson	...!floyd!burl!rcj
			...!sb1!burl!rcj
			...!mhuxv!burl!rcj