From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Determining size of Standard_Input (when file contents are piped into a program). Date: Sun, 06 Jan 2019 19:05:31 -0800 Organization: None to speak of Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader01.eternal-september.org; posting-host="8aece196c9e75518dbb5186db17fe852"; logging-data="32487"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Q7IwTnG5IuVgYnOsVVy8v" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:anKTBEpo4X9Vwkc+e5PCHm8Q/OY= sha1:1FAsUhCJUDk+vAVaHtT2HaM3GGo= Xref: reader01.eternal-september.org comp.lang.ada:55232 Date: 2019-01-06T19:05:31-08:00 List-Id: Niklas Holsti writes: > On 19-01-06 13:02 , Bojan Bozovic wrote: >> Is there platform independent way to do this? I was unable to find >> anything in RM under Ada.text_IO. > > I would say that this is impossible in principle. On some systems, other > concurrent programs can write more data into the input file as your > program is reading the file, so the input file can grow during the > execution of the program, and may not even have any fixed upper bound on > its size (apart from the total space available in the system). > > IMO the only robust way is to read all of standard input and store it > within the program, or in a temporary file, and then process the stored > data. I mostly agree, but it could be possible in some limited circumstances. For example, if a program on Linux has its standard input redirected from a file, the system still keeps track of the identity of the file (/proc/$PID/fd/0 is a symbolic link to the file). You can then determine the size of that file. This is all very system-specific and not generally useful -- though some programs might use it as a heuristic to estimate how much memory to allocate (only an estimate, since the size of the file might change while the program is running). And if input is not a regular file, no meaningful size information will be available. Ada doesn't provide a portable way to do this. -- Keith Thompson (The_Other_Keith) kst@mib.org Will write code for food. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"