www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/08/02:51:41

Date: Thu, 8 Aug 1996 09:46:56 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Allen Pouratian <allenp AT nima DOT eecs DOT berkeley DOT edu>
Cc: djgpp AT delorie DOT com
Subject: Re: file "read" DOS vs. UNIX
In-Reply-To: <4tveqm$agf@agate.berkeley.edu>
Message-Id: <Pine.SUN.3.91.960808093937.19168M-100000@is>
Mime-Version: 1.0

On 3 Aug 1996, Allen Pouratian wrote:

> I am attempting to port Sam Leffler's TIFF library from UNIX to DOS
> and it keeps seg-faulting when the "read" system call is invoked in DOS.
> 
> It works fine under UNIX, is the "read" call legit under DOS?

Sure it is.  Just be sure to open all non-text files (such as graphics 
files) in BINARY mode.  The easiest way to ensure this is to set _fmode 
variable somewhere near the beginning of your `main' function, like this:

	#include <fcntl.h>
	.
	.
	.
	  _fmode = O_BINARY;

However, if the programs can also read and write binary files from 
standard streams stdin and stdout (like when they are in a pipe or in 
redirection), you will have also to switch stdin and/or stdout to binary 
mode, like this:

	#include <io.h>
	.
	.
	  if (!isatty (fileno (stdin)))
	    setmode (fileno (stdin), O_BINARY);

and the same with stdout, if you need to write binary files.  Both 
`_fmode' and `setmode' are documented in the libc reference.

If the above doesn't help, you will have to debug the reason for the
segfaults (there's always a chance that there is a bug in the program that
goes undetected on other platforms, or a bug in `read' or the library
functions it calls.

- Raw text -


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