version 0.1.6
[fms.git] / libs / shttpd / compat_wince.h
1
2 #ifndef INCLUDE_WINCE_COMPAT_H
3 #define INCLUDE_WINCE_COMPAT_H
4
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8
9 /*** ANSI C library ***/
10
11 /* Missing ANSI C definitions */
12
13 #define BUFSIZ 4096
14
15 #define ENOMEM ERROR_NOT_ENOUGH_MEMORY
16 #define EBADF ERROR_INVALID_HANDLE
17 #define EINVAL ERROR_INVALID_PARAMETER
18 #define ENOENT ERROR_FILE_NOT_FOUND
19 #define ERANGE ERROR_INSUFFICIENT_BUFFER
20 #define EINTR WSAEINTR
21
22 /*
23  *      Because we need a per-thread errno, we define a function
24  *      pointer that we can call to return a pointer to the errno
25  *      for the current thread.  Then we define a macro for errno
26  *      that dereferences this function's result.
27  *
28  *      This makes it syntactically just like the "real" errno.
29  *
30  *      Using a function pointer allows us to use a very fast
31  *      function when there are no threads running and a slower
32  *      function when there are multiple threads running.
33  */
34 void __WinCE_Errno_New_Thread(int *Errno_Pointer);
35 void __WinCE_Errno_Thread_Exit(void);
36 extern int *(*__WinCE_Errno_Pointer_Function)(void);
37
38 #define errno (*(*__WinCE_Errno_Pointer_Function)())
39
40 char *strerror(int errnum);
41
42 struct tm {
43         int tm_sec;     /* seconds after the minute - [0,59] */
44         int tm_min;     /* minutes after the hour - [0,59] */
45         int tm_hour;    /* hours since midnight - [0,23] */
46         int tm_mday;    /* day of the month - [1,31] */
47         int tm_mon;     /* months since January - [0,11] */
48         int tm_year;    /* years since 1900 */
49         int tm_wday;    /* days since Sunday - [0,6] */
50         int tm_yday;    /* days since January 1 - [0,365] */
51         int tm_isdst;   /* daylight savings time flag */
52 };
53
54 struct tm *gmtime(const time_t *TimeP); /* for future use */
55 struct tm *localtime(const time_t *TimeP);
56 time_t mktime(struct tm *tm);
57 time_t time(time_t *TimeP);
58
59 size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *tim_p);
60
61 int _wrename(const wchar_t *oldname, const wchar_t *newname);
62 int _wremove(const wchar_t *filename);
63
64 /* Environment variables are not supported */
65 #define getenv(x) (NULL)
66
67 /* Redefine fileno so that it returns an integer */
68 #undef fileno
69 #define fileno(f) (int)_fileno(f)
70
71 /* Signals are not supported */
72 #define signal(num, handler) (0)
73 #define SIGTERM 0
74 #define SIGINT 0
75
76
77 /*** POSIX API ***/
78
79 /* Missing POSIX definitions */
80
81 #define FILENAME_MAX MAX_PATH
82
83 struct _stat {
84         unsigned long st_size;
85         unsigned long st_ino;
86         int st_mode;
87         unsigned long st_atime;
88         unsigned long st_mtime;
89         unsigned long st_ctime;
90         unsigned short st_dev;
91         unsigned short st_nlink;
92         unsigned short st_uid;
93         unsigned short st_gid;
94 };
95
96 #define S_IFMT   0170000
97 #define S_IFDIR  0040000
98 #define S_IFREG  0100000
99 #define S_IEXEC  0000100
100 #define S_IWRITE 0000200 
101 #define S_IREAD  0000400
102
103 #define _S_IFDIR S_IFDIR        /* MSVCRT compatibilit */
104
105 int _fstat(int handle, struct _stat *buffer);
106 int _wstat(const wchar_t *path, struct _stat *buffer);
107
108 #define stat _stat      /* NOTE: applies to _stat() and also struct _stat */
109 #define fstat _fstat
110
111 #define O_RDWR          (1<<0)
112 #define O_RDONLY        (2<<0)
113 #define O_WRONLY        (3<<0)
114 #define O_MODE_MASK     (3<<0)
115 #define O_TRUNC         (1<<2)
116 #define O_EXCL          (1<<3)
117 #define O_CREAT         (1<<4)
118 #define O_BINARY 0
119
120 int _wopen(const wchar_t *filename, int oflag, ...);
121 int _close(int handle);
122 int _write(int handle, const void *buffer, unsigned int count);
123 int _read(int handle, void *buffer, unsigned int count);
124 long _lseek(int handle, long offset, int origin);
125
126 #define close _close
127 #define write _write
128 #define read _read
129 #define lseek _lseek
130
131 /* WinCE has only a Unicode version of this function */
132 FILE *fdopen(int handle, const char *mode);
133
134 int _wmkdir(const wchar_t *dirname);
135
136 /* WinCE has no concept of current directory so we return a constant path */
137 wchar_t *_wgetcwd(wchar_t *buffer, int maxlen);
138
139 #define freopen(path, mode, stream) assert(0)
140
141 #ifdef __cplusplus
142 }
143 #endif
144
145 #endif /* INCLUDE_WINCE_COMPAT_H */