Re: File name from stream

From: Gordon Burditt (gordonb.r8qjp_at_burditt.org)
Date: 04/28/05


Date: Thu, 28 Apr 2005 17:14:32 -0000


>>>I think it's an oversight that the original implementation of streams
>>>didn't record the file name being opened. If i pass the stream as a
>>>parameter to a function, the function cannot print an error message
>>>that includes the file name of the stream.
>>
>> This is a *GOOD* thing, as if I pass stdin, stdout, or stderr to
>> that function, it won't *HAVE* a name to print (to say nothing of
>> the issue that unnamed pipes and sockets don't even HAVE names).
>> I also don't want the output looking different due to the program's
>> opinion of where I directed the output.
>>
>> Gordon L. Burditt
>
>But it could have been implemented so that streams of stdin, stdout,
>stderr, and pipe automatically got names: "stdin", "stdout", "stderr",
>and "pipe".

That's fine if there's a law that you can't use the name for anything
but an error message to be read by a human. Also, someone is going
to write code that gets upset when fopen(get_filename_from_stream(f),
"r") fails.

Hmm, and what happens when stdin *IS* a pipe, which is not that
uncommon.

And then some idiot is going to write code like:

int dosomething(FILE *f, double ***v) {
        int result;

        if (strcmp(get_filename_from_stream(f), "pipe") == 0) {
                /* do something different */
        } else {
                /* do the normal thing */
        }
        return result;
}

Ever hear of data hiding in C++? There's a reason why I pass streams
and DON'T pass file names as arguments to most functions that deal
with streams.

One guy wanted to take a read-only stream I passed in, figure out
the file name, open it for write, and fix (style) errors in it.
Then he got upset when doing that destroyed a lot of his source
code (due to a slight bug in the "fix" code, plus the fact that he
didn't know I was using his code in more than one program) which
he wasn't expecting to have directly passed to that function. The
really disturbing part was that his code was getting mangled and
he didn't realize that any changes were being made at all (so the
last couple of backups also had the corrupted code).

                                                Gordon L. Burditt



Relevant Pages

  • Re: File name from stream
    ... >>I think it's an oversight that the original implementation of streams ... > the issue that unnamed pipes and sockets don't even HAVE names). ... But it could have been implemented so that streams of stdin, stdout, ...
    (comp.unix.programmer)
  • Re: Corrupt Index
    ... Rebuilding the index seemed to fix the problem, ... The plan involves "Parallelism(Gather Streams)" which is close to MS's ...
    (microsoft.public.sqlserver.server)
  • Re: byte order
    ... Try it first, then profile, then fix it where performance is ... I use (unsigned-byte 8) streams and vectors to write ...
    (comp.lang.lisp)
  • Re: iTunes 8 and Airport Express
    ... Steve Hodgson wrote: ... I'm getting this here and there doesn't seem to be a clear fix ... streams to the various expresses we have here, ...
    (uk.comp.sys.mac)