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 / Mac Programming / June 2006



Tip: Looking for answers? Try searching our database.

file descriptor and file reference number mapping

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
piyuesh@gmail.com - 28 Jun 2006 08:01 GMT
There are times when you want to use low level unix system calls in
your carbon application. It's trivial but some syscalls needs file
descriptor
and you only have file reference number (got from HOpenDF, FSpOpenDF
etc..)
at hand. There is no official way to map this filerefnum to file
descriptor.
There is a hack available to do the mapping between these 2 numbers.
{
    int fd = open(filename, flags);
    close(fd);
    short int fileRef= HOpenDF()/FSOpenFork()/FSpOpenDF;
    // now fd corresponds to fileRef.
    fstat(fd); // It will work.
}
The reason for this behavior is open() syscall always utilizes
lowest file descriptor available in the process's file descriptor table.
Ben Artin - 29 Jun 2006 05:56 GMT
> There are times when you want to use low level unix system calls in
> your carbon application. It's trivial but some syscalls needs file
[quoted text clipped - 3 lines]
> at hand. There is no official way to map this filerefnum to file
> descriptor.

Can you give us some example when your code (which relies on undocumented
behavior that might change in a new OS release) is better than simply getting
the path from the Carbon file ref and using that path with POSIX calls?

Ben

Signature

If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>

I changed my name: <http://periodic-kingdom.org/People/NameChange.php>

--
Posted via a free Usenet account from http://www.teranews.com

piyuesh@gmail.com - 30 Jun 2006 10:22 GMT
> > There are times when you want to use low level unix system calls in
> > your carbon application. It's trivial but some syscalls needs file
[quoted text clipped - 11 lines]
>
> --
for example fcntl, flock etc..works on file descriptor not on
pathnames, also there may be some other usage for this method. I'm not
able to think every possible scenario right now.

Piyuesh
Ben Artin - 30 Jun 2006 17:16 GMT
> > > There are times when you want to use low level unix system calls in your
> > > carbon application. It's trivial but some syscalls needs file descriptor
[quoted text clipped - 13 lines]
> there may be some other usage for this method. I'm not able to think every
> possible scenario right now.

OK, so once you have the path, call fopen() yourself. That's a much better
idea than relying on the undocumented implementation details of Apple APIs.

Ben

Signature

If this message helped you, consider buying an item
from my wish list: <http://artins.org/ben/wishlist>

I changed my name: <http://periodic-kingdom.org/People/NameChange.php>

--
Posted via a free Usenet account from http://www.teranews.com

 
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.