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
34 #include <sys/types.h>
35 #include <sys/strace.h>
37 extern const char case_folded_lower
[];
38 #define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
39 extern const char case_folded_upper
[];
40 #define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
43 #define cfree newlib_cfree_dont_use
46 #define WIN32_LEAN_AND_MEAN 1
65 /* The one function we use from winuser.h most of the time */
66 extern "C" DWORD WINAPI
GetLastError (void);
68 enum codepage_type
{ansi_cp
, oem_cp
};
69 extern codepage_type current_codepage
;
71 extern int cygserver_running
;
73 /* Used to check if Cygwin DLL is dynamically loaded. */
74 extern int dynamically_loaded
;
76 #define sys_wcstombs(tgt,src,len) \
77 WideCharToMultiByte((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len),NULL,NULL)
78 #define sys_mbstowcs(tgt,src,len) \
79 MultiByteToWideChar((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len))
81 #define TITLESIZE 1024
83 /* status bit manipulation */
84 #define __ISSETF(what, x, prefix) \
85 ((what)->status & prefix##_##x)
86 #define __SETF(what, x, prefix) \
87 ((what)->status |= prefix##_##x)
88 #define __CLEARF(what, x, prefix) \
89 ((what)->status &= ~prefix##_##x)
90 #define __CONDSETF(n, what, x, prefix) \
91 ((n) ? __SETF (what, x, prefix) : __CLEARF (what, x, prefix))
96 extern HANDLE title_mutex
;
98 /**************************** Convenience ******************************/
100 /* Used when treating / and \ as equivalent. */
101 #define SLASH_P(ch) \
104 ((__c) == '/' || (__c) == '\\'); \
107 /* Convert a signal to a signal mask */
108 #define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract))
109 extern unsigned int signal_shift_subtract
;
111 #ifdef NEW_MACRO_VARARGS
112 # define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
114 # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
118 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
120 #define isdirsep SLASH_P
121 #define isabspath(p) \
122 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
124 /******************** Initialization/Termination **********************/
127 /* cygwin .dll initialization */
128 void dll_crt0 (per_process
*) __asm__ ("_dll_crt0__FP11per_process");
129 extern "C" void __stdcall
_dll_crt0 ();
131 /* dynamically loaded dll initialization */
132 extern "C" int dll_dllcrt0 (HMODULE
, per_process
*);
134 /* dynamically loaded dll initialization for non-cygwin apps */
135 extern "C" int dll_noncygwin_dllcrt0 (HMODULE
, per_process
*);
137 /* exit the program */
138 extern "C" void __stdcall
do_exit (int) __attribute__ ((noreturn
));
141 void uinfo_init (void);
143 #define ILLEGAL_UID16 ((__uid16_t)-1)
144 #define ILLEGAL_UID ((__uid32_t)-1)
145 #define ILLEGAL_GID16 ((__gid16_t)-1)
146 #define ILLEGAL_GID ((__gid32_t)-1)
147 #define ILLEGAL_SEEK ((__off64_t)-1)
149 #define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
150 #define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
152 extern "C" __uid32_t
getuid32 (void);
153 extern "C" __uid32_t
geteuid32 (void);
154 extern "C" struct passwd
*getpwuid32 (__uid32_t
);
157 void events_init (void);
158 void events_terminate (void);
160 void __stdcall
close_all_files (void);
161 BOOL __stdcall
check_pty_fds (void);
163 /* Invisible window initialization/termination. */
164 HWND __stdcall
gethwnd (void);
165 void __stdcall
window_terminate (void);
167 /* Globals that handle initialization of winsock in a child process. */
168 extern HANDLE wsock32_handle
;
169 extern HANDLE ws2_32_handle
;
171 /* Globals that handle initialization of netapi in a child process. */
172 extern HANDLE netapi32_handle
;
174 /* debug_on_trap support. see exceptions.cc:try_to_debug() */
175 extern "C" void error_start_init (const char*);
176 extern "C" int try_to_debug (bool waitloop
= 1);
178 void set_file_api_mode (codepage_type
);
180 extern int cygwin_finished_initializing
;
182 /**************************** Miscellaneous ******************************/
184 void __stdcall
set_std_handle (int);
185 int __stdcall
writable_directory (const char *file
);
186 int __stdcall
stat_dev (DWORD
, int, unsigned long, struct __stat64
*);
187 extern BOOL allow_ntsec
;
189 unsigned long __stdcall
hash_path_name (unsigned long hash
, const char *name
) __attribute__ ((regparm(2)));
190 void __stdcall
nofinalslash (const char *src
, char *dst
) __attribute__ ((regparm(2)));
191 extern "C" char *__stdcall
rootdir (char *full_path
) __attribute__ ((regparm(1)));
193 /* String manipulation */
194 extern "C" char *__stdcall
strccpy (char *s1
, const char **s2
, char c
);
195 extern "C" int __stdcall
strcasematch (const char *s1
, const char *s2
) __attribute__ ((regparm(2)));
196 extern "C" int __stdcall
strncasematch (const char *s1
, const char *s2
, size_t n
) __attribute__ ((regparm(3)));
197 extern "C" char *__stdcall
strcasestr (const char *searchee
, const char *lookfor
) __attribute__ ((regparm(2)));
200 void __stdcall
totimeval (struct timeval
*dst
, FILETIME
* src
, int sub
, int flag
);
201 long __stdcall
to_time_t (FILETIME
* ptr
);
202 void __stdcall
to_timestruc_t (FILETIME
* ptr
, timestruc_t
* out
);
203 void __stdcall
time_as_timestruc_t (timestruc_t
* out
);
205 void __stdcall
set_console_title (char *);
206 void early_stuff_init ();
208 int __stdcall
check_null_str (const char *name
) __attribute__ ((regparm(1)));
209 int __stdcall
check_null_empty_str (const char *name
) __attribute__ ((regparm(1)));
210 int __stdcall
check_null_empty_str_errno (const char *name
) __attribute__ ((regparm(1)));
211 int __stdcall
check_null_str_errno (const char *name
) __attribute__ ((regparm(1)));
212 int __stdcall
__check_null_invalid_struct (const void *s
, unsigned sz
) __attribute__ ((regparm(2)));
213 int __stdcall
__check_null_invalid_struct_errno (const void *s
, unsigned sz
) __attribute__ ((regparm(2)));
214 int __stdcall
__check_invalid_read_ptr_errno (const void *s
, unsigned sz
) __attribute__ ((regparm(2)));
216 #define check_null_invalid_struct(s) \
217 __check_null_invalid_struct ((s), sizeof (*(s)))
218 #define check_null_invalid_struct_errno(s) \
219 __check_null_invalid_struct_errno ((s), sizeof (*(s)))
221 #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
222 void __set_winsock_errno (const char *fn
, int ln
) __attribute__ ((regparm(2)));
224 extern bool wsock_started
;
226 /* Printf type functions */
227 extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn
));
228 extern "C" int __small_sprintf (char *dst
, const char *fmt
, ...) /*__attribute__ ((regparm (2)))*/;
229 extern "C" int __small_vsprintf (char *dst
, const char *fmt
, va_list ap
) /*__attribute__ ((regparm (3)))*/;
230 extern void multiple_cygwin_problem (const char *, unsigned, unsigned);
232 extern "C" void __malloc_lock (struct _reent
*);
233 extern "C" void __malloc_unlock (struct _reent
*);
236 int __stdcall
stat_worker (const char *name
, struct __stat64
*buf
, int nofollow
,
237 path_conv
*pc
= NULL
) __attribute__ ((regparm (3)));
239 /**************************** Exports ******************************/
242 int cygwin_select (int , fd_set
*, fd_set
*, fd_set
*,
244 int cygwin_gethostname (char *__name
, size_t __len
);
246 int kill_pgrp (pid_t
, int);
247 int _kill (int, int);
248 int _raise (int sig
);
250 extern DWORD binmode
;
251 extern char _data_start__
, _data_end__
, _bss_start__
, _bss_end__
;
252 extern void (*__CTOR_LIST__
) (void);
253 extern void (*__DTOR_LIST__
) (void);
254 extern SYSTEM_INFO system_info
;
257 /*************************** Unsorted ******************************/
259 #define WM_ASYNCIO 0x8000 // WM_APP
261 /* Note that MAX_PATH is defined in the windows headers */
262 /* There is also PATH_MAX and MAXPATHLEN.
263 PATH_MAX is from Posix and does *not* include the trailing NUL.
264 MAXPATHLEN is from Unix.
266 Thou shalt use MAX_PATH throughout. It avoids the NUL vs no-NUL
267 issue and is neither of the Unixy ones [so we can punt on which
268 one is the right one to use]. */
270 #define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
271 #define STD_WBITS (S_IWUSR)
272 #define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
273 #define NO_W ~(S_IWUSR | S_IWGRP | S_IWOTH)
274 #define NO_R ~(S_IRUSR | S_IRGRP | S_IROTH)
275 #define NO_X ~(S_IXUSR | S_IXGRP | S_IXOTH)
277 /* The title on program start. */
278 extern char *old_title
;
279 extern BOOL display_title
;
281 extern HANDLE hMainThread
;
282 extern HANDLE hMainProc
;
284 extern bool cygwin_testing
;
285 extern unsigned _cygwin_testing_magic
;
286 extern HMODULE cygwin_hmodule
;
288 #define winsock2_active (wsadata.wVersion >= 512)
289 #define winsock_active (wsadata.wVersion < 512)
290 extern struct WSAData wsadata
;
292 #endif /* defined __cplusplus */