2 * Copyright 2005-2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
14 static map
<int, int> sToHaikuErrorMap
;
15 static map
<int, int> sToHostErrorMap
;
16 static bool sErrorMapsInitialized
= false;
22 if (sErrorMapsInitialized
)
25 #define ADD_ERROR(error) \
26 sToHaikuErrorMap[error] = HAIKU_##error; \
27 sToHostErrorMap[HAIKU_##error] = error;
50 ADD_ERROR(EPROTOTYPE
);
51 ADD_ERROR(EPROTONOSUPPORT
);
52 ADD_ERROR(EPFNOSUPPORT
);
53 ADD_ERROR(EAFNOSUPPORT
);
54 ADD_ERROR(EADDRINUSE
);
55 ADD_ERROR(EADDRNOTAVAIL
);
57 ADD_ERROR(ENETUNREACH
);
59 ADD_ERROR(ECONNABORTED
);
60 ADD_ERROR(ECONNRESET
);
64 ADD_ERROR(ECONNREFUSED
);
65 ADD_ERROR(EHOSTUNREACH
);
66 ADD_ERROR(ENOPROTOOPT
);
68 ADD_ERROR(EINPROGRESS
);
75 ADD_ERROR(EOPNOTSUPP
);
82 ADD_ERROR(EDESTADDRREQ
);
108 ADD_ERROR(ETIMEDOUT
);
110 ADD_ERROR(EWOULDBLOCK
);
114 ADD_ERROR(ENAMETOOLONG
);
119 ADD_ERROR(ENOTEMPTY
);
131 sErrorMapsInitialized
= true;
136 to_host_error(int error
)
140 map
<int, int>::iterator it
= sToHostErrorMap
.find(error
);
141 return (it
!= sToHostErrorMap
.end() ? it
->second
: error
);
146 to_haiku_error(int error
)
150 map
<int, int>::iterator it
= sToHaikuErrorMap
.find(error
);
151 if (it
!= sToHaikuErrorMap
.end())
154 return (error
> 0 ? -error
: error
);
157 // _haiku_build_strerror
159 _haiku_build_strerror(int errnum
)
161 return strerror(to_host_error(errnum
));
164 // _haiku_build_errno
168 static int previousErrno
= 0;
169 static int localErrno
= 0;
170 static int previousLocalErrno
= 0;
172 // If the localErrno has been changed and the real errno has not changed
173 // in the meantime, we update errno itself, so that the local update will
174 // be reflected. If errno has changed we always update localErrno.
175 int currentErrno
= errno
;
176 if (currentErrno
== previousErrno
) {
177 if (localErrno
!= previousLocalErrno
) {
178 errno
= previousErrno
= to_host_error(localErrno
);
179 previousLocalErrno
= localErrno
;
182 previousErrno
= currentErrno
;
183 previousLocalErrno
= localErrno
= to_haiku_error(errno
);
189 // _haiku_to_host_error
191 _haiku_to_host_error(int error
)
193 return to_host_error(error
);