Boost logo

Boost :

From: Oliver.Kowalke_at_[hidden]
Date: 2006-10-12 07:40:35


Hi,
LINUX and HP/UX have different strerror_r functions. At least for me the
moduification works.

regards,
Oliver

std::string errno_md( const error_code & ec )
  {
# if !defined(BOOST_WINDOWS_API) // does not have strerror_t
#if defined(__linux)
    char buf[64];
    char * bp = buf;
    std::size_t sz = sizeof(buf);
    return strerror_r( ec.value(), bp, sz);
#elif defined(__hpux)
    return strerror( ec.value() );
#else
    char buf[64];
    char * bp = buf;
    std::size_t sz = sizeof(buf);
    int result;
    while ( (result = strerror_r( ec.value(), bp, sz )) == ERANGE )
    {
      if ( sz > sizeof(buf) ) std::free( bp );
      sz *= 2;
      if ( (bp = static_cast<char*>(std::malloc( sz ))) == 0 )
        return std::string( "ENOMEM" );
    }
    std::string msg( ( result == EINVAL ) ? "EINVAL" : bp );
    if ( sz > sizeof(buf) ) std::free( bp );
    return msg;
# endif
# else
    const char * c_str = std::strerror( ec.value() );
    return std::string( c_str ? c_str : "EINVAL" );
# endif
  }


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk