1 /* winsup.h: main Cygwin header file.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
15 #define __INSIDE_CYGWIN__
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
26 #define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
27 #define NO_COPY_INIT __attribute__((section(".data_cygwin_nocopy")))
29 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
30 #define NEW_MACRO_VARARGS
34 #define _WIN32_WINNT 0x0500
37 #include <sys/types.h>
38 #include <sys/strace.h>
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 *);
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)])
60 #define cfree newlib_cfree_dont_use
63 #define WIN32_LEAN_AND_MEAN 1
82 /* The one function we use from winuser.h most of the time */
83 extern "C" DWORD WINAPI
GetLastError (void);
85 enum codepage_type
{ansi_cp
, oem_cp
};
86 extern codepage_type current_codepage
;
90 int __stdcall
sys_wcstombs(char *, const WCHAR
*, int)
91 __attribute__ ((regparm(3)));
93 int __stdcall
sys_mbstowcs(WCHAR
*, const char *, int)
94 __attribute__ ((regparm(3)));
96 /* Used to check if Cygwin DLL is dynamically loaded. */
97 extern int dynamically_loaded
;
99 extern int cygserver_running
;
101 #define TITLESIZE 1024
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))
116 extern HANDLE title_mutex
;
118 /**************************** Convenience ******************************/
120 /* Used when treating / and \ as equivalent. */
121 #define isdirsep(ch) \
124 ((__c) == '/' || (__c) == '\\'); \
127 /* Convert a signal to a signal mask */
128 #define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract))
129 extern unsigned int signal_shift_subtract
;
131 #ifdef NEW_MACRO_VARARGS
132 # define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
134 # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
138 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
140 #define isabspath(p) \
141 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
143 /******************** Initialization/Termination **********************/
146 /* cygwin .dll initialization */
147 void dll_crt0 (per_process
*) __asm__ ("_dll_crt0__FP11per_process");
148 extern "C" void __stdcall
_dll_crt0 ();
150 /* dynamically loaded dll initialization */
151 extern "C" int dll_dllcrt0 (HMODULE
, per_process
*);
153 /* dynamically loaded dll initialization for non-cygwin apps */
154 extern "C" int dll_noncygwin_dllcrt0 (HMODULE
, per_process
*);
156 /* exit the program */
157 extern "C" void __stdcall
do_exit (int) __attribute__ ((noreturn
));
160 void uinfo_init (void);
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)
168 #define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
169 #define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
172 void events_init (void);
173 void events_terminate (void);
175 void __stdcall
close_all_files (void);
177 /* Invisible window initialization/termination. */
178 HWND __stdcall
gethwnd (void);
180 /* Globals that handle initialization of winsock in a child process. */
181 extern HANDLE wsock32_handle
;
182 extern HANDLE ws2_32_handle
;
184 /* Globals that handle initialization of netapi in a child process. */
185 extern HANDLE netapi32_handle
;
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);
191 void set_file_api_mode (codepage_type
);
193 extern int cygwin_finished_initializing
;
195 /**************************** Miscellaneous ******************************/
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
;
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)));
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)));
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
);
218 void __stdcall
set_console_title (char *);
219 void early_stuff_init ();
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)));
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)))
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)));
238 #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
239 void __set_winsock_errno (const char *fn
, int ln
) __attribute__ ((regparm(2)));
241 extern bool wsock_started
;
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);
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
255 /**************************** Exports ******************************/
258 int cygwin_select (int , fd_set
*, fd_set
*, fd_set
*,
260 int cygwin_gethostname (char *__name
, size_t __len
);
262 int kill_pgrp (pid_t
, int);
263 int _kill (int, int);
264 int _raise (int sig
);
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
;
273 /*************************** Unsorted ******************************/
275 #define WM_ASYNCIO 0x8000 // WM_APP
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.
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]. */
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)
293 /* The title on program start. */
294 extern char *old_title
;
295 extern BOOL display_title
;
297 extern HANDLE hMainThread
;
298 extern HANDLE hMainProc
;
300 extern bool cygwin_testing
;
301 extern unsigned _cygwin_testing_magic
;
302 extern HMODULE cygwin_hmodule
;
304 extern char almost_null
[];
306 #define winsock2_active (wsadata.wVersion >= 512)
307 #define winsock_active (wsadata.wVersion < 512)
308 extern struct WSAData wsadata
;
310 #endif /* defined __cplusplus */