]> sourceware.org Git - newlib-cygwin.git/blame - winsup/cygwin/winsup.h
* cygwin.sc: Add recent changes from ld sources.
[newlib-cygwin.git] / winsup / cygwin / winsup.h
CommitLineData
1fd5e000
CF
1/* winsup.h: main Cygwin header file.
2
33ad2bf9 3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
1fd5e000
CF
4
5This file is part of Cygwin.
6
7This software is a copyrighted work licensed under the terms of the
8Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9details. */
10
11#ifdef HAVE_CONFIG_H
12# include "config.h"
13#endif
14
15#define __INSIDE_CYGWIN__
16
1fd5e000 17#define strlen __builtin_strlen
ac944e37 18#define strcmp __builtin_strcmp
1fd5e000
CF
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
60b68f0d 26#define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
0a047e8f 27
95a8465b
CF
28#ifdef __cplusplus
29
a5a965ff
CF
30#if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
31#define NEW_MACRO_VARARGS
32#endif
33
1fd5e000
CF
34#include <sys/types.h>
35#include <sys/strace.h>
1fd5e000 36
57c89867 37extern const char case_folded_lower[];
2556e737 38#define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
57c89867 39extern const char case_folded_upper[];
2556e737
DD
40#define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
41
8db71e01 42#ifndef MALLOC_DEBUG
8dec7b03 43#define cfree newlib_cfree_dont_use
8db71e01 44#endif
8dec7b03 45
d0b178fe
DD
46#define WIN32_LEAN_AND_MEAN 1
47#define _WINGDI_H
48#define _WINUSER_H
49#define _WINNLS_H
50#define _WINVER_H
51#define _WINNETWK_H
52#define _WINSVC_H
1fd5e000 53#include <windows.h>
1c0c369b 54#include <wincrypt.h>
17db1105 55#include <lmcons.h>
d0b178fe
DD
56#undef _WINGDI_H
57#undef _WINUSER_H
58#undef _WINNLS_H
59#undef _WINVER_H
60#undef _WINNETWK_H
61#undef _WINSVC_H
62
ba946828
CV
63#include "wincap.h"
64
d0b178fe
DD
65/* The one function we use from winuser.h most of the time */
66extern "C" DWORD WINAPI GetLastError (void);
1fd5e000 67
ee1d77e4
CF
68enum codepage_type {ansi_cp, oem_cp};
69extern codepage_type current_codepage;
70
f449bfef
RC
71extern int cygserver_running;
72
1fd5e000
CF
73/* Used to check if Cygwin DLL is dynamically loaded. */
74extern int dynamically_loaded;
75
9fb628fc 76#define sys_wcstombs(tgt,src,len) \
ee1d77e4 77 WideCharToMultiByte((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len),NULL,NULL)
9fb628fc 78#define sys_mbstowcs(tgt,src,len) \
ee1d77e4 79 MultiByteToWideChar((current_codepage==ansi_cp?CP_ACP:CP_OEMCP),0,(src),-1,(tgt),(len))
9fb628fc 80
1fd5e000 81#define TITLESIZE 1024
0c4d2abd 82
1fd5e000
CF
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))
92
1fd5e000 93#include "debug.h"
1fd5e000
CF
94
95/* Events/mutexes */
1fd5e000
CF
96extern HANDLE title_mutex;
97
1fd5e000
CF
98/**************************** Convenience ******************************/
99
1fd5e000
CF
100/* Used when treating / and \ as equivalent. */
101#define SLASH_P(ch) \
102 ({ \
103 char __c = (ch); \
104 ((__c) == '/' || (__c) == '\\'); \
105 })
106
107/* Convert a signal to a signal mask */
108#define SIGTOMASK(sig) (1<<((sig) - signal_shift_subtract))
109extern unsigned int signal_shift_subtract;
110
a5a965ff
CF
111#ifdef NEW_MACRO_VARARGS
112# define api_fatal(...) __api_fatal ("%P: *** " __VA_ARGS__)
113#else
114# define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
115#endif
1fd5e000
CF
116
117#undef issep
118#define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
119
120#define isdirsep SLASH_P
121#define isabspath(p) \
42867d69 122 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
1fd5e000
CF
123
124/******************** Initialization/Termination **********************/
125
f0338f54 126class per_process;
1fd5e000 127/* cygwin .dll initialization */
82c8d7ef 128void dll_crt0 (per_process *) __asm__ ("_dll_crt0__FP11per_process");
44cac411 129extern "C" void __stdcall _dll_crt0 ();
1fd5e000
CF
130
131/* dynamically loaded dll initialization */
f0338f54 132extern "C" int dll_dllcrt0 (HMODULE, per_process *);
1fd5e000
CF
133
134/* dynamically loaded dll initialization for non-cygwin apps */
135extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
136
137/* exit the program */
138extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn));
139
1fd5e000
CF
140/* UID/GID */
141void uinfo_init (void);
142
a8d7ae61
CV
143#define ILLEGAL_UID16 ((__uid16_t)-1)
144#define ILLEGAL_UID ((__uid32_t)-1)
145#define ILLEGAL_GID16 ((__gid16_t)-1)
57196405 146#define ILLEGAL_GID ((__gid32_t)-1)
acb56175 147#define ILLEGAL_SEEK ((__off64_t)-1)
de4e0d30 148
a8d7ae61
CV
149#define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
150#define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
151
152extern "C" __uid32_t getuid32 (void);
153extern "C" __uid32_t geteuid32 (void);
154extern "C" struct passwd *getpwuid32 (__uid32_t);
155
1fd5e000
CF
156/* various events */
157void events_init (void);
158void events_terminate (void);
159
160void __stdcall close_all_files (void);
611d92e2 161BOOL __stdcall check_pty_fds (void);
1fd5e000 162
1fd5e000
CF
163/* Invisible window initialization/termination. */
164HWND __stdcall gethwnd (void);
165void __stdcall window_terminate (void);
166
167/* Globals that handle initialization of winsock in a child process. */
168extern HANDLE wsock32_handle;
afd5033d 169extern HANDLE ws2_32_handle;
1fd5e000
CF
170
171/* Globals that handle initialization of netapi in a child process. */
172extern HANDLE netapi32_handle;
173
174/* debug_on_trap support. see exceptions.cc:try_to_debug() */
175extern "C" void error_start_init (const char*);
8abeff1e 176extern "C" int try_to_debug (bool waitloop = 1);
1fd5e000 177
4c15b7ab
ED
178void set_file_api_mode (codepage_type);
179
2eb392bd
CF
180extern int cygwin_finished_initializing;
181
1fd5e000
CF
182/**************************** Miscellaneous ******************************/
183
1fd5e000
CF
184void __stdcall set_std_handle (int);
185int __stdcall writable_directory (const char *file);
acb56175 186int __stdcall stat_dev (DWORD, int, unsigned long, struct __stat64 *);
1fd5e000
CF
187extern BOOL allow_ntsec;
188
166b2571
CF
189unsigned long __stdcall hash_path_name (unsigned long hash, const char *name) __attribute__ ((regparm(2)));
190void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
191extern "C" char *__stdcall rootdir (char *full_path) __attribute__ ((regparm(1)));
1fd5e000 192
1fd5e000 193/* String manipulation */
166b2571
CF
194extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c);
195extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribute__ ((regparm(2)));
196extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3)));
197extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2)));
1fd5e000
CF
198
199/* Time related */
200void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag);
201long __stdcall to_time_t (FILETIME * ptr);
c4e6ff48
CV
202void __stdcall to_timestruc_t (FILETIME * ptr, timestruc_t * out);
203void __stdcall time_as_timestruc_t (timestruc_t * out);
1fd5e000 204
1fd5e000 205void __stdcall set_console_title (char *);
c0a8e8d0 206void early_stuff_init ();
1fd5e000 207
b0fa0e6e 208int __stdcall check_null_str (const char *name) __attribute__ ((regparm(1)));
7a4078ee
CF
209int __stdcall check_null_empty_str (const char *name) __attribute__ ((regparm(1)));
210int __stdcall check_null_empty_str_errno (const char *name) __attribute__ ((regparm(1)));
5a64d869 211int __stdcall check_null_str_errno (const char *name) __attribute__ ((regparm(1)));
6fdd2131
CF
212int __stdcall __check_null_invalid_struct (const void *s, unsigned sz) __attribute__ ((regparm(2)));
213int __stdcall __check_null_invalid_struct_errno (const void *s, unsigned sz) __attribute__ ((regparm(2)));
214int __stdcall __check_invalid_read_ptr_errno (const void *s, unsigned sz) __attribute__ ((regparm(2)));
7a4078ee
CF
215
216#define check_null_invalid_struct(s) \
f38ac9b7 217 __check_null_invalid_struct ((s), sizeof (*(s)))
7a4078ee
CF
218#define check_null_invalid_struct_errno(s) \
219 __check_null_invalid_struct_errno ((s), sizeof (*(s)))
220
829425c9 221#define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
c90e420d 222void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2)));
1fd5e000 223
0a047e8f
CF
224extern bool wsock_started;
225
f0338f54
CF
226/* Printf type functions */
227extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
c90e420d
CF
228extern "C" int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/;
229extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/;
77f4a250 230extern void multiple_cygwin_problem (const char *, unsigned, unsigned);
f0338f54 231
e2ea684e
CF
232extern "C" void __malloc_lock (struct _reent *);
233extern "C" void __malloc_unlock (struct _reent *);
234
32fb80db 235class path_conv;
acb56175 236int __stdcall stat_worker (const char *name, struct __stat64 *buf, int nofollow,
32fb80db
CF
237 path_conv *pc = NULL) __attribute__ ((regparm (3)));
238
1fd5e000
CF
239/**************************** Exports ******************************/
240
241extern "C" {
242int cygwin_select (int , fd_set *, fd_set *, fd_set *,
243 struct timeval *to);
244int cygwin_gethostname (char *__name, size_t __len);
245
246int kill_pgrp (pid_t, int);
247int _kill (int, int);
248int _raise (int sig);
249
53211514 250extern DWORD binmode;
1fd5e000
CF
251extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
252extern void (*__CTOR_LIST__) (void);
253extern void (*__DTOR_LIST__) (void);
2a6fc028 254extern SYSTEM_INFO system_info;
1fd5e000
CF
255};
256
257/*************************** Unsorted ******************************/
258
1fd5e000
CF
259#define WM_ASYNCIO 0x8000 // WM_APP
260
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.
265
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]. */
269
0cda2f46
CF
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)
291be307
CF
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)
1fd5e000 276
1fd5e000
CF
277/* The title on program start. */
278extern char *old_title;
279extern BOOL display_title;
280
f0338f54
CF
281extern HANDLE hMainThread;
282extern HANDLE hMainProc;
283
57013c31
CF
284extern bool cygwin_testing;
285extern unsigned _cygwin_testing_magic;
286extern HMODULE cygwin_hmodule;
287
0476bae5
CF
288#define winsock2_active (wsadata.wVersion >= 512)
289#define winsock_active (wsadata.wVersion < 512)
290extern struct WSAData wsadata;
291
4c8d72de 292#endif /* defined __cplusplus */
This page took 0.152594 seconds and 5 git commands to generate.