34c06fc3921a212b540020993a82a0a683cae479
[oftp] / libs / watt32 / sys / werrno.h
1 /*!\file sys/werrno.h
2  *
3  * sys_errlist[] and errno's for compilers with limited errnos.
4  * For WIN32, we do NOT use the <winsock.h> WSAE* codes.
5  *
6  * G. Vanem <giva@bgnett.no> 1998 - 2004
7  */
8
9 #ifndef __SYS_WERRNO_H
10 #define __SYS_WERRNO_H
11
12 /* When doing "gcc -MM" with gcc 3.0 we must include <sys/version.h>
13  * (via stdio.h) in order for __DJGPP__ to be defined
14  */
15 #include <stdio.h>
16 #include <errno.h>
17
18 #ifndef __SYS_W32API_H
19 #include <sys/w32api.h>
20 #endif
21
22 /* Hack: fix for compiling with djgpp 2.04, but
23  *       ./util/dj_err.exe was compiled with 2.03
24  */
25 #if defined(MIXING_DJGPP_203_AND_204)
26 #undef ELOOP
27 #endif
28
29 #if defined(__MINGW32__)
30   #include <sys/mingw32.err>
31
32 #elif defined(__HIGHC__)
33   #undef EDEADLK
34   #undef EDEADLOCK
35   #include <sys/highc.err>
36
37 #elif defined(__BORLANDC__)
38   #ifdef __FLAT__
39   #undef ENAMETOOLONG  /* bcc32 4.0 */
40   #endif
41   #ifdef _WIN32
42   #undef ENOTEMPTY
43   #endif
44   #include <sys/borlandc.err>
45
46 #elif defined(__TURBOC__)
47   #include <sys/turboc.err>
48
49 #elif defined(__WATCOMC__)
50   #include <sys/watcom.err>
51
52 #elif defined(__DJGPP__)
53   #include <sys/djgpp.err>
54
55 #elif defined(__DMC__)                        /* Digital Mars Compiler */
56   #include <sys/digmars.err>
57
58 #elif defined(_MSC_VER) && (_MSC_VER <= 800)  /* MSC 8.0 or older */
59   #include <sys/quickc.err>
60
61 #elif defined(_MSC_VER) && (_MSC_VER > 800)   /* Visual C on Windows */
62   #undef EDEADLOCK
63   #include <sys/visualc.err>
64
65 #elif defined(__CCDL__)                       /* LadSoft's cc386.exe */
66   #include <sys/ladsoft.err>
67
68 #elif defined(__LCC__)
69   #include <sys/lcc.err>
70
71 #elif defined(__POCC__)
72   #include <sys/pellesc.err>
73
74 #else
75   #error Unknown target in <sys/werrno.h>.
76 #endif
77
78 /*
79  * Ugly hack ahead. Someone tell me a better way, but
80  * errno and friends are macros on Windows. Redefine them
81  * to point to our variables.
82  *
83  * On Windows, the usual 'errno' is a macro "(*_errno)()" that
84  * is problematic to use as a lvalue.
85  * On other platforms we modify the global 'errno' variable directly.
86  * (see SOCK_ERRNO() in misc.h). So no need to redefine it in any way.
87  */
88
89 W32_DATA int   _w32_errno;
90 W32_DATA int   _w32_sys_nerr;
91 W32_DATA char *_w32_sys_errlist[];
92
93 #if 0
94   #undef  sys_nerr
95   #define sys_nerr      _w32_sys_nerr
96
97   #undef  _sys_nerr
98   #define _sys_nerr     _w32_sys_nerr
99
100   #undef  __sys_nerr
101   #define __sys_nerr    _w32_sys_nerr
102
103   #undef  sys_errlist
104   #define sys_errlist   _w32_sys_errlist
105
106   #undef  _sys_errlist
107   #define _sys_errlist  _w32_sys_errlist
108
109   #undef  __sys_errlist
110   #define __sys_errlist _w32_sys_errlist
111 #endif
112
113 /*
114  * Incase you have trouble with duplicate defined symbols,
115  * make sure the "*_s()" versions are referenced before normal
116  * perror() and strerror() in your C-library.
117  */
118 W32_FUNC void  perror_s   (const char *str);
119 W32_FUNC char *strerror_s (int errnum);
120
121 #if defined(__cplusplus)  /* Damn C++ */
122   #include <stdlib.h>
123   #include <string.h>
124
125 #elif !defined(_MSC_VER) && !defined(WIN32)
126   #if !defined(_INC_STDLIB) && !defined(_STDLIB_H_) && !defined(_STDIO_H)
127   W32_FUNC void perror (const char *str);
128   #endif
129
130   #if !defined(_INC_STRING) && !defined(_STRING_H) && !defined(_STRING_H_)
131   W32_FUNC char *strerror (int errnum);
132   #endif
133 #endif
134
135 #if defined(WIN32) || defined(_WIN32)
136   W32_FUNC int  __stdcall WSAGetLastError (void);
137   W32_FUNC void __stdcall WSASetLastError (int err);
138 #endif
139
140 #endif  /* __SYS_WERRNO_H */
141