====== errno ======
Bei **errno** gibt es keinen einheitlichen Standard. In einigen Implementierungen ist es eine **int**-Variable, in den anderen ist es ein Makro.
Folgendes konnte ich beim Debuggen von Programmen feststellen:
Unter Sun Solaris hatte ich mit der Variable int errno;
zu tun. Die Funktionen, wie z.B. **atoi()**, legen dort den ErrorCode ab oder 0 bei Erfolg. D.h., durch die Auswertung der Variable %%errno%% kann man feststellen, ob die zuletzt aufgerufene %%atoi()%% (oder andere Funktion, die %%errno%% nutzt) erfolgreich war.
#include
int main()
{
char szEineZahlAlsString[] = "12345";
int iEineZahlAlsInteger = 0;
iEineZahlAlsInteger = atoi(szEineZahlAlsString);
if (errno == EINVAL || errno == ERANGE) printf("Fehler beim atoi(), errno = [%d]\n", errno);
printf("szEineZahlAlsString = [%s], iEineZahlAlsInteger = [%d]\n", szEineZahlAlsString, iEineZahlAlsInteger);
return 0;
} // main()
Unter MS VisualStudio 2010 hatte ich mit dem Makro #define errno (*_errno())
zu tun. Falls eine "fehlgeschlagene" Funktion dort einen Fehlerwert abspeichert, setzt die nächste "erfolgreiche" Funktion diesen Fehlerwert u.U. nicht zurück! Als work around funktioniert, wann man vor den Funktionen wie %%atoi()%% manuell %%errno%% auf 0 zurücksetzt.
Auszug aus dem Kapitel **ERRNO(3)** (Linux Programmer's Manual): [[http://man7.org/linux/man-pages/man3/errno.3.html]]
* //**errno** is defined by the ISO C standard to be a modifiable lvalue of type int, and must not be explicitly declared; errno may be a macro. errno is **thread-local**; setting it in one thread does not affect its value in any other thread.//
* //It was common in traditional C to declare errno manually (i.e., extern int errno) instead of including . **Do not do this.** It will not work with modern versions of the C library. However, on (very) old UNIX systems, there may be no and the declaration is needed.//
__Weitere Infos:__\\
IBM: [[http://www.ibm.com/developerworks/aix/library/au-errnovariable/|Errors: errno in UNIX programs]]\\
MS: [[http://msdn.microsoft.com/de-de/library/t3ayayh1%28v=vs.100%29.aspx|errno, _doserrno, _sys_errlist, and _sys_nerr]] (MSDN, Visual Studio 2010)\\
----
Stand: 07.06.2016\\
--- //[[feedback.jk-wiki@kreick.de|: Jürgen Kreick]]//
EOF