Unfortunately, not programmatically.
Just a thought: if this is a debugging problem, perhaps you can set a memory breakpoint at the address where errno is stored and cause it to break when it is written to memory. Then the call stack will tell you who did it.
source share