Files & fopen()

astham ogetti

Registered
Hi all.

I'm trying to port an application to MacOS and need some help with converting the output from NavGetDialogReply to a pathname (would rather not re-write 12,000 lines of ANSI C). There seems to be a zillion ways to do this, but I can't find any in the examples. Seems like a classic problem, so it must have been solved in an elegant way somewhere.

Thanks.
 
Well, it is a FSRef or a FSSpec. Inside a AEDescList. (I guess what I'm trying to say is that I'm totally confused.) I just want to get a path name out of a file selection dialog box. It works if a try to get a FSRef from the descriptor list, converting that FSRef to a Unicode string, and then converting that Unicode string to a char string (something that POSIX fopen can read). But the Unicode string won't cover for files on network shares (or would it?), and if the user is trying to open a file with a name in Russian the last conversion fails. I would be more comfortable by opening a file with the FSRef and then in some magical way getting a FILE* out of that operation.

There must be some smarter way to do this. That's all.
 
Hmm, network shares should work, as long as the path is valid. Are you using Cocoa at all? Or just straight C/Carbon calls?

If you're using Cocoa, you can use FSRefMakePath(), then copy the returned char string to an NSString, and use [string fileSystemRepresentation] - that'll correctly convert any non-ASCII characters in the string where fopen() can use the path.

You can do the same with CoreFoundation, using CFStrings (though the functions are different).

I don't think there's any way to do this in C or Carbon, though. But I could be wrong about that.

Let me know what you're using, then I can possibly give an example.
 
Back
Top