Date: Thu, 8 Aug 1996 09:46:56 +0200 (IST) From: Eli Zaretskii To: Allen Pouratian Cc: djgpp AT delorie DOT com Subject: Re: file "read" DOS vs. UNIX In-Reply-To: <4tveqm$agf@agate.berkeley.edu> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 . . . _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 . . 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.