f77 REWIND bug

Calvin H. Vu calvin at dinkum.wpd.sgi.com
Sun Mar 24 09:06:47 AEST 1991


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 at sgi.com   (415) 962-3679	   | each other."



More information about the Comp.sys.sgi mailing list