The setlocale
C/C++ function writes the global variable errno
to 0
. In Linux it doesn't have this behavior and the documentation doesn't says anything about setting errno
(as I understand, no function should set errno
to 0
The following code allows to reproduce it
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream myStream;
myStream.open("NONEXISTENT.txt", ios::in);
cout << errno << endl;
setlocale(LC_ALL, "en_US.UTF-8");
cout << errno << endl;
}
// Output:
// 2
// 0
I don't think is a compiler issue as the error also happens with gcc
but rather a libc
issue.