www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/04/11/14:48:57

Date: Sun, 9 Apr 1995 09:02:45 +0300
From: eliz AT is DOT elta DOT co DOT il (Eli Zaretskii)
To: djgpp AT sun DOT soe DOT clarkson DOT edu, damianf AT WPI DOT EDU
Subject: Re: Raw file access question

> I need to do some raw binary file i/o.  Under UNIX, I'd just use read and
> write, which is exactly what I tried to do - and failed.  My file contains
> an end-of-file char (0x1a under DOS), and read stops right there, reporting
> end-of-file.  At this point, I see no other alternative than going right to
> DOS via int21, as I've done in real mode before.  However, it seems like
> there should be an easier way.  Is there?

Yes, there is: open the file in BINARY mode.  For files open with fopen(), you
should add "b" to the list of open mode, like this:

	FILE *fp = fopen("myfile.dat", "rb");  /* this is for reading in binary */

For files open with open(), add O_BINARY to the flags, like this:

	int fd = open("myfile.dat", O_RDONLY | O_BINARY);

*Then* the C library will behave like you'd expect under Unix.

Btw, this is explained in the DJGPP FAQ list, Section 9.6.  You can get the latest
version of the FAQ list as faqNNN.zip (where NNN is the version number) from the
same place where you've got DJGPP.  Or point your Web browser to this URL:

	http://www.delorie.mv.com/

and follow the links to the hypertext version of the FAQ, which is also searchable
by keyword.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019