OSDN Git Service

* fhandler.cc (fhandler_base::fcntl): Behave properly when passed
[pf3gnuchains/sourceware.git] / winsup / cygwin / winsup.h
1 /* winsup.h: main Cygwin header file.
2
3    Copyright 1996, 1997, 1998, 1999, 2000 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #ifdef HAVE_CONFIG_H
12 # include "config.h"
13 #endif
14
15 #define __INSIDE_CYGWIN__
16
17 #ifdef __cplusplus
18
19 #define alloca __builtin_alloca
20 #define strlen __builtin_strlen
21 #define strcmp __builtin_strcmp
22 #define strcpy __builtin_strcpy
23 #define memcpy __builtin_memcpy
24 #define memcmp __builtin_memcmp
25 #ifdef HAVE_BUILTIN_MEMSET
26 # define memset __builtin_memset
27 #endif
28
29 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
30 #define NEW_MACRO_VARARGS
31 #endif
32
33 #include <sys/types.h>
34 #include <sys/strace.h>
35
36 #undef strchr
37 #define strchr cygwin_strchr
38 extern "C" inline __stdcall char * strchr(const char * s, int c)
39 {
40 register char * __res;
41 __asm__ __volatile__(
42         "movb %%al,%%ah\n"
43         "1:\tmovb (%1),%%al\n\t"
44         "cmpb %%ah,%%al\n\t"
45         "je 2f\n\t"
46         "incl %1\n\t"
47         "testb %%al,%%al\n\t"
48         "jne 1b\n\t"
49         "xorl %1,%1\n"
50         "2:\tmovl %1,%0\n\t"
51         :"=a" (__res), "=r" (s)
52         :"0" (c),      "1"  (s));
53 return __res;
54 }
55
56 extern char case_folded_lower[];
57 #define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
58 extern char case_folded_upper[];
59 #define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
60
61 #define cfree newlib_cfree_dont_use
62
63 #define WIN32_LEAN_AND_MEAN 1
64 #define _WINGDI_H
65 #define _WINUSER_H
66 #define _WINNLS_H
67 #define _WINVER_H
68 #define _WINNETWK_H
69 #define _WINSVC_H
70 #include <windows.h>
71 #include <wincrypt.h>
72 #undef _WINGDI_H
73 #undef _WINUSER_H
74 #undef _WINNLS_H
75 #undef _WINVER_H
76 #undef _WINNETWK_H
77 #undef _WINSVC_H
78
79 /* The one function we use from winuser.h most of the time */
80 extern "C" DWORD WINAPI GetLastError (void);
81
82 /* Used for runtime OS check/decisions. */
83 enum os_type {winNT = 1, win95, win98, winME, win32s, unknown};
84 extern os_type os_being_run;
85
86 /* Used to check if Cygwin DLL is dynamically loaded. */
87 extern int dynamically_loaded;
88
89 #define sys_wcstombs(tgt,src,len) \
90                     WideCharToMultiByte(CP_ACP,0,(src),-1,(tgt),(len),NULL,NULL)
91 #define sys_mbstowcs(tgt,src,len) \
92                     MultiByteToWideChar(CP_ACP,0,(src),-1,(tgt),(len))
93
94 #define TITLESIZE 1024
95 #define MAX_USER_NAME 20
96 #define DEFAULT_UID 500
97 #define DEFAULT_GID 544
98
99 #define MAX_SID_LEN 40
100 #define MAX_HOST_NAME 256
101
102 /* status bit manipulation */
103 #define __ISSETF(what, x, prefix) \
104   ((what)->status & prefix##_##x)
105 #define __SETF(what, x, prefix) \
106   ((what)->status |= prefix##_##x)
107 #define __CLEARF(what, x, prefix) \
108   ((what)->status &= ~prefix##_##x)
109 #define __CONDSETF(n, what, x, prefix) \
110   ((n) ? __SETF (what, x, prefix) : __CLEARF (what, x, prefix))
111
112 #include "debug.h"
113
114 /* Events/mutexes */
115 extern HANDLE title_mutex;
116
117 /**************************** Convenience ******************************/
118
119 #define NO_COPY __attribute__((section(".data_cygwin_nocopy")))
120
121 /* Used when treating / and \ as equivalent. */
122 #define SLASH_P(ch) \
123     ({ \
124         char __c = (ch); \
125         ((__c) == '/' || (__c) == '\\'); \
126     })
127
128 /* Convert a signal to a signal mask */
129 #define SIGTOMASK(sig)  (1<<((sig) - signal_shift_subtract))
130 extern unsigned int signal_shift_subtract;
131
132 #ifdef NEW_MACRO_VARARGS
133 # define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
134 #else
135 # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
136 #endif
137
138 #undef issep
139 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
140
141 #define isdirsep SLASH_P
142 #define isabspath(p) \
143   (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
144
145 /******************** Initialization/Termination **********************/
146
147 class per_process;
148 /* cygwin .dll initialization */
149 void dll_crt0 (per_process *);
150 extern "C" void __stdcall _dll_crt0 ();
151
152 /* dynamically loaded dll initialization */
153 extern "C" int dll_dllcrt0 (HMODULE, per_process *);
154
155 /* dynamically loaded dll initialization for non-cygwin apps */
156 extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
157
158 /* exit the program */
159 extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn));
160
161 /* UID/GID */
162 void uinfo_init (void);
163
164 /* various events */
165 void events_init (void);
166 void events_terminate (void);
167
168 void __stdcall close_all_files (void);
169
170 /* Invisible window initialization/termination. */
171 HWND __stdcall gethwnd (void);
172 void __stdcall window_terminate (void);
173
174 /* Globals that handle initialization of winsock in a child process. */
175 extern HANDLE wsock32_handle;
176
177 /* Globals that handle initialization of netapi in a child process. */
178 extern HANDLE netapi32_handle;
179
180 /* debug_on_trap support. see exceptions.cc:try_to_debug() */
181 extern "C" void error_start_init (const char*);
182 extern "C" int try_to_debug ();
183
184 extern int cygwin_finished_initializing;
185
186 /**************************** Miscellaneous ******************************/
187
188 void __stdcall set_std_handle (int);
189 int __stdcall writable_directory (const char *file);
190 int __stdcall stat_dev (DWORD, int, unsigned long, struct stat *);
191 extern BOOL allow_ntsec;
192
193 unsigned long __stdcall hash_path_name (unsigned long hash, const char *name) __attribute__ ((regparm(2)));
194 void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
195 extern "C" char *__stdcall rootdir (char *full_path) __attribute__ ((regparm(1)));
196
197 /* String manipulation */
198 extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c);
199 extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribute__ ((regparm(2)));
200 extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3)));
201 extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2)));
202
203 /* Time related */
204 void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag);
205 long __stdcall to_time_t (FILETIME * ptr);
206
207 void __stdcall set_console_title (char *);
208 void set_console_handler ();
209
210 #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
211 void __set_winsock_errno (const char *fn, int ln);
212
213 /* Printf type functions */
214 extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
215 extern "C" int __small_sprintf (char *dst, const char *fmt, ...);
216 extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap);
217
218 /**************************** Exports ******************************/
219
220 extern "C" {
221 int cygwin_select (int , fd_set *, fd_set *, fd_set *,
222                    struct timeval *to);
223 int cygwin_gethostname (char *__name, size_t __len);
224
225 int kill_pgrp (pid_t, int);
226 int _kill (int, int);
227 int _raise (int sig);
228
229 extern DWORD binmode;
230 extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
231 extern void (*__CTOR_LIST__) (void);
232 extern void (*__DTOR_LIST__) (void);
233 };
234
235 /*************************** Unsorted ******************************/
236
237 #define WM_ASYNCIO      0x8000          // WM_APP
238
239 /* Note that MAX_PATH is defined in the windows headers */
240 /* There is also PATH_MAX and MAXPATHLEN.
241    PATH_MAX is from Posix and does *not* include the trailing NUL.
242    MAXPATHLEN is from Unix.
243
244    Thou shalt use MAX_PATH throughout.  It avoids the NUL vs no-NUL
245    issue and is neither of the Unixy ones [so we can punt on which
246    one is the right one to use].  */
247
248 #define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
249 #define STD_WBITS (S_IWUSR)
250 #define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
251
252 #define O_NOSYMLINK 0x080000
253 #define O_DIROPEN   0x100000
254
255 /* newlib used to define O_NDELAY differently from O_NONBLOCK.  Now it
256    properly defines both to be the same.  Unfortunately, we have to
257    behave properly the old version, too, to accomodate older executables. */
258 #define OLD_O_NDELAY    4
259
260 /* The title on program start. */
261 extern char *old_title;
262 extern BOOL display_title;
263
264 extern HANDLE hMainThread;
265 extern HANDLE hMainProc;
266
267 #endif /* defined __cplusplus */