]> sourceware.org Git - newlib-cygwin.git/blob - winsup/cygwin/winsup.h
* dir.cc (readdir): Fill out new old_d_ino field.
[newlib-cygwin.git] / winsup / cygwin / winsup.h
1 /* winsup.h: main Cygwin header file.
2
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 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 #define strlen __builtin_strlen
18 #define strcmp __builtin_strcmp
19 #define strcpy __builtin_strcpy
20 #define memcpy __builtin_memcpy
21 #define memcmp __builtin_memcmp
22 #ifdef HAVE_BUILTIN_MEMSET
23 # define memset __builtin_memset
24 #endif
25
26 #define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
27 #define NO_COPY_INIT __attribute__((section(".data_cygwin_nocopy")))
28
29 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
30 #define NEW_MACRO_VARARGS
31 #endif
32
33 #ifndef _WIN32_WINNT
34 #define _WIN32_WINNT 0x0500
35 #endif
36
37 #include <sys/types.h>
38 #include <sys/strace.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 extern __uid32_t getuid32 (void);
44 extern __uid32_t geteuid32 (void);
45 extern __gid32_t getegid32 (void);
46 extern struct passwd *getpwuid32 (__uid32_t);
47 struct passwd *getpwnam (const char *);
48 #ifdef __cplusplus
49 }
50 #endif
51
52 #ifdef __cplusplus
53
54 extern const char case_folded_lower[];
55 #define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
56 extern const char case_folded_upper[];
57 #define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
58
59 #ifndef MALLOC_DEBUG
60 #define cfree newlib_cfree_dont_use
61 #endif
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 #include <lmcons.h>
73 #undef _WINGDI_H
74 #undef _WINUSER_H
75 #undef _WINNLS_H
76 #undef _WINVER_H
77 #undef _WINNETWK_H
78 #undef _WINSVC_H
79
80 #include "wincap.h"
81
82 /* The one function we use from winuser.h most of the time */
83 extern "C" DWORD WINAPI GetLastError (void);
84
85 enum codepage_type {ansi_cp, oem_cp};
86 extern codepage_type current_codepage;
87
88 UINT get_cp ();
89
90 int __stdcall sys_wcstombs(char *, const WCHAR *, int)
91 __attribute__ ((regparm(3)));
92
93 int __stdcall sys_mbstowcs(WCHAR *, const char *, int)
94 __attribute__ ((regparm(3)));
95
96 /* Used to check if Cygwin DLL is dynamically loaded. */
97 extern int dynamically_loaded;
98
99 extern int cygserver_running;
100
101 #define TITLESIZE 1024
102
103 /* status bit manipulation */
104 #define __ISSETF(what, x, prefix) \
105 ((what)->status & prefix##_##x)
106 #define __SETF(what, x, prefix) \
107 ((what)->status |= prefix##_##x)
108 #define __CLEARF(what, x, prefix) \
109 ((what)->status &= ~prefix##_##x)
110 #define __CONDSETF(n, what, x, prefix) \
111 ((n) ? __SETF (what, x, prefix) : __CLEARF (what, x, prefix))
112
113 #include "debug.h"
114
115 /* Events/mutexes */
116 extern HANDLE title_mutex;
117
118 /**************************** Convenience ******************************/
119
120 /* Used when treating / and \ as equivalent. */
121 #define isdirsep(ch) \
122 ({ \
123 char __c = (ch); \
124 ((__c) == '/' || (__c) == '\\'); \
125 })
126
127 /* Convert a signal to a signal mask */
128 #define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract))
129 extern unsigned int signal_shift_subtract;
130
131 #ifdef NEW_MACRO_VARARGS
132 # define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
133 #else
134 # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
135 #endif
136
137 #undef issep
138 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
139
140 #define isabspath(p) \
141 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
142
143 /******************** Initialization/Termination **********************/
144
145 class per_process;
146 /* cygwin .dll initialization */
147 void dll_crt0 (per_process *) __asm__ ("_dll_crt0__FP11per_process");
148 extern "C" void __stdcall _dll_crt0 ();
149
150 /* dynamically loaded dll initialization */
151 extern "C" int dll_dllcrt0 (HMODULE, per_process *);
152
153 /* dynamically loaded dll initialization for non-cygwin apps */
154 extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
155
156 /* exit the program */
157 extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn));
158
159 /* UID/GID */
160 void uinfo_init (void);
161
162 #define ILLEGAL_UID16 ((__uid16_t)-1)
163 #define ILLEGAL_UID ((__uid32_t)-1)
164 #define ILLEGAL_GID16 ((__gid16_t)-1)
165 #define ILLEGAL_GID ((__gid32_t)-1)
166 #define ILLEGAL_SEEK ((_off64_t)-1)
167
168 #define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
169 #define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
170
171 /* various events */
172 void events_init (void);
173 void events_terminate (void);
174
175 void __stdcall close_all_files (void);
176
177 /* Invisible window initialization/termination. */
178 HWND __stdcall gethwnd (void);
179
180 /* Globals that handle initialization of winsock in a child process. */
181 extern HANDLE wsock32_handle;
182 extern HANDLE ws2_32_handle;
183
184 /* Globals that handle initialization of netapi in a child process. */
185 extern HANDLE netapi32_handle;
186
187 /* debug_on_trap support. see exceptions.cc:try_to_debug() */
188 extern "C" void error_start_init (const char*);
189 extern "C" int try_to_debug (bool waitloop = 1);
190
191 void set_file_api_mode (codepage_type);
192
193 extern int cygwin_finished_initializing;
194
195 /**************************** Miscellaneous ******************************/
196
197 void __stdcall set_std_handle (int);
198 int __stdcall writable_directory (const char *file);
199 int __stdcall stat_dev (DWORD, int, unsigned long, struct __stat64 *);
200 extern BOOL allow_ntsec;
201
202 ino_t __stdcall hash_path_name (ino_t hash, const char *name) __attribute__ ((regparm(2)));
203 void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
204 extern "C" char *__stdcall rootdir (char *full_path) __attribute__ ((regparm(1)));
205
206 /* String manipulation */
207 extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c);
208 extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribute__ ((regparm(2)));
209 extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3)));
210 extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2)));
211
212 /* Time related */
213 void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag);
214 long __stdcall to_time_t (FILETIME * ptr);
215 void __stdcall to_timestruc_t (FILETIME * ptr, timestruc_t * out);
216 void __stdcall time_as_timestruc_t (timestruc_t * out);
217
218 void __stdcall set_console_title (char *);
219 void early_stuff_init ();
220
221 int __stdcall check_null_str (const char *name) __attribute__ ((regparm(1)));
222 int __stdcall check_null_empty_str (const char *name) __attribute__ ((regparm(1)));
223 int __stdcall check_null_empty_str_errno (const char *name) __attribute__ ((regparm(1)));
224 int __stdcall check_null_str_errno (const char *name) __attribute__ ((regparm(1)));
225 int __stdcall __check_null_invalid_struct (void *s, unsigned sz) __attribute__ ((regparm(2)));
226 int __stdcall __check_null_invalid_struct_errno (void *s, unsigned sz) __attribute__ ((regparm(2)));
227 int __stdcall __check_invalid_read_ptr_errno (const void *s, unsigned sz) __attribute__ ((regparm(2)));
228
229 #define check_null_invalid_struct(s) \
230 __check_null_invalid_struct ((s), sizeof (*(s)))
231 #define check_null_invalid_struct_errno(s) \
232 __check_null_invalid_struct_errno ((s), sizeof (*(s)))
233
234 struct iovec;
235 ssize_t check_iovec_for_read (const struct iovec *, int) __attribute__ ((regparm(2)));
236 ssize_t check_iovec_for_write (const struct iovec *, int) __attribute__ ((regparm(2)));
237
238 #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
239 void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2)));
240
241 extern bool wsock_started;
242
243 /* Printf type functions */
244 extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
245 extern "C" int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/;
246 extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/;
247 extern void multiple_cygwin_problem (const char *, unsigned, unsigned);
248
249 class path_conv;
250 int __stdcall stat_worker (const char *name, struct __stat64 *buf, int nofollow,
251 path_conv *pc = NULL) __attribute__ ((regparm (3)));
252 int __stdcall low_priority_sleep (DWORD) __attribute__ ((regparm (1)));
253 #define SLEEP_0_STAY_LOW INFINITE
254
255 /**************************** Exports ******************************/
256
257 extern "C" {
258 int cygwin_select (int , fd_set *, fd_set *, fd_set *,
259 struct timeval *to);
260 int cygwin_gethostname (char *__name, size_t __len);
261
262 int kill_pgrp (pid_t, int);
263 int _kill (int, int);
264 int _raise (int sig);
265
266 extern DWORD binmode;
267 extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
268 extern void (*__CTOR_LIST__) (void);
269 extern void (*__DTOR_LIST__) (void);
270 extern SYSTEM_INFO system_info;
271 };
272
273 /*************************** Unsorted ******************************/
274
275 #define WM_ASYNCIO 0x8000 // WM_APP
276
277 /* Note that MAX_PATH is defined in the windows headers */
278 /* There is also PATH_MAX and MAXPATHLEN.
279 PATH_MAX is from Posix and does *not* include the trailing NUL.
280 MAXPATHLEN is from Unix.
281
282 Thou shalt use MAX_PATH throughout. It avoids the NUL vs no-NUL
283 issue and is neither of the Unixy ones [so we can punt on which
284 one is the right one to use]. */
285
286 #define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
287 #define STD_WBITS (S_IWUSR)
288 #define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
289 #define NO_W ~(S_IWUSR | S_IWGRP | S_IWOTH)
290 #define NO_R ~(S_IRUSR | S_IRGRP | S_IROTH)
291 #define NO_X ~(S_IXUSR | S_IXGRP | S_IXOTH)
292
293 /* The title on program start. */
294 extern char *old_title;
295 extern BOOL display_title;
296
297 extern HANDLE hMainThread;
298 extern HANDLE hMainProc;
299
300 extern bool cygwin_testing;
301 extern unsigned _cygwin_testing_magic;
302 extern HMODULE cygwin_hmodule;
303
304 extern char almost_null[];
305
306 #define winsock2_active (wsadata.wVersion >= 512)
307 #define winsock_active (wsadata.wVersion < 512)
308 extern struct WSAData wsadata;
309
310 #endif /* defined __cplusplus */
This page took 0.048552 seconds and 6 git commands to generate.