comp.lang.ada
 help / color / mirror / Atom feed
* Portable way to read/write from a binary file?
@ 1994-09-14  1:40 Dale Stanbrough
  1994-09-14  3:51 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Dale Stanbrough @ 1994-09-14  1:40 UTC (permalink / raw)


Is there a _portable_ way to read/write from a binary file using only
Ada83 or Ada94 I/O routines?

I would like to be able to read the individual bytes from a file, as can
be achieved using Unix read/write.

Dale
-------------------------------------------------------------
Dale Stanbrough, RMIT, Melbourne, Australia, dale@rmit.edu.au
GNU Ada Compiler (GNAT) => the best $0 you'll ever spend.
Available for DOS, Linux, OS/2, Sun Sparc, Sun Solaris, ...
Coming to a GNU supported platform near you soon...



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

* Re: Portable way to read/write from a binary file?
  1994-09-14  1:40 Portable way to read/write from a binary file? Dale Stanbrough
@ 1994-09-14  3:51 ` Robert Dewar
  1994-09-16  1:47   ` Lee_Robert_Willis
  1994-09-14 22:39 ` Dale Stanbrough
  1994-09-15 22:59 ` Keith Thompson @pulsar
  2 siblings, 1 reply; 10+ messages in thread
From: Robert Dewar @ 1994-09-14  3:51 UTC (permalink / raw)


sequential_io instantiated for a byte or character type may work, but is
not guaranteed, and may well be gruseomely slow.

best get is just to use pragma interface and use the appropriate unix
routines directly, whjy not>




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

* Re: Portable way to read/write from a binary file?
  1994-09-14  1:40 Portable way to read/write from a binary file? Dale Stanbrough
  1994-09-14  3:51 ` Robert Dewar
@ 1994-09-14 22:39 ` Dale Stanbrough
  1994-09-15 17:08   ` Robert Dewar
  1994-09-16  5:00   ` R_Tim_Coslet
  1994-09-15 22:59 ` Keith Thompson @pulsar
  2 siblings, 2 replies; 10+ messages in thread
From: Dale Stanbrough @ 1994-09-14 22:39 UTC (permalink / raw)


Subject: Re: Portable way to read/write from a binary file?
From: Robert Dewar, dewar@cs.nyu.edu
Date: 13 Sep 1994 23:51:00 -0400
In article <355rv4$eg8@gnat.cs.nyu.edu> Robert Dewar, dewar@cs.nyu.edu writes:
>sequential_io instantiated for a byte or character type may work, but is
>not guaranteed, and may well be gruseomely slow.
>
>best get is just to use pragma interface and use the appropriate unix
>routines directly, whjy not>

Because I wanted a portable solution that wasn't tied to a particular
operating system. It may be that there are comparable routines on _all_
operating systems, but it still (potentially) leaves you with code to change
when porting.

Dale
-------------------------------------------------------------
Dale Stanbrough, RMIT, Melbourne, Australia, dale@rmit.edu.au
GNU Ada 94 (GNAT) => the best $0 you'll ever spend.
Available for DOS, Linux, OS/2, Sun Sparc, Sun Solaris, ...
Coming to a GNU supported platform near you soon...



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

* Re: Portable way to read/write from a binary file?
  1994-09-14 22:39 ` Dale Stanbrough
@ 1994-09-15 17:08   ` Robert Dewar
  1994-09-16  5:00   ` R_Tim_Coslet
  1 sibling, 0 replies; 10+ messages in thread
From: Robert Dewar @ 1994-09-15 17:08 UTC (permalink / raw)


There is a set of C/Unix/ANSIC routines (some intersection) that is VERY
portable, as portable as anything else. The GNU porting guide (perhaps Richard
can give a better reference) has details on what can typically be counted on.




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

* Re: Portable way to read/write from a binary file?
  1994-09-14  1:40 Portable way to read/write from a binary file? Dale Stanbrough
  1994-09-14  3:51 ` Robert Dewar
  1994-09-14 22:39 ` Dale Stanbrough
@ 1994-09-15 22:59 ` Keith Thompson @pulsar
  2 siblings, 0 replies; 10+ messages in thread
From: Keith Thompson @pulsar @ 1994-09-15 22:59 UTC (permalink / raw)


In <355kao$38d@goanna.cs.rmit.oz.au> Dale Stanbrough <dale@goanna.cs.rmit.edu.au> writes:
> Is there a _portable_ way to read/write from a binary file using only
> Ada83 or Ada94 I/O routines?
> 
> I would like to be able to read the individual bytes from a file, as can
> be achieved using Unix read/write.

For Ada 83, POSIX_IO is reasonably portable (among implementations that
support it).

For Ada 94 (assuming X=4 8-)}), I think Stream_IO does what you want.

-- 
Keith Thompson (The_Other_Keith)  kst@alsys.com
TeleSoft^H^H^H^H^H^H^H^H Alsys, Inc.
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
/user/kst/.signature: I/O error (core dumped)



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

* Re: Portable way to read/write from a binary file?
  1994-09-14  3:51 ` Robert Dewar
@ 1994-09-16  1:47   ` Lee_Robert_Willis
  0 siblings, 0 replies; 10+ messages in thread
From: Lee_Robert_Willis @ 1994-09-16  1:47 UTC (permalink / raw)


>sequential_io instantiated for a byte or character type may work, but is
>not guaranteed, and may well be gruseomely slow.

FWIW: This will not work under VMS.  (Been there, tried that)

   -lee     Lee_Robert_Willis@cup.portal.com
   



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

* Re: Portable way to read/write from a binary file?
  1994-09-14 22:39 ` Dale Stanbrough
  1994-09-15 17:08   ` Robert Dewar
@ 1994-09-16  5:00   ` R_Tim_Coslet
  1994-09-19  2:59     ` Dale Stanbrough
  1 sibling, 1 reply; 10+ messages in thread
From: R_Tim_Coslet @ 1994-09-16  5:00 UTC (permalink / raw)


>In article <355rv4$eg8@gnat.cs.nyu.edu> Robert Dewar, dewar@cs.nyu.edu writes:
>>sequential_io instantiated for a byte or character type may work, but is
>>not guaranteed, and may well be gruseomely slow.
>>
>>best get is just to use pragma interface and use the appropriate unix
>>routines directly, whjy not>
>
>Because I wanted a portable solution that wasn't tied to a particular
>operating system. It may be that there are comparable routines on _all_
>operating systems, but it still (potentially) leaves you with code to change
>when porting.
>
>Dale
>-------------------------------------------------------------
>Dale Stanbrough, RMIT, Melbourne, Australia, dale@rmit.edu.au
>GNU Ada 94 (GNAT) => the best $0 you'll ever spend.
>Available for DOS, Linux, OS/2, Sun Sparc, Sun Solaris, ...
>Coming to a GNU supported platform near you soon...

Or maybe the code will eventually be used in an embedded environment that has
NO operating system of any kind, just a small Ada Runtime customized
to the hardware environment.

                                        R. Tim Coslet

Usenet: R_Tim_Coslet@cup.portal.com
        technology, n.  domesticated natural phenomena



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

* Re: Portable way to read/write from a binary file?
  1994-09-16  5:00   ` R_Tim_Coslet
@ 1994-09-19  2:59     ` Dale Stanbrough
  1994-09-19 17:46       ` Bob Duff
  1994-09-20 22:51       ` Dale Stanbrough
  0 siblings, 2 replies; 10+ messages in thread
From: Dale Stanbrough @ 1994-09-19  2:59 UTC (permalink / raw)


In article <Cw717J.66q@alsys.com> , kst@alsys.com writes:
>For Ada 94 (assuming X=4 8-)}), I think Stream_IO does what you want.
>

Unfortunately not (as I read it!)
Each object in a stream has a tag appended to it so that the 
procedure S'Class'Read can reconstruct the value from the tag 
contained within the stream (13.13.2.14).
As well the representation of stream elements is implementation
defined (13.13.2.17)

The best solution seems to be to use pragma import or use the
Posix_IO package.

Dale
-------------------------------------------------------------
Dale Stanbrough, RMIT, Melbourne, Australia, dale@rmit.edu.au
GNU Ada 94 (GNAT) => the best $0 you'll ever spend.
Available for DOS, Linux, OS/2, Sun Sparc, Sun Solaris, ...
Coming to a GNU supported platform near you soon...



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

* Re: Portable way to read/write from a binary file?
  1994-09-19  2:59     ` Dale Stanbrough
@ 1994-09-19 17:46       ` Bob Duff
  1994-09-20 22:51       ` Dale Stanbrough
  1 sibling, 0 replies; 10+ messages in thread
From: Bob Duff @ 1994-09-19 17:46 UTC (permalink / raw)


In article <35iuqj$5dj@goanna.cs.rmit.oz.au>,
Dale Stanbrough  <dale@goanna.cs.rmit.edu.au> wrote:
>In article <Cw717J.66q@alsys.com> , kst@alsys.com writes:
>>For Ada 94 (assuming X=4 8-)}), I think Stream_IO does what you want.
>>
>
>Unfortunately not (as I read it!)
>Each object in a stream has a tag appended to it so that the 
>procedure S'Class'Read can reconstruct the value from the tag 
>contained within the stream (13.13.2.14).

No.  S'Class'Read and S'Class'Write do not generally read and write tags.
(S'Class'Input and S'Class'Output do.)
Furthermore, if you're not using tagged types, then no tags are written
or read by any of these things.

The Stream_IO package and the streams stuff in 13.13 are definitely
intended for doing binary I/O.  A typical case is where the various
types are *not* tagged (or discriminated or unconstrained arrays or
anything fancy like that), and S'Write and S'Read can be used directly.
You won't get tags or other dope mixed in with your data.

>As well the representation of stream elements is implementation
>defined (13.13.2.17)

True, but in practice that's not a big problem.  After all, the
representation of Sequential_IO, Direct_IO, and Text_IO files are also
implementation defined.  You have to trust the implementation to use a
"reasonable" representation.  13.13.2(18-20) give advice about what a
reasonable representation is.  Most languages that support binary I/O
are similar in this regard.  (Not COBOL, though.)

>The best solution seems to be to use pragma import or use the
>Posix_IO package.

Note that Posix_IO, or pretty much any other I/O package, also has an
implementation-defined representation of the data.
-- 
Bob Duff                                bobduff@inmet.com
Oak Tree Software, Inc.
Ada 9X Mapping/Revision Team (Intermetrics, Inc.)



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

* Re: Portable way to read/write from a binary file?
  1994-09-19  2:59     ` Dale Stanbrough
  1994-09-19 17:46       ` Bob Duff
@ 1994-09-20 22:51       ` Dale Stanbrough
  1 sibling, 0 replies; 10+ messages in thread
From: Dale Stanbrough @ 1994-09-20 22:51 UTC (permalink / raw)


I wrote:
>In article <Cw717J.66q@alsys.com> , kst@alsys.com writes:
>>For Ada 94 (assuming X=4 8-)}), I think Stream_IO does what you want.
>>
>
>Unfortunately not (as I read it!)
>Each object in a stream has a tag appended to it so that the 
>procedure S'Class'Read can reconstruct the value from the tag 
>contained within the stream (13.13.2.14).

Keith Thompson emailed a correction to this; what I said is true only
for tagged types.
I had previously skimmed over streams in the LRM and produced a particularly 
premature perception of how it performs. When Keith posted his original reply
I opened up the LRM to the section I quoted - the only bit which did agree with
how I thought it worked! (Damn!   !:-(   ).

So here's a question that I couldn't find the answer to (no more posturing
about how it does work from me! :-). Does a stream of heterogenous scalar
elements have any encoding so that you can decide what the byte stream
represents, or does the format of the data in a stream have to be previously
determined?

Dale
-------------------------------------------------------------
Dale Stanbrough, RMIT, Melbourne, Australia, dale@rmit.edu.au
GNU Ada 94 (GNAT) => the best $0 you'll ever spend.
Available for DOS, Linux, OS/2, Sun Sparc, Sun Solaris, ...
Coming to a GNU supported platform near you soon...



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

end of thread, other threads:[~1994-09-20 22:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-09-14  1:40 Portable way to read/write from a binary file? Dale Stanbrough
1994-09-14  3:51 ` Robert Dewar
1994-09-16  1:47   ` Lee_Robert_Willis
1994-09-14 22:39 ` Dale Stanbrough
1994-09-15 17:08   ` Robert Dewar
1994-09-16  5:00   ` R_Tim_Coslet
1994-09-19  2:59     ` Dale Stanbrough
1994-09-19 17:46       ` Bob Duff
1994-09-20 22:51       ` Dale Stanbrough
1994-09-15 22:59 ` Keith Thompson @pulsar

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