accessing errno in CFM code of a MACH-O. function call (Apple's sample code "Call Mach-O Framework")

accessing errno in CFM code of a MACH-O. function call (Apple's sample code "Call Mach-O Framework")

Post by michae » Sat, 11 Oct 2003 08:12:50


Hi.

I'm using Apple's sample code "Call Mach-O Framework", to access I/O
Kit function calls (open(), read(), write()). I've been using the
function pointer method. It's been working fine for months, and what
simple error handling I've needed I've been able to handle with the
return values of the function calls.

Now I need to add a more elaborate error handling scheme which
requires that I know the value of errno. To my suprise, errno is
always zero, even after a function call returns an error.

I'm guessing that the real errno is in the Mach-o side of things, and
even though I have a global variable errno, it is not the same as the
one on the Mach-o side.

How can I find the value of errno that corresponds to my failed Mach-o
function call?

Thanks,
Michael
 
 
 

accessing errno in CFM code of a MACH-O. function call (Apple's sample code "Call Mach-O Framework")

Post by Eric Alber » Sat, 11 Oct 2003 13:39:26

In article < XXXX@XXXXX.COM >,



If you look at /usr/include/sys/errno.h, you'll see this:

__BEGIN_DECLS
extern int * __error __P((void));
#define errno (*__error())
__END_DECLS

Try calling __error() and see if that works.

Hope this helps,
Eric

--
Eric Albert XXXX@XXXXX.COM
http://www.yqcomputer.com/ ~ejalbert/

 
 
 

accessing errno in CFM code of a MACH-O. function call (Apple's sample code "Call Mach-O Framework")

Post by michae » Sun, 12 Oct 2003 04:38:46


Hi Eric,

Thanks for your suggestion. Unfortunately, __error is undefined
and fails at link time. Which makes me wonder if there is some library
which would provide this, which I'm missing, which might be the cause
of my problem in the first place.

I'm using CarbonLibStub and MSL_All_Carbon.lib.

Further suggestions welcomed,

Thanks again,
Michael
 
 
 

accessing errno in CFM code of a MACH-O. function call (Apple's sample code "Call Mach-O Framework")

Post by michae » Sun, 12 Oct 2003 06:41:15


Hi Eric,

Thanks for your suggestion. Unfortunately, __error is undefined
and fails at link time. Which makes me wonder if there is some library
which would provide this, which I'm missing, which might be the cause
of my problem in the first place.

I'm using CarbonLibStub and MSL_All_Carbon.lib.

Further suggestions welcomed,

Thanks again,
Michael
 
 
 

accessing errno in CFM code of a MACH-O. function call (Apple's sample code "Call Mach-O Framework")

Post by Miro Juris » Sun, 12 Oct 2003 07:57:11

In article < XXXX@XXXXX.COM >,



You should call __error via the CFM<->Mach-O glue as you are doing with other
functions in System.framework.

hth

meeroh

--
If this message helped you, consider buying an item
from my wish list: < http://www.yqcomputer.com/ ;
 
 
 

accessing errno in CFM code of a MACH-O. function call (Apple's sample code "Call Mach-O Framework")

Post by michae » Thu, 16 Oct 2003 06:47:37

Hi Miro,

Thanks for your suggestion and thanks to Eric for the first part of
this answer.

It works just as you say: I set up the CFM<->Mach-O glue and defined
errno as indicated, and it worked right away.

Thanks again everyone,

Michael