ADC Home > Reference Library > Technical Notes > Legacy Documents > Tools >

Legacy Documentclose button

Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.

Current information on this Reference Library topic can be found here:

MPW Library Q&As

CONTENTS

This Technical Note contains a collection of archived Q&As relating to a specific topic - questions sent the Developer Support Center (DSC) along with answers from the DSC engineers. Current Q&A's can be found on the Macintosh Technical Q&A's web site.

[Oct 01 1990]






Getting MPW to recognize a file created using "open"

Date Written: 5/3/89

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"

SIOW libraries run in 32-bit mode

Date Written: 7/30/91

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.

MPW glue for trackbox & other lowercase toolbox calls is broken

Date Written: 7/9/91

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.


Back to top

Downloadables

Acrobat gif

Acrobat version of this Note (34K).

Download



Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.