Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!sco!chapman From: chapman@sco.COM (Brian Chapman) Newsgroups: comp.unix.xenix Subject: Re: NEED HELP: fread, fwrite, fseek, ftell Keywords: AAAAAAAAARRRRRGGGHHH Message-ID: <692@sysco> Date: 3 May 89 20:03:25 GMT References: <7327@mrspoc.UUCP> Reply-To: chapman@sco.COM (Brian Chapman) Organization: The Santa Cruz Operation, Inc. Lines: 25 In article <7327@mrspoc.UUCP> itkin@mrspoc.UUCP (Steven List) writes: >I am trying to write a simple little program to swap bytes and/or words >in a file. The program works great except for one little problem. When >I try to do it in place, the file just keeps growing and growing and... I think I can guess your problem. [ Although your code fragment was not sufficent to be sure ]. The old V7 and or BSD trick of opening a file for appending (eg. fopen(....."a");) and then rewinding it; doesn't work on System V compatibile systems. Open for appending inforces an implied seek() to EOF on writes. So you read from the front of the file and your writes get added to the end, to be read again and added as yet more data at the end of file to be read again.... Try just opening the file read|write. (fopen(....."r+");) [ I once chased this "feature" all the way to the exact line in ] [ in the kernel, and was about to report it as a bug. Until a ] [ co-worked pointed it out in the SVID. :-) ] -- Pay no attention to the man behind the curtain. Brian Chapman uunet!sco!chapman SCO UNIX 3.2 Development