Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Navigation Services to get FILE* -- how?

Navigation Services to get FILE* -- how?
Thread Tools
Forum Regular
Join Date: Aug 2001
Location: PA
Status: Offline
Reply With Quote
Jul 18, 2002, 01:27 PM
 
I'd like to use the Apple Carbon Navigation Services in a C program to obtain a regular stdio file pointer (FILE *). This would allow me to keep most of my application platform independent with standard ANSI C code.

I need it to:
1) open an input (preexisting) file with Navigation Services, and to
2) open an output (normally nonexistant but with a check to be sure) file with Navigation Services.

Is there some example code around so I don't have to reinvent the wheel?
     
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Jul 19, 2002, 04:52 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by warnergt:
<strong>I'd like to use the Apple Carbon Navigation Services in a C program to obtain a regular stdio file pointer (FILE *). This would allow me to keep most of my application platform independent with standard ANSI C code.

I need it to:
1) open an input (preexisting) file with Navigation Services, and to
2) open an output (normally nonexistant but with a check to be sure) file with Navigation Services.

Is there some example code around so I don't have to reinvent the wheel?</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Take a look at <a href="http://developer.apple.com/techpubs/macosx/Carbon/Files/NavigationServices/Prog_Navigation_Services/index.html" target="_blank">this link</a> for info on using Nav Services. You can follow their sample code, but you should use FSRef instead of FSSpec in order to support long file names. Anywhere you see FSSpec, replace it with an FSRef, and replace typeFSS with typeFSRef. Then you can use this to translate the FSRef into a path:

FSRef myRef;
UInt8 path[PATH_MAX];
FILE* file;

FSRefMakePath(&myRef, path, PATH_MAX);
file = fopen((char*)path, "r");

To go the other way:

char* myPath;
FSRef resultRef;

FSPathMakeRef(myPath, &resultRef, NULL);
     
Mac Elite
Join Date: Jun 2000
Location: Pasadena
Status: Offline
Reply With Quote
Jul 24, 2002, 05:17 PM
 
been looking for this for like 2 days...just didn't occur to me to look here 'til now thx! made my life much easier! now i can output the path to a text box in my program!
G4/450, T-bird 1.05GHz, iBook 500, iBook 233...4 different machines, 4 different OSes...(9, 2k, X.1, YDL2.2 respectively) PiA to maintain...
     
Mac Elite
Join Date: Jun 2000
Location: Pasadena
Status: Offline
Reply With Quote
Jul 24, 2002, 06:39 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by bewebste:
<strong>Take a look at <a href="http://developer.apple.com/techpubs/macosx/Carbon/Files/NavigationServices/Prog_Navigation_Services/index.html" target="_blank">this link</a> for info on using Nav Services. You can follow their sample code, but you should use FSRef instead of FSSpec in order to support long file names. Anywhere you see FSSpec, replace it with an FSRef, and replace typeFSS with typeFSRef. Then you can use this to translate the FSRef into a path:

FSRef myRef;
UInt8 path[PATH_MAX];
FILE* file;

FSRefMakePath(&myRef, path, PATH_MAX);
file = fopen((char*)path, "r");

To go the other way:

char* myPath;
FSRef resultRef;

FSPathMakeRef(myPath, &resultRef, NULL);</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">I have a few questions regarding that...
first, PATH_MAX is a constant? what should the value be generally speaking...(FSRefMakePath asks for UInt32)
Also, how do i use theString = CFSTR((char*)path)? I get an "illegal function call" error and a "parse error before string constant" (more directly, I'm trying to do SetControlData(stringOutBox, kControlEntireControl, kControlEditTextCFStringTag, sizeof(CFStringRef), &
theString); with no luck...
G4/450, T-bird 1.05GHz, iBook 500, iBook 233...4 different machines, 4 different OSes...(9, 2k, X.1, YDL2.2 respectively) PiA to maintain...
     
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Jul 25, 2002, 08:56 AM
 
PATH_MAX should be declared in syslimits.h, one of the standard C headers. Under OS X, it's defined as 1024 - don't know its value under OS 9. You basically just need a sufficiently large buffer to hold any path that might come up.

The CFSTR() macro only works with string constants, like CFSTR("foo") as opposed to CFSTR(myCString). You can create a CFString from a C string using CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8).
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Jul 25, 2002, 05:41 PM
 
</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">quote:</font><hr /><font size="1" face="Geneva, Verdana, Arial, sans-serif">Originally posted by bewebste:
<strong>PATH_MAX should be declared in syslimits.h, one of the standard C headers. Under OS X, it's defined as 1024 - don't know its value under OS 9. You basically just need a sufficiently large buffer to hold any path that might come up.</strong></font><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Actually, 1024 is a bit small on a modern OS with the possibility of using multi-byte characters in paths. I think Apple should expand it a bit.
     
Bwa
Dedicated MacNNer
Join Date: Oct 2000
Location: Somerville, MA and San Jose, CA
Status: Offline
Reply With Quote
Jul 27, 2002, 11:52 PM
 
Definitinely check out the MoreFilesX sample code at developer.apple.com. It'll take care of a lot of these goodies for you. Very good stuff.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:04 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2