version 0.1.6
[fms.git] / libs / shttpd / compat_win32.h
1 /*
2  * Copyright (c) 2004-2007 Sergey Lyubka <valenok@gmail.com>
3  * All rights reserved
4  *
5  * "THE BEER-WARE LICENSE" (Revision 42):
6  * Sergey Lyubka wrote this file.  As long as you retain this notice you
7  * can do whatever you want with this stuff. If we meet some day, and you think
8  * this stuff is worth it, you can buy me a beer in return.
9  */
10
11 /* Tip from Justin Maximilian, suppress errors from winsock2.h */
12 #define _WINSOCKAPI_
13
14 #include <windows.h>
15 #include <winsock2.h>
16 #include <commctrl.h>
17 #include <winnls.h>
18 #include <shlobj.h>
19 #include <shellapi.h>
20
21 #ifndef _WIN32_WCE
22
23 #ifdef _MSC_VER /* pragmas not valid on MinGW */
24 #pragma comment(lib,"ws2_32")
25 #pragma comment(lib,"user32")
26 #pragma comment(lib,"comctl32")
27 #pragma comment(lib,"comdlg32")
28 #pragma comment(lib,"shell32")
29 #ifdef NO_GUI
30 #pragma comment(linker,"/subsystem:console")
31 #else
32 #pragma comment(linker,"/subsystem:windows")
33 #endif /* NO_GUI */
34 #endif /* _MSC_VER */
35 #include <process.h>
36 #include <direct.h>
37 #include <io.h>
38
39 #else /* _WIN32_WCE */
40
41 /* Windows CE-specific definitions */
42 #define NO_CGI  /* WinCE has no pipes */
43 #define NO_GUI  /* temporarily until it is fixed */
44 #pragma comment(lib,"ws2")
45 /* WinCE has both Unicode and ANSI versions of GetProcAddress */
46 #undef GetProcAddress
47 #define GetProcAddress GetProcAddressA
48 #include "compat_wince.h"
49
50 #endif /* _WIN32_WCE */
51
52 #define ERRNO                   GetLastError()
53 #define NO_SOCKLEN_T
54 #define SSL_LIB                 L"libssl32.dll"
55 #define DIRSEP                  '\\'
56 #define IS_DIRSEP_CHAR(c)       ((c) == '/' || (c) == '\\')
57 #define O_NONBLOCK              0
58 #define EWOULDBLOCK             WSAEWOULDBLOCK
59 #define snprintf                _snprintf
60 #define vsnprintf               _vsnprintf
61 #define mkdir(x,y)              _mkdir(x)
62 #define popen(x,y)              _popen(x, y)
63 #define pclose(x)               _pclose(x)
64 #define dlopen(x,y)             LoadLibraryW(x)
65 #define dlsym(x,y)              (void *) GetProcAddress(x,y)
66 #define _POSIX_
67
68 #ifdef __LCC__
69 #include <stdint.h>
70 #endif /* __LCC__ */
71
72 #ifdef _MSC_VER /* MinGW already has these */
73 typedef unsigned int            uint32_t;
74 typedef unsigned short          uint16_t;
75 typedef __int64                 uint64_t;
76 #define S_ISDIR(x)              ((x) & _S_IFDIR)
77 #endif /* _MSC_VER */
78
79 /*
80  * POSIX dirent interface
81  */
82 struct dirent {
83         char    d_name[FILENAME_MAX];
84 };
85
86 typedef struct DIR {
87         HANDLE                  handle;
88         WIN32_FIND_DATAW        info;
89         struct dirent           result;
90         char                    *name;
91 } DIR;
92
93 extern DIR *opendir(const char *name);
94 extern int closedir(DIR *dir);
95 extern struct dirent *readdir(DIR *dir);