Oriel — AI & technology worth noticing, every day.

a hacky fucked up way to portably access errno from outside of c

Web page · https://sebsite.pw/w/20260925-errno.html

First seen by Oriel on .

AI summary

The post demonstrates a deliberately hacky way to recover errno values from Hare without a C wrapper by capturing perror output and matching it against strerror messages.

  • It redirects stderr to a temporary file during initialization, calls perror, then reads the captured error string.
  • A startup table stores strerror messages by error number; get_errno() compares perror output against that table to identify the number.
  • The approach avoids strerror_r because glibc exposes a GNU version under strerror_r, while its POSIX version uses the nonportable symbol __xpg_strerror_r.
  • The code also probes lseek whence values from 0 to 2 to find one that seeks to the start, since POSIX does not guarantee SEEK_SET equals 0.
  • The author presents this as a portability experiment for Hare and acknowledges that the technique is intentionally elaborate.

#hare #errno #posix #libc

Generated by gpt-5.6-sol. Check the original for details.

Metric trends

Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained

Points

Score reported by the source.

  • Lobsters: 30, latest observation ; +29 over observed period since

Comments

Comment count reported by the source.

  • Lobsters: 24, latest observation ; +24 over observed period since

Aliases

SourceExternal IDURL
Lobstersjgull9https://sebsite.pw/w/20260925-errno.html Read discussion