1 /* winsup.h: main Cygwin header file.
3 Copyright 1996, 1997, 1998, 1999, 2000, 2001 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 alloca __builtin_alloca
18 #define strlen __builtin_strlen
19 #define strcmp __builtin_strcmp
20 #define strcpy __builtin_strcpy
21 #define memcpy __builtin_memcpy
22 #define memcmp __builtin_memcmp
23 #ifdef HAVE_BUILTIN_MEMSET
24 # define memset __builtin_memset
29 #if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
30 #define NEW_MACRO_VARARGS
33 #include <sys/types.h>
34 #include <sys/strace.h>
36 extern char case_folded_lower[];
37 #define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
38 extern char case_folded_upper[];
39 #define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
42 #define cfree newlib_cfree_dont_use
45 #define WIN32_LEAN_AND_MEAN 1
62 /* The one function we use from winuser.h most of the time */
63 extern "C" DWORD WINAPI GetLastError (void);
65 /* Used for runtime OS check/decisions. */
66 enum os_type {winNT = 1, win95, win98, winME, win32s, unknown};
67 extern os_type os_being_run;
69 enum codepage_type {ansi_cp, oem_cp};
70 extern codepage_type current_codepage;
72 /* Used to check if Cygwin DLL is dynamically loaded. */
73 extern int dynamically_loaded;
75 #define sys_wcstombs(tgt,src,len) \
76 WideCharToMultiByte((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len),NULL,NULL)
77 #define sys_mbstowcs(tgt,src,len) \
78 MultiByteToWideChar((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len))
80 #define TITLESIZE 1024
82 /* status bit manipulation */
83 #define __ISSETF(what, x, prefix) \
84 ((what)->status & prefix##_##x)
85 #define __SETF(what, x, prefix) \
86 ((what)->status |= prefix##_##x)
87 #define __CLEARF(what, x, prefix) \
88 ((what)->status &= ~prefix##_##x)
89 #define __CONDSETF(n, what, x, prefix) \
90 ((n) ? __SETF (what, x, prefix) : __CLEARF (what, x, prefix))
95 extern HANDLE title_mutex;
97 /**************************** Convenience ******************************/
99 #define NO_COPY __attribute__((section(".data_cygwin_nocopy")))
101 /* Used when treating / and \ as equivalent. */
102 #define SLASH_P(ch) \
105 ((__c) == '/' || (__c) == '\\'); \
108 /* Convert a signal to a signal mask */
109 #define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract))
110 extern unsigned int signal_shift_subtract;
112 #ifdef NEW_MACRO_VARARGS
113 # define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
115 # define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
119 #define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
121 #define isdirsep SLASH_P
122 #define isabspath(p) \
123 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
125 /******************** Initialization/Termination **********************/
128 /* cygwin .dll initialization */
129 void dll_crt0 (per_process *) __asm__ ("_dll_crt0__FP11per_process");
130 extern "C" void __stdcall _dll_crt0 ();
132 /* dynamically loaded dll initialization */
133 extern "C" int dll_dllcrt0 (HMODULE, per_process *);
135 /* dynamically loaded dll initialization for non-cygwin apps */
136 extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
138 /* exit the program */
139 extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn));
142 void uinfo_init (void);
145 void events_init (void);
146 void events_terminate (void);
148 void __stdcall close_all_files (void);
150 /* Invisible window initialization/termination. */
151 HWND __stdcall gethwnd (void);
152 void __stdcall window_terminate (void);
154 /* Globals that handle initialization of winsock in a child process. */
155 extern HANDLE wsock32_handle;
156 extern HANDLE ws2_32_handle;
158 /* Globals that handle initialization of netapi in a child process. */
159 extern HANDLE netapi32_handle;
161 /* debug_on_trap support. see exceptions.cc:try_to_debug() */
162 extern "C" void error_start_init (const char*);
163 extern "C" int try_to_debug (bool waitloop = 1);
165 void set_file_api_mode (codepage_type);
167 extern int cygwin_finished_initializing;
169 /**************************** Miscellaneous ******************************/
171 void __stdcall set_std_handle (int);
172 int __stdcall writable_directory (const char *file);
173 int __stdcall stat_dev (DWORD, int, unsigned long, struct stat *);
174 extern BOOL allow_ntsec;
176 unsigned long __stdcall hash_path_name (unsigned long hash, const char *name) __attribute__ ((regparm(2)));
177 void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
178 extern "C" char *__stdcall rootdir (char *full_path) __attribute__ ((regparm(1)));
180 /* String manipulation */
181 extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c);
182 extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribute__ ((regparm(2)));
183 extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3)));
184 extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2)));
187 void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag);
188 long __stdcall to_time_t (FILETIME * ptr);
190 void __stdcall set_console_title (char *);
191 void set_console_handler ();
193 #define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
194 void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2)));
196 /* Printf type functions */
197 extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
198 extern "C" int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/;
199 extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/;
201 /**************************** Exports ******************************/
204 int cygwin_select (int , fd_set *, fd_set *, fd_set *,
206 int cygwin_gethostname (char *__name, size_t __len);
208 int kill_pgrp (pid_t, int);
209 int _kill (int, int);
210 int _raise (int sig);
212 extern DWORD binmode;
213 extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
214 extern void (*__CTOR_LIST__) (void);
215 extern void (*__DTOR_LIST__) (void);
216 extern SYSTEM_INFO system_info;
219 /*************************** Unsorted ******************************/
221 #define WM_ASYNCIO 0x8000 // WM_APP
223 /* Note that MAX_PATH is defined in the windows headers */
224 /* There is also PATH_MAX and MAXPATHLEN.
225 PATH_MAX is from Posix and does *not* include the trailing NUL.
226 MAXPATHLEN is from Unix.
228 Thou shalt use MAX_PATH throughout. It avoids the NUL vs no-NUL
229 issue and is neither of the Unixy ones [so we can punt on which
230 one is the right one to use]. */
232 #define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
233 #define STD_WBITS (S_IWUSR)
234 #define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
236 #define O_NOSYMLINK 0x080000
237 #define O_DIROPEN 0x100000
239 /* newlib used to define O_NDELAY differently from O_NONBLOCK. Now it
240 properly defines both to be the same. Unfortunately, we have to
241 behave properly the old version, too, to accomodate older executables. */
242 #define OLD_O_NDELAY 4
244 /* The title on program start. */
245 extern char *old_title;
246 extern BOOL display_title;
248 extern HANDLE hMainThread;
249 extern HANDLE hMainProc;
251 #endif /* defined __cplusplus */