Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uwm.edu!bionet!ames!sgi!shinobu!odin!dinkum!calvin From: calvin@dinkum.wpd.sgi.com (Calvin H. Vu) Newsgroups: comp.sys.sgi Subject: Re: f77 REWIND bug Keywords: fortran Message-ID: <1991Mar23.230647.14882@odin.corp.sgi.com> Date: 23 Mar 91 23:06:47 GMT References: <1991Mar21.193634.13881@ux1.cso.uiuc.edu> Sender: news@odin.corp.sgi.com (Net News) Distribution: comp Organization: Silicon Graphics, Inc. Mountain View, CA Lines: 61 It sounds like a bug. It's surprising nobody has reported it before. The I/O library should truncate the physical file [i.e. not just the internal representation of it inside the library] to the current file pointer position if the first I/O statement after a REWIND/BACKSPACE is a WRITE. It will be fixed in our next release. Meanwhile I can't think of anything better than using your workaround or by calling a wrapper to the C function truncate() to give the file a zero length after the REWIND i.e. something like this would also work: program rewbug c c program that illustrates rewind bug c open (1,file='afile') write (1,*) 'this is the first line of afile ' write (1,*) 'this is the second line of afile' c rewind 1 call trunct('afile') write (1,*) 'this should be the only line now' call flush (1) c c when the pause statement is reached, look at 'afile' from another window, c or press CTRL-Z and look at afile. only after the program continues is c the junk at the end of 'afile' (the second line) cleaned up. c pause close (1) c end and a C routine for a wrapper: void trunct_(filename, len) char *filename; int len; { static char *buf; static int oldlen; if (!buf || oldlen < len) { buf = (char *) malloc(len+1); oldlen = len; } strncpy(buf, filename, len); buf[len] = '\0'; truncate(buf, 0); } Oh well, it's even messier than your workaround only it should be much speedier. Thanks for the consise report and the workaround. - calvin -- ----------------------------------------------------------------------------- Calvin H. Vu | "We are each of us angels with only one Silicon Graphics Computer Systems | wing. And we can only fly embracing calvin@sgi.com (415) 962-3679 | each other."