[comp.os.os9] Need help w/directories under C

rh2y+@andrew.cmu.edu (Russell E. Hoffman, II) (12/16/90)

I am writing a utility program in C, and part of it requires grabbing
the directory stuff for a particular file (i.e. the size of the file,
date of creation, etc.)

I am presently using the opendir() and readdir() routines to read in the
filenames, and then i do an open() on an individual file to get a path
to it, then a _gs_gfd() to get its file descriptor. This works fine,
unless the particular file happens to itself be a directory. In this case,
_gs_gfd() returns -1, an error. How can I tell if a file is a directory
or not? I was hoping that _gs_gfd() would be of use, by reading the file
descriptor and then getting its attribute byte, but obviously this is not
going to work.   Any hints?


Thanks in advance,
Russell Hoffman
rh2y+@andrew.cmu.edu
Carnegie Mellon University

blarson@blars (12/17/90)

In article <0bOkkiu00WB6QLT0M4@andrew.cmu.edu> rh2y+@andrew.cmu.edu (Russell E. Hoffman, II) writes:
>I am writing a utility program in C, and part of it requires grabbing
>the directory stuff for a particular file (i.e. the size of the file,
>date of creation, etc.)
>
>I am presently using the opendir() and readdir() routines to read in the
>filenames, and then i do an open() on an individual file to get a path
>to it, then a _gs_gfd() to get its file descriptor. This works fine,
>unless the particular file happens to itself be a directory.

When the open(file, 0) fails, do an open(file, S_IFDIR) .  Then do the
_gs_gfd() as normal.

Alternatibly, if you run by the superuser (or your program is setuid
superuser) you could open the raw disk and read the file descriptor
directly.  This would be less overhead, but very os9 specific.


-- 
blarson@usc.edu
		C news and rn for os9/68k!
-- 
Bob Larson (blars)	blarson@usc.edu			usc!blarson
	Hiding differences does not make them go away.  Accepting
	differences makes them unimportant.

pete@wlbr.imsd.contel.com (Pete Lyall) (12/18/90)

When you open the files that are directories, a conventional OPEN
for read should fail. After it fails, attempt to open it with the 
READ + DIR attributes.


Pete

-- 
Pete Lyall                                                   Contel Corporation
Compuserve: 76703,4230              OS9_Net: (805) 375-1401 (24hr 300/1200/2400)
Internet: pete@wlbr.imsd.contel.com     UUCP: {hacgate,jplgodo,voder}!wlbr!pete