STORKEL@RICE.BITNET (Scott Storkel) (06/08/88)
I just discovered a VERY interesting little fact about using stdio from MPW C. For the last few days, I have been working on writing a Macintosh interface for a program that converts MacWrite files to into Script. This program was originally written to run on Unix machines. No problem, I thought, I'll just write some Mac routines to get the file names, and let the stdio routines built into MPW C do all the work for me. I finally managed to get the Mac stuff working, and the program which runs fine on a Sun, doesn't work on the Mac. The problem was that the output file was truncated. The part of the file that was there was fine, but part of it was missing. After trying all kinds of variations of fflush, fclose, and so on I finally found the problem. I was calling ExitToShell() to quit from the program, and NOT exit(). It seems to me that as long as I have called fclose() to close the file, I should not have to call exit(). However, if I don't call exit() the output file is truncated, and the Finder says that it is locked or in use. It seems that this is a BAD policy. What if the user converts a file, then sits around for a few minutes staring at the wonderful About.. dialog box, and then power goes out? BOOM, his file is trashed. Is there any way around this type of situation? Will changing the way in which the stream is buffered make any difference? Please mail any response directly to me, if possible. Scott Storkel Macintosh Software Development Rice University Houston, Texas
guido@cwi.nl (Guido van Rossum) (06/12/88)
Well, I suppose a call to FlushVol after the fclose would do what you want. --Guido
thomas@uvabick.UUCP (Thomas Fruin) (06/17/88)
> I just discovered a VERY interesting little fact about using stdio > from MPW C. And I just discovered an interesting little fact about using stdio from MPW Pascal ... correct me if I'm wrong: Every file you open, even if you never change the file but only read from it, gets its creator changed by MPW to 'MPS '. Since I'm working on a program that also tests the creator in a standard file filter, this was a problem. I appeared as if gradually files were disappearing, since they didn't show up in standard file anymore after an open... Now I have to make sure to call SetFInfo whenever I'm through with a file :( -- Thomas Fruin fruin@hlerul5.BITNET University of Leiden thomas@uvabick.UUCP University of Amsterdam dibs@well.UUCP hol0066.AppleLink 2:512/115.FidoNet The Netherlands