Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / CodeWarrior / January 2006



Tip: Looking for answers? Try searching our database.

fopen() to open a HFS path

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
djg@tramontana.co.hu - 02 Jan 2006 17:31 GMT
Hello,

I'm working with CodeWarrior 10. When I try to fopen() a file for
reading, supplying it a HFS-style path, it returns with "File cannot be
found". The file is there, available, not even read-only, the path is
correct, I checked it several times.

Is fopen() supposed to work with HFS paths as well, or only POSIX? If
the second, what standard function could I use to convert my HFS path
into a POSIX one? I mean something that reconstructs the actual path,
not a simple string manipulation of replacing slashes with colons
because the file is located somewhere in an application's subdirectory,
so the actual POSIX-style equivalent path would be different to the
path elements of the HFS path (MacOS/Contents etc).

Thanks,
 Gábor
hp - 02 Jan 2006 18:50 GMT
fopen() *must* have a POSIX path...

Do NOT substitute colons to slashes; it will only get you into
trouble...

To get the full path, follow these steps:
1) create an FSSpec from the HFS path using FSMakeFSSpec()
2) convert the FSSpec to an FSRef using FSMakeFSRef()
3) create a POSIX path via FSRefMakePath()

BTW, get a copy of MoreFilesX from Apple; there are many useful file
utils
contained therein.

Hope this helps...

-harry
djg@tramontana.co.hu - 02 Jan 2006 19:15 GMT
Harry,

> Do NOT substitute colons to slashes; it will only get you into
> trouble...

In this actual case, as I checked the actual paths, this replacement
would be enough but I sure don't want to follow that way, it's bound to
cause problems later.

> To get the full path, follow these steps:
> 1) create an FSSpec from the HFS path using FSMakeFSSpec()
> 2) convert the FSSpec to an FSRef using FSMakeFSRef()
> 3) create a POSIX path via FSRefMakePath()

I'll try it, thanks.

Bye,
 Gábor
djg@tramontana.co.hu - 02 Jan 2006 19:24 GMT
Now that I check it, any reason why I can't directly use FSMakePath?
>From the documentation I found on the web, this seems to include all
the necessary steps to go from HFS to POSIX in one step.

Bye,
 Gábor
hp - 02 Jan 2006 19:32 GMT
FSMakePath() is contained in MoreFilesX.c and indeed does the job in
one step (it calls FSMakeFSRef() and FSRefMakePath()) ... see "(Third
Party Support)" under Metrowerks MacOS Support.

-harry
djg@tramontana.co.hu - 04 Jan 2006 19:29 GMT
Harry,

I finally solved this and I have an even more serious problem now. It
seems that fopen() and the related stuff underwent quite significant
changes. After having opened the file successfully, I have a very
simple

fread (Table, sizeof (ENTRY) MAXENTRIES, f)

where ENTRY is a simple struct of eight bytes and ENTRY Table
[MAXENTRIES]. The table is statically allocated, it is there. And when
I execute this line, the program crashes. Very strange. And it worked
on Mac OS X, although with an older version of CW.

Bye,
 Gábor
hp - 05 Jan 2006 18:41 GMT
I would be willing to bet that you have a link order problem; you are
either creating the stream via MSL fopen(), and using BSD fread() [or
vice versa]. This is a MachO project, right?

Your system project access paths should define

  /usr/include (non-recursive)
 /usr/lib         (non-recursive)

BEFORE
 (Compiler)MSL
 (Compiler)MacOS X Support

You will find many references in this news group talking about the
system path order

Good luck...

-h
DEÁK JAHN, Gábor - 08 Jan 2006 14:42 GMT
Harry,

> FSMakePath() is contained in MoreFilesX.c and indeed does the job
> in one step (it calls FSMakeFSRef() and FSRefMakePath()) ... see
> "(Third Party Support)" under Metrowerks MacOS Support.

Silly me, I didn't realize a copy was there under CW, I tried to use one downloaded from the web. Anyway, as I already mentioned in another thread (just that I used Google Groups to access the newsgroup instead of doing it directly and some posts take days to finally appear there, making the whole impossible to follow), after some experiments with moving the relevant parts of MoreFilesX into my own code, I finally settled on CFURL instead. This also made it easy to avoid the problems of Pascal versus C strings and finally gave me the HFS-to-POSIX path conversion function I was looking for. So, all seems to be nice and functioning now. Thanks for all of your help.

Bye,
 Gábor
larry@skytag.com - 08 Jan 2006 20:31 GMT
FWIW, the CFURL approach works even when the object referenced by the
path doesn't exist. The other approach does not because FSRefs can't be
used to refer to something that doesn't exist.

Larry
Sean McBride - 06 Jan 2006 01:12 GMT
> Is fopen() supposed to work with HFS paths as well, or only POSIX? If

It depends which fopen() you're using.  Apple's takes posix paths, and
IIRC the MSL one takes either HFS or POSIX paths depending how you've
set it up.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.