1 /* winsup.h: main Cygwin header file.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 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")))
30 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
31 #define NEW_MACRO_VARARGS
35 #define _WIN32_WINNT 0x0500
38 #include <sys/types.h>
39 #include <sys/strace.h>
41 extern const char case_folded_lower
[];
42 #define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
43 extern const char case_folded_upper
[];
44 #define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
47 #define cfree newlib_cfree_dont_use
50 #define WIN32_LEAN_AND_MEAN 1
69 /* The one function we use from winuser.h most of the time */
70 extern "C" DWORD WINAPI
GetLastError (void);
72 enum codepage_type
{ansi_cp
, oem_cp
};
73 extern codepage_type current_codepage
;
77 int __stdcall
sys_wcstombs(char *, const WCHAR
*, int)
78 __attribute__ ((regparm(3)));
80 int __stdcall
sys_mbstowcs(WCHAR
*, const char *, int)
81 __attribute__ ((regparm(3)));
83 /* Used to check if Cygwin DLL is dynamically loaded. */
84 extern int dynamically_loaded
;
86 extern int cygserver_running
;
88 #define TITLESIZE 1024
90 /* status bit manipulation */
91 #define __ISSETF(what, x, prefix) \
92 ((what)->status & prefix##_##x)
93 #define __SETF(what, x, prefix) \
94 ((what)->status |= prefix##_##x)
95 #define __CLEARF(what, x, prefix) \
96 ((what)->status &= ~prefix##_##x)
97 #define __CONDSETF(n, what, x, prefix) \
98 ((n) ? __SETF (what, x, prefix) : __CLEARF (what, x, prefix))
103 extern HANDLE title_mutex
;
105 /**************************** Convenience ******************************/
107 /* Used when treating / and \ as equivalent. */
108 #define SLASH_P(ch) \
111 ((__c) == '/' || (__c) == '\\'); \
114 /* Convert a signal to a signal mask */
115 #define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract))
116 extern unsigned int signal_shift_subtract
;
118 #ifdef NEW_MACRO_VARARGS
119 # define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
121 # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
125 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
127 #define isdirsep SLASH_P
128 #define isabspath(p) \
129 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
131 /******************** Initialization/Termination **********************/
134 /* cygwin .dll initialization */
135 void dll_crt0 (per_process
*) __asm__ ("_dll_crt0__FP11per_process");
136 extern "C" void __stdcall
_dll_crt0 ();
138 /* dynamically loaded dll initialization */
139 extern "C" int dll_dllcrt0 (HMODULE
, per_process
*);
141 /* dynamically loaded dll initialization for non-cygwin apps */
142 extern "C" int dll_noncygwin_dllcrt0 (HMODULE
, per_process
*);
144 /* exit the program */
145 extern "C" void __stdcall
do_exit (int) __attribute__ ((noreturn
));
148 void uinfo_init (void);
150 #define ILLEGAL_UID16 ((__uid16_t)-1)
151 #define ILLEGAL_UID ((__uid32_t)-1)
152 #define ILLEGAL_GID16 ((__gid16_t)-1)
153 #define ILLEGAL_GID ((__gid32_t)-1)
154 #define ILLEGAL_SEEK ((__off64_t)-1)
156 #define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
157 #define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
159 extern "C" __uid32_t
getuid32 (void);
160 extern "C" __uid32_t
geteuid32 (void);
161 extern "C" struct passwd
*getpwuid32 (__uid32_t
);
164 void events_init (void);
165 void events_terminate (void);
167 void __stdcall
close_all_files (void);
168 BOOL __stdcall
check_pty_fds (void);
170 /* Invisible window initialization/termination. */
171 HWND __stdcall
gethwnd (void);
172 void __stdcall
window_terminate (void);
174 /* Globals that handle initialization of winsock in a child process. */
175 extern HANDLE wsock32_handle
;
176 extern HANDLE ws2_32_handle
;
178 /* Globals that handle initialization of netapi in a child process. */
179 extern HANDLE netapi32_handle
;
181 /* debug_on_trap support. see exceptions.cc:try_to_debug() */
182 extern "C" void error_start_init (const char*);
183 extern "C" int try_to_debug (bool waitloop
= 1);
185 void set_file_api_mode (codepage_type
);
187 extern int cygwin_finished_initializing
;
189 /**************************** Miscellaneous ******************************/
191 void __stdcall
set_std_handle (int);
192 int __stdcall
writable_directory (const char *file
);
193 int __stdcall
stat_dev (DWORD
, int, unsigned long, struct __stat64
*);
194 extern BOOL allow_ntsec
;
196 unsigned long __stdcall
hash_path_name (unsigned long hash
, const char *name
) __attribute__ ((regparm(2)));
197 void __stdcall
nofinalslash (const char *src
, char *dst
) __attribute__ ((regparm(2)));
198 extern "C" char *__stdcall
rootdir (char *full_path
) __attribute__ ((regparm(1)));
200 /* String manipulation */
201 extern "C" char *__stdcall
strccpy (char *s1
, const char **s2
, char c
);
202 extern "C" int __stdcall
strcasematch (const char *s1
, const char *s2
) __attribute__ ((regparm(2)));
203 extern "C" int __stdcall
strncasematch (const char *s1
, const char *s2
, size_t n
) __attribute__ ((regparm(3)));
204 extern "C" char *__stdcall
strcasestr (const char *searchee
, const char *lookfor
) __attribute__ ((regparm(2)));
207 void __stdcall
totimeval (struct timeval
*dst
, FILETIME
* src
, int sub
, int flag
);
208 long __stdcall
to_time_t (FILETIME
* ptr
);
209 void __stdcall
to_timestruc_t (FILETIME
* ptr
, timestruc_t
* out
);
210 void __stdcall
time_as_timestruc_t (timestruc_t
* out
);
212 void __stdcall
set_console_title (char *);
213 void early_stuff_init ();
215 int __stdcall
check_null_str (const char *name
) __attribute__ ((regparm(1)));
216 int __stdcall
check_null_empty_str (const char *name
) __attribute__ ((regparm(1)));
217 int __stdcall
check_null_empty_str_errno (const char *name
) __attribute__ ((regparm(1)));
218 int __stdcall
check_null_str_errno (const char *name
) __attribute__ ((regparm(1)));
219 int __stdcall
__check_null_invalid_struct (void *s
, unsigned sz
) __attribute__ ((regparm(2)));
220 int __stdcall
__check_null_invalid_struct_errno (void *s
, unsigned sz
) __attribute__ ((regparm(2)));
221 int __stdcall
__check_invalid_read_ptr_errno (const void *s
, unsigned sz
) __attribute__ ((regparm(2)));
223 #define check_null_invalid_struct(s) \
224 __check_null_invalid_struct ((s), sizeof (*(s)))
225 #define check_null_invalid_struct_errno(s) \
226 __check_null_invalid_struct_errno ((s), sizeof (*(s)))
229 ssize_t
check_iovec_for_read (const struct iovec
*, int) __attribute__ ((regparm(2)));
230 ssize_t
check_iovec_for_write (const struct iovec
*, int) __attribute__ ((regparm(2)));
232 #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
233 void __set_winsock_errno (const char *fn
, int ln
) __attribute__ ((regparm(2)));
235 extern bool wsock_started
;
237 /* Printf type functions */
238 extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn
));
239 extern "C" int __small_sprintf (char *dst
, const char *fmt
, ...) /*__attribute__ ((regparm (2)))*/;
240 extern "C" int __small_vsprintf (char *dst
, const char *fmt
, va_list ap
) /*__attribute__ ((regparm (3)))*/;
241 extern void multiple_cygwin_problem (const char *, unsigned, unsigned);
244 int __stdcall
stat_worker (const char *name
, struct __stat64
*buf
, int nofollow
,
245 path_conv
*pc
= NULL
) __attribute__ ((regparm (3)));
247 /**************************** Exports ******************************/
250 int cygwin_select (int , fd_set
*, fd_set
*, fd_set
*,
252 int cygwin_gethostname (char *__name
, size_t __len
);
254 int kill_pgrp (pid_t
, int);
255 int _kill (int, int);
256 int _raise (int sig
);
258 extern DWORD binmode
;
259 extern char _data_start__
, _data_end__
, _bss_start__
, _bss_end__
;
260 extern void (*__CTOR_LIST__
) (void);
261 extern void (*__DTOR_LIST__
) (void);
262 extern SYSTEM_INFO system_info
;
265 /*************************** Unsorted ******************************/
267 #define WM_ASYNCIO 0x8000 // WM_APP
269 /* Note that MAX_PATH is defined in the windows headers */
270 /* There is also PATH_MAX and MAXPATHLEN.
271 PATH_MAX is from Posix and does *not* include the trailing NUL.
272 MAXPATHLEN is from Unix.
274 Thou shalt use MAX_PATH throughout. It avoids the NUL vs no-NUL
275 issue and is neither of the Unixy ones [so we can punt on which
276 one is the right one to use]. */
278 #define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
279 #define STD_WBITS (S_IWUSR)
280 #define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
281 #define NO_W ~(S_IWUSR | S_IWGRP | S_IWOTH)
282 #define NO_R ~(S_IRUSR | S_IRGRP | S_IROTH)
283 #define NO_X ~(S_IXUSR | S_IXGRP | S_IXOTH)
285 /* The title on program start. */
286 extern char *old_title
;
287 extern BOOL display_title
;
289 extern HANDLE hMainThread
;
290 extern HANDLE hMainProc
;
292 extern bool cygwin_testing
;
293 extern unsigned _cygwin_testing_magic
;
294 extern HMODULE cygwin_hmodule
;
296 extern char almost_null
[];
298 #define winsock2_active (wsadata.wVersion >= 512)
299 #define winsock_active (wsadata.wVersion < 512)
300 extern struct WSAData wsadata
;
302 #endif /* defined __cplusplus */