Technote PT 560 | October 1990 |
Last reviewed: 6/14/93
I'm using the C standard library routines to read and write text files. But when I create a file using open(), MPW doesn't recognize it as a TEXT file. What's going on?
___
When open() creates a file, it leaves the fdType and fdCreator blank, since it doesn't know the format of the file you are going to write (it's possible to write binary data using the standard C library).
To change the file type and creator of a file created by open(), use SetFInfo, as shown in the example below:
#include <stdio.h> #include <fcntl.h> #include <Files.h> int main(void) { int fd; short vol, err; FInfo fInfo; fd = open("junk.out",O_CREAT | O_RDWR | O_TRUNC); if (fd < 0) { printf("Error creating file\n"); return(1); } (void) close(fd); err = GetVol((StringPtr) NULL,&vol); if (err != 0) { printf("Error %d getting current volume\n",err); return(1); } err = GetFInfo((StringPtr) "\pjunk.out", vol, &fInfo); if (err != 0) { printf("Error %d getting file info\n",err); return(1); } fInfo.fdType = 'TEXT'; fInfo.fdCreator = 'MPS '; err = SetFInfo((StringPtr) "\pjunk.out", vol, &fInfo); if (err != 0) { printf("Error %d setting file info\n",err); return(1); } return(0); }
By the way, you are generally much better off if you use the File Manager's routines to manipulate your files. The performance will be much better.
X-Refs:
File Manager
Macintosh Technical Note "Mixing HFS and C File I/O"
Last reviewed: 6/14/93
Comments in the SIOW.r file indicate that the Standard I/O Window (SIOW) software is not 32-bit clean. Are there any known bugs that crop up if the current software is run in 32-bit mode anyway?
___
The "not32BitCompatible" setting in the SIZE resource is ignored, more or less. Originally, it was going to trigger an alert like "Be careful - this application may crash!" if the system was running in 32-bit mode; thankfully, this alert was removed before System 7.0 was shipped (though A/UX still has it).
As far as the SIOW libraries are concerned, there isn't anything about them that restricts their use to 24-bit environments. Other than the problems discussed in the release notes that come with MPW 3.2 (which includes SIOW), Apple doesn't know of any bugs with SIOW.
Last reviewed: 6/14/93
Is trackbox in the MPW C library broken? It always returns 0 (false).
___
Yes, the glue for the MPW C library trackbox is broken. In fact, the glue for many of the lowercase Toolbox calls is broken. Fixing lowercase glue routines is a never-ending challenge. This probably won't be fixed; instead, expect to see all lowercase glue routines removed from future versions of MPW. What does this mean to you? Use only the proper mixed-case interfaces (the ones spelled just like in Inside Macintosh) at all times. This also will serve to make your code smaller and faster, since the mixed-case interfaces make direct Toolbox calls instead of calls to glue routines in many cases.
Incidentally, in case you're wondering, the C library trackbox doesn't work because the glue clears a long for the result instead of a word and pulls a long off the stack, so the result is in the wrong byte of the register on return.