Here's my interim solution:
package HErrno; # tlhackque - roughly based on a scheme by Perlbotics # in http://www.perlmonks.org/index.pl?node_id=773351 # # use HErrno.pm; # # print $herrno{$?} # String from h_errno # print $herrno{NETDB_SUCCESS} # String from name or value # use HErrno.pm qw( :NAMES ); # Constant (subroutines) for all name +s # use HErrno.pm qw ( HOST_NOT_FOUND ); # Constant for one name # # my h_errno = $? # if( h_errno == HOST_NOT_FOUND ) ... # our (@EXPORT, @EXPORT_OK,%EXPORT_TAGS,@ISA,%herrno,$VERSION); use Exporter (); use strict; $VERSION = "0.01_00"; $VERSION = eval $VERSION; @ISA = qw(Exporter); @EXPORT = qw(%herrno); BEGIN { %herrno = ( # Symbols to obtain => error string to return. NETDB_INTERNAL => "See errno.", NETDB_SUCCESS => "No problem.", HOST_NOT_FOUND => "Authoritative Answer Host not found.", TRY_AGAIN => "Non-Authoritative Host not found, or SER +VERFAIL.", NO_RECOVERY => "Non recoverable errors, FORMERR, REFUSED +, NOTIMP.", NO_DATA => "Valid name, no data record of requested +type.", NO_ADDRESS => "No address, look for MX record.", ); @EXPORT_OK = ( qw(NO_ADDRESS) ); %EXPORT_TAGS = ( NAMES => [qw(NO_ADDRESS)] ); # Get symbol values from netdb.h. This isn't robust... open my $errdb, '<', '/usr/include/netdb.h' or die; while (my $line = <$errdb>) { if (my ($symbol, $val) = $line =~ /^\s*\#\s*define\s+([^_]\w+)\s+( +-?\d+)/) { next unless exists $herrno{$symbol}; # skip irrelevant symbols die "FATAL: $symbol = $val - conflicts with $herrno{$val}\n" if exists $herrno{$val}; # Map numeric codes to text strings $herrno{$val} = $herrno{$symbol}; # Provide a symbolic value { no strict 'refs' ; *{$symbol} = sub () { $val; }; } # Export the symbol & add to the NAMES tag push @EXPORT_OK, $symbol; push @{$EXPORT_TAGS{NAMES}}, $symbol; } } # NO_ADDRESS is an alias for NO_DATA sub NO_ADDRESS() { NO_DATA() }; close $errdb or die; } 1; __END__

This communication may not represent my employer's views, if any, on the matters discussed.


In reply to Re: h_errno constants? by tlhackque
in thread h_errno constants? by tlhackque

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.