Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!ucbvax!ucdavis!arons From: arons@sesame.ucdavis.edu (Tom &) Newsgroups: comp.sys.hp Subject: fopen/fseek interaction Message-ID: Date: 20 Dec 89 17:48:55 GMT Sender: uucp@ucdavis.ucdavis.edu Organization: University of California at Davis Lines: 30 In porting a program from a BSD system to hp-ux version 3.10 on a 9k/800 I discovered a difference in stdio behavior. fd = fopen(path, "a") is used on the BSD system to open, creating if necessary a file. One, and only one, number is kept in the file by using: fseek(fd, 0L, 0); fprintf(fd, "%d\n", n); to update the file. On the hp-ux system the fseek's are effectively no-ops, that is the file consists of as many numbers as there are writes. Changing the "a" to a "r+" in the fopen works fine if the file exists, but won't create a new file. "a+" seems to behave the same as "a". In all cases the fseek returns a 0, indicating success. A workaround is easy enough to implement, but it is annoying to have to #ifdef the code. I am not sure whether the difference is a bug in either the BSD or hp-ux system, or some BSD/System V semantic difference. Does anyone know? The man page explanations for fopen on both systems are virtually identical. Tom Arons Internet: arons@iris.ucdavis.edu EE/CS Department Bitnet: arons@ucdavis University of California UUCP: {lll-crg, ucbvax}!ucdavis!iris!arons Davis, CA 95616 Phone: (916) 752-1750