# Ruby/DL and errno

**URL:** <https://www.ruby-forum.com/t/ruby-dl-and-errno/133885>\
**Category:** Ruby\
**Created:** [April 4, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/ruby-dl-and-errno/133885 "2008-04-04T16:58:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbochan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/96bed5/32.png) [@tbochan](https://www.ruby-forum.com/u/tbochan)\
**Post date:** [April 4, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/ruby-dl-and-errno/133885/1 "2008-04-04T16:58:08Z")

</div>

Hi,  
I’m using Ruby 1.8.6 on HPUX.  
When I call a unix library routine via Ruby syscall, any unix exception  
correctly gets trapped.

However, when I call the same routine via Ruby/DL, the unix error  
does not get trapped, and what is more, I don’t know how to retrieve  
the value of unix ‘errno’.

Can anyone suggest a way around this , please ?

The demo code illustrates :

require “dl”  
LIBRT=DL.dlopen("/usr/lib/librt.sl")  
pmqopen=LIBRT[“mq\_open”,“ISIIS”]  
SYS\_mq\_open = 439  
qname="/notHere" # non-existent queue !!  
mqattr=[0,2048, 512,0].pack(“LLLL”)

puts “Using Ruby/DL :”  
p pmqopen[qname, File::RDWR, 0660, mqattr]

puts “Using syscall :”  
p syscall(SYS\_mq\_open, qname, File::RDWR, 0660, mqattr)

… produces …\>\>

> ruby prob1demo  
> Using Ruby/DL :  
> [-1, ["/notHere", 2, 432,  
> “\000\000\000\000\000\000\b\000\000\000\002\000\000\000\000\000”]]  
> Using syscall :  
> prob1demo:11:in `syscall’: No such file or directory (Errno::ENOENT)  
> from prob1demo:11
