An alternative would be to iterate through /proc/self/fd with a fallback to this method if we are on a platform without /proc.