delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1992/09/25/14:47:17

Date: Fri, 25 Sep 92 20:38:04 GMT
From: kuku AT acds DOT physik DOT rwth-aachen DOT de (Christoph Kukulies)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: still binary files

Yeah, I found the problem with binary files and f2c. In the course of 
opening a file which is a long story you can see from the following example
an open is made by the libf2c runtime routines. This open does not take into
account that also a O_BINARY is possible (which is peculiar to DJGPP, i believe)
Normally a file is a file is a file, insn't it (under unix :-).
Example:
/* I have boiled the problem down to what actually happens
   when a file is opened in libf2c.a for writing.
   I.e. a fortran open(unit,file='test.dat',status='new',form='unformatted',
                       access='direct')
 
 */
#include <stdio.h>
#include <fcntl.h>
short int kpx[]={ 10,12,0,0};
FILE *op;
main()
{
    int fd;
    close(creat("test.dat",0666));
    op=fopen("test.dat","rb");     
    fd=open("test.dat",O_WRONLY); /* the open is in err.c in function
                                     nowwriting() 
                                     at this point it is not taken into
                                     account that a binary file was required */
    write(fd,kpx,sizeof(kpx));
}
Excuse the missing error checks. If I add O_WRONLY|O_BINARY everything works.
The change is deep down in module err.c around line 248. If anyone is using
f2c and needs the fix, mail me. I'll post this also to the maintainers of f2c
but they say they are fed up with adding another #ifdef into their code :)
BTW, they never heard of djgpp. I pointed them to djgpp then.

--Chris

- Raw text -


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