[comp.std.c] directory handling in ansi C

beech@ms.uky.edu (Wayne Beech) (11/21/89)

Hello,

Does anyone know the rationale behind not specifically defining a set of
functions to work with directories in ansi C; things like opendir(),
next_dir_entry(), isdir(), etc.  if you are writing a program that works
with directories that is expected to run on unix and non-unix machines how
do you handle this? with a bunch of #ifdef UNIX #elif SOMEOTHERMACHINE ....?

-- 
=============================================================================
UUCP  : !ukma!beech
BITNET: beech@ukma
DOMAIN: beech@ms.uky.edu

news@haddock.ima.isc.com (overhead) (11/22/89)

In article <13288@s.ms.uky.edu> beech@ms.uky.edu (Wayne Beech) writes:
>Does anyone know the rationale behind not specifically defining a set of
>functions to work with directories in ansi C; things like opendir(),
>next_dir_entry(), isdir(), etc.  if you are writing a program that works
>with directories that is expected to run on unix and non-unix machines how
>do you handle this? with a bunch of #ifdef UNIX #elif SOMEOTHERMACHINE ....?

I would hope that UNIX and non-UNIX OSs would used the POSIX
semantics for this.  POSIX is a standard, and covers this issue.
The ANSI C document has a finite scope (as does any standard or
document of finite length).  Directory stuff is one of those
areas I now do without ifdefs.  Sometimes, I have to provide my
own directory library routines, implemented with what they gave
me, but more systems are being provided using the POSIX and ANSI
C guides.  This has been a help.

Stephen.

gwyn@smoke.BRL.MIL (Doug Gwyn) (11/22/89)

In article <13288@s.ms.uky.edu> beech@ms.uky.edu (Wayne Beech) writes:
>Does anyone know the rationale behind not specifically defining a set of
>functions to work with directories in ansi C; things like opendir(), ...

What's a directory?

mcdonald@aries.uiuc.edu (Doug McDonald) (11/22/89)

In article <11659@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes:
>In article <13288@s.ms.uky.edu> beech@ms.uky.edu (Wayne Beech) writes:
>>Does anyone know the rationale behind not specifically defining a set of
>>functions to work with directories in ansi C; things like opendir(), ...
>
>What's a directory?

Interesting question. Let's try another: what is a file? 

Assuming that MR. Gwyn, who is a member of X3J11, does not know what a
directory is, we shall, since he is a member of the committee, and it
has indeed included things called "files" in its hosted library,
know what a "file" is. 

So does X3J3 (know what a file is). So, Mr. Gwyn, how, in C,
do I open a file written by

      open(unit = 11, form="unformatted", access="sequential",
     1   status = "new")
      x = 3.3
      i = 17
      write(11) x,i
      write(11) x,i

and read it, in C, to recover the numbers 3.3, 17, 3.3, 17 in that
order?

Okay, seriously, C assumes that things called "files" are a lot simpler
than they are in general. So a precedent is set: the promulgators
of C are prepared to accept a subset of possible operations on "files".
Why not do the same for directories?

"No prior art" (in C of course) is an acceptable answer. I find
it hard to believe that X3J11 can come up with any other explanation
that isn't stupid, other than that or "we ran out of steam" or 
"it's already too big" or "we don't care about directories".

The correct answer is likely all but the last.

Doug McDonald

davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) (11/22/89)

In article <1989Nov21.235640.3662@ux1.cso.uiuc.edu> mcdonald@aries.scs.uiuc.edu (Doug McDonald) writes:

| "No prior art" (in C of course) is an acceptable answer. I find
| it hard to believe that X3J11 can come up with any other explanation
| that isn't stupid, other than that or "we ran out of steam" or 
| "it's already too big" or "we don't care about directories".

  How about "we can't agree on how to do it right and can agree not to
do a half-assed job of it." Is that so bad a position? 
-- 
bill davidsen	(davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
"The world is filled with fools. They blindly follow their so-called
'reason' in the face of the church and common sense. Any fool can see
that the world is flat!" - anon

henry@utzoo.uucp (Henry Spencer) (11/23/89)

In article <13288@s.ms.uky.edu> beech@ms.uky.edu (Wayne Beech) writes:
>Does anyone know the rationale behind not specifically defining a set of
>functions to work with directories in ansi C...

The very concept of "directory" is not portable, never mind the set of
operations you can perform on one.

X3J11 decided early that (with the exception of the free-standing/hosted
split) it did *not* want a standard with multiple levels or optional
parts.  Ignoring the free-standing business, there is *one* C standard.
This is a Good Thing.  It did limit the committee to providing only
functions that could be implemented on an enormous range of systems,
however.
-- 
A bit of tolerance is worth a  |     Henry Spencer at U of Toronto Zoology
megabyte of flaming.           | uunet!attcan!utzoo!henry henry@zoo.toronto.edu