Mail Archives: djgpp/1996/08/08/02:51:41
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 -