Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: encapsulating directory operations Date: Tue, 20 May 2025 22:49:01 -0700 Organization: None to speak of Lines: 52 Message-ID: <87h61ezf76.fsf@nosuchdomain.example.com> References: <100h650$23r5l$1@dont-email.me> <20250520065158.709@kylheku.com> <100i2la$292le$1@dont-email.me> <87a5770xjw.fsf@nosuchdomain.example.com> <100j09o$2f04b$1@dont-email.me> <87tt5ezx9y.fsf@nosuchdomain.example.com> <20250520171848.66@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Wed, 21 May 2025 07:49:01 +0200 (CEST) Injection-Info: dont-email.me; posting-host="151d526d8f9bb67aa0331e0f184aea14"; logging-data="2841629"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eEHX2wf5nL3BPYcVF1lPf" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:+xek9ynpnOgtW60zX1ZEROVsQ3I= sha1:V/zzTrfT9Vs8DzXocodM327tkq4= Xref: csiph.com comp.lang.c:393493 Kaz Kylheku <643-408-1753@kylheku.com> writes: > On 2025-05-20, Keith Thompson wrote: >> "Paul Edwards" writes: [...] >>> As far as I know, there was never any LOGICAL barrier >>> to including basic directory manipulation in C90. >> >> None that I can think of. > > There was a significant barrier. The ANSI group which standardized > C was mainly looking at surveying and codifying existing practice. Agreed. I consider that a practical barrier, not a "LOGICAL" one. The ANSI C committee *could* have added directory operations to the C standard library. (I'm not suggesting that they should have.) [...] >> Sure, it would be theoretically possible to treat directories as files, >> and to make reading from a FILE* resulting from calling fopen() with a >> directory name give you access to the directory entries. > > I implemented something like this. It is fine; I don't regret it. > > i1> (open-directory ".") > # > 2> (get-line *1) > "htrailer.txr" > 3> (get-line *1) > "y.output.bison" > 4> (get-line *1) > "jmp.S" > 5> (open-file "/etc/hosts") > # > 6> (get-line *5) > "127.0.0.1\tlocalhost" > 7> (get-line *5) > "127.0.1.1\tsun-go" It looks like it treats a directory as a file containing a sequence of *lines*, each of which is a file name. The problem with that is that on some systems, file names can legally include newline characters. I don't suggest it's not a horrible idea to take advantage of that, but it is something that would have to be addressed in a language standard. [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */