# Propagating errno from c extensions

**URL:** <https://rubytalk.org/t/propagating-errno-from-c-extensions/9200>\
**Category:** ruby-talk\
**Created:** [5 December 2003 02:57 UTC](https://rubytalk.org/t/propagating-errno-from-c-extensions/9200 "2003-12-05T02:57:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ara.T.Howard2](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ara.T.Howard2](https://rubytalk.org/u/Ara.T.Howard2)\
**Post date:** [5 December 2003 02:57 UTC](https://rubytalk.org/t/propagating-errno-from-c-extensions/9200/1 "2003-12-05T02:57:05Z")

</div>

rubyists-

any strong opinions on handling errno from c extentions?

personally, it seems that one would want to raise an exception like

Errno::EACCESS

when errno == EACCESS

however i see many cases where functions simply return Qfalse, Qtrue, etc. for  
broad catagories of errno values - leaving the user to guess as to the cause  
of the error (eg. rb\_file\_flock). is there are way of getting at errno that i  
am unaware of? if so perhaps this is o.k…

IMHO a VHLL like ruby should either

a) succeed

b) throw an error

and one should never explcitly need to check error codes.

-a

> **···**
>
> –
> 
> ATTN: please update your address books with address below!
> 
> ===============================================================================
> 
> > EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov  
> > PHONE :: 303.497.6469  
> > ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328  
> > STP :: [Solar-Terrestrial Physics Data | NCEI](http://www.ngdc.noaa.gov/stp/)  
> > NGDC :: [http://www.ngdc.noaa.gov/](http://www.ngdc.noaa.gov/)  
> > NESDIS :: [http://www.nesdis.noaa.gov/](http://www.nesdis.noaa.gov/)  
> > NOAA :: [http://www.noaa.gov/](http://www.noaa.gov/)  
> > US DOC :: [http://www.commerce.gov/](http://www.commerce.gov/)
> > 
> > The difference between art and science is that science is what we  
> > understand well enough to explain to a computer.  
> > Art is everything else.  
> > – Donald Knuth, “Discover”
> > 
> > /bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’  
> > ===============================================================================

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [5 December 2003 03:38 UTC](https://rubytalk.org/t/propagating-errno-from-c-extensions/9200/2 "2003-12-05T03:38:00Z")

</div>

Hi,

> any strong opinions on handling errno from c extentions?

rb\_sys\_fail()

> however i see many cases where functions simply return Qfalse, Qtrue, etc. for  
> broad catagories of errno values - leaving the user to guess as to the cause  
> of the error (eg. rb\_file\_flock). is there are way of getting at errno that i  
> am unaware of? if so perhaps this is o.k…

rb\_file\_flock() raises SystemCallError except for the case it  
would block.

> **···**
>
> At Fri, 5 Dec 2003 11:57:05 +0900, Ara.T.Howard wrote:
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard2](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@Ara.T.Howard2](https://rubytalk.org/u/Ara.T.Howard2)\
**Post date:** [5 December 2003 05:02 UTC](https://rubytalk.org/t/propagating-errno-from-c-extensions/9200/3 "2003-12-05T05:02:05Z")

</div>

> Date: Fri, 5 Dec 2003 12:38:00 +0900  
> From: [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net)  
> Newsgroups: comp.lang.ruby  
> Subject: Re: propagating errno from c extensions
> 
> Hi,
> 
> > any strong opinions on handling errno from c extentions?
> 
> rb\_sys\_fail()

thanks. didn’t realize that’s what that did!

> > however i see many cases where functions simply return Qfalse, Qtrue, etc. for  
> > broad catagories of errno values - leaving the user to guess as to the cause  
> > of the error (eg. rb\_file\_flock). is there are way of getting at errno that i  
> > am unaware of? if so perhaps this is o.k…
> 
> rb\_file\_flock() raises SystemCallError except for the case it  
> would block.

doesn’t this mean that, under certain return values (EACCES), flock would  
simply return false?

file.c

> **···**
>
> On Fri, 5 Dec 2003 [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > At Fri, 5 Dec 2003 11:57:05 +0900, \> Ara.T.Howard wrote:  
> > ================  
> > …  
> > 2092 retry:  
> > 2093 TRAP\_BEG;  
> > 2094 ret = flock(fileno(fptr-\>f), NUM2INT(operation));  
> > 2095 TRAP\_END;  
> > 2096 if (ret \< 0) {  
> > 2097 switch (errno) {  
> > 2098 case EAGAIN:  
> > 2099 case EACCES:  
> > 2100 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN  
> > 2101 case EWOULDBLOCK:  
> > 2102 #endif  
> > 2103 return Qfalse;  
> > 2104 case EINTR:  
> > 2105 #if defined(ERESTART)  
> > 2106 case ERESTART:  
> > 2107 #endif  
> > 2108 goto retry;  
> > 2109 }  
> > 2110 rb\_sys\_fail(fptr-\>path);  
> > 2111 }  
> > 2112 #endif  
> > 2113 return INT2FIX(0);  
> > 2114 }
> 
> ## -a
> 
> ATTN: please update your address books with address below!
> 
> ===============================================================================
> 
> > EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov  
> > PHONE :: 303.497.6469  
> > ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328  
> > STP :: [Solar-Terrestrial Physics Data | NCEI](http://www.ngdc.noaa.gov/stp/)  
> > NGDC :: [http://www.ngdc.noaa.gov/](http://www.ngdc.noaa.gov/)  
> > NESDIS :: [http://www.nesdis.noaa.gov/](http://www.nesdis.noaa.gov/)  
> > NOAA :: [http://www.noaa.gov/](http://www.noaa.gov/)  
> > US DOC :: [http://www.commerce.gov/](http://www.commerce.gov/)
> > 
> > The difference between art and science is that science is what we  
> > understand well enough to explain to a computer.  
> > Art is everything else.  
> > – Donald Knuth, “Discover”
> > 
> > /bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’  
> > ===============================================================================

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [5 December 2003 08:47 UTC](https://rubytalk.org/t/propagating-errno-from-c-extensions/9200/4 "2003-12-05T08:47:16Z")

</div>

Hi,

> **···**
>
> At Fri, 5 Dec 2003 14:02:05 +0900, Ara.T.Howard wrote:
> 
> > > > however i see many cases where functions simply return Qfalse, Qtrue, etc. for  
> > > > broad catagories of errno values - leaving the user to guess as to the cause  
> > > > of the error (eg. rb\_file\_flock). is there are way of getting at errno that i  
> > > > am unaware of? if so perhaps this is o.k…
> > > 
> > > rb\_file\_flock() raises SystemCallError except for the case it  
> > > would block.
> > 
> > doesn’t this mean that, under certain return values (EACCES), flock would  
> > simply return false?
> 
> On some systems, fcntl() fails with not EAGAIN but EACCES when the  
> file is locked already.
> 
> –  
> Nobu Nakada
