comp.lang.ada
 help / color / mirror / Atom feed
* Determining size of Standard_Input (when file contents are piped into a program).
@ 2019-01-06 11:02 Bojan Bozovic
  2019-01-06 12:51 ` Niklas Holsti
  0 siblings, 1 reply; 5+ messages in thread
From: Bojan Bozovic @ 2019-01-06 11:02 UTC (permalink / raw)


Is there platform independent way to do this? I was unable to find anything in RM under Ada.text_IO.

Thanks,
Bojan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Determining size of Standard_Input (when file contents are piped into a program).
  2019-01-06 11:02 Determining size of Standard_Input (when file contents are piped into a program) Bojan Bozovic
@ 2019-01-06 12:51 ` Niklas Holsti
  2019-01-06 14:53   ` Bojan Bozovic
  2019-01-07  3:05   ` Keith Thompson
  0 siblings, 2 replies; 5+ messages in thread
From: Niklas Holsti @ 2019-01-06 12:51 UTC (permalink / raw)


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.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Determining size of Standard_Input (when file contents are piped into a program).
  2019-01-06 12:51 ` Niklas Holsti
@ 2019-01-06 14:53   ` Bojan Bozovic
  2019-01-07  3:05   ` Keith Thompson
  1 sibling, 0 replies; 5+ messages in thread
From: Bojan Bozovic @ 2019-01-06 14:53 UTC (permalink / raw)


On Sunday, January 6, 2019 at 1:51:11 PM UTC+1, Niklas Holsti wrote:
> 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.
> 
> -- 
> Niklas Holsti
> Tidorum Ltd
> niklas holsti tidorum fi
>        .      @       .

Yes that makes sense. Thank you.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Determining size of Standard_Input (when file contents are piped into a program).
  2019-01-06 12:51 ` Niklas Holsti
  2019-01-06 14:53   ` Bojan Bozovic
@ 2019-01-07  3:05   ` Keith Thompson
  2019-01-07  9:32     ` Niklas Holsti
  1 sibling, 1 reply; 5+ messages in thread
From: Keith Thompson @ 2019-01-07  3:05 UTC (permalink / raw)


Niklas Holsti <niklas.holsti@tidorum.invalid> 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  <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Determining size of Standard_Input (when file contents are piped into a program).
  2019-01-07  3:05   ` Keith Thompson
@ 2019-01-07  9:32     ` Niklas Holsti
  0 siblings, 0 replies; 5+ messages in thread
From: Niklas Holsti @ 2019-01-07  9:32 UTC (permalink / raw)


On 19-01-07 05:05 , Keith Thompson wrote:
> Niklas Holsti <niklas.holsti@tidorum.invalid> 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).

Ah, good to know.

> You can then determine the size of that file.

Yep, but the file-size may grow with time and -- on some systems -- the 
added data may become visible (readable) to a program reading the file. 
But not on all systems -- I ran across this quirk when a certain 
multi-process application which worked under Linux did not work under 
Apple OS/X, because it used such a growing file to communicate data from 
one process (writer) to another (reader). On OS/X, the reader never saw 
any data that the writer wrote _after_ the reader opened the file. Of 
course this may also depend on the Ada run-time in some way, although in 
both cases GNAT was used.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-07  9:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-06 11:02 Determining size of Standard_Input (when file contents are piped into a program) Bojan Bozovic
2019-01-06 12:51 ` Niklas Holsti
2019-01-06 14:53   ` Bojan Bozovic
2019-01-07  3:05   ` Keith Thompson
2019-01-07  9:32     ` Niklas Holsti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox