]> sourceware.org Git - newlib-cygwin.git/blame - winsup/cygwin/winsup.h
revert previous not-ready-for-primetime checkin.
[newlib-cygwin.git] / winsup / cygwin / winsup.h
CommitLineData
1fd5e000
CF
1/* winsup.h: main Cygwin header file.
2
cec48792 3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 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
2d1d1eb1
CF
11#ifdef DEBUGIT
12#define spf(a, b, c) small_printf (a, b, c)
13#else
14#define spf(a, b, c) do {} while (0)
15#endif
16
1fd5e000
CF
17#ifdef HAVE_CONFIG_H
18# include "config.h"
19#endif
20
21#define __INSIDE_CYGWIN__
22
1fd5e000 23#define strlen __builtin_strlen
ac944e37 24#define strcmp __builtin_strcmp
1fd5e000
CF
25#define strcpy __builtin_strcpy
26#define memcpy __builtin_memcpy
27#define memcmp __builtin_memcmp
28#ifdef HAVE_BUILTIN_MEMSET
29# define memset __builtin_memset
30#endif
31
60b68f0d 32#define NO_COPY __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy")))
066ca06f 33#define NO_COPY_INIT __attribute__((section(".data_cygwin_nocopy")))
0a047e8f 34
a5a965ff
CF
35#if !defined(__STDC_VERSION__) || __STDC_VERSION__ >= 199900L
36#define NEW_MACRO_VARARGS
37#endif
38
9d1e72a1 39#ifndef _WIN32_WINNT
5c0469b4 40#define _WIN32_WINNT 0x0500
4898f75e 41#endif
5c0469b4 42
1fd5e000
CF
43#include <sys/types.h>
44#include <sys/strace.h>
1fd5e000 45
932a40e8 46/* Declarations for functions used in C and C++ code. */
b1aae492
CV
47#ifdef __cplusplus
48extern "C" {
49#endif
50extern __uid32_t getuid32 (void);
51extern __uid32_t geteuid32 (void);
932a40e8 52extern int seteuid32 (__uid32_t);
b1aae492
CV
53extern __gid32_t getegid32 (void);
54extern struct passwd *getpwuid32 (__uid32_t);
932a40e8
CV
55extern struct passwd *getpwnam (const char *);
56extern struct __sFILE64 *fopen64 (const char *, const char *);
57extern struct hostent *cygwin_gethostbyname (const char *name);
58extern unsigned long cygwin_inet_addr (const char *cp);
59
b1aae492
CV
60#ifdef __cplusplus
61}
62#endif
63
95d02d5b
RC
64/* Note that MAX_PATH is defined in the windows headers */
65/* There is also PATH_MAX and MAXPATHLEN.
66 PATH_MAX is from Posix and does *not* include the trailing NUL.
67 MAXPATHLEN is from Unix.
68
69 Thou shalt use CYG_MAX_PATH throughout. It avoids the NUL vs no-NUL
70 issue and is neither of the Unixy ones [so we can punt on which
71 one is the right one to use].
72
73 Windows ANSI calls are limited to MAX_PATH in length. Cygwin calls that
74 thunk through to Windows Wide calls are limited to 32K. We define
75 CYG_MAX_PATH as a convenient, not to short, not too long 'happy medium'.
76
77 */
78
79#define CYG_MAX_PATH (MAX_PATH)
80
b1aae492
CV
81#ifdef __cplusplus
82
57c89867 83extern const char case_folded_lower[];
2556e737 84#define cyg_tolower(c) (case_folded_lower[(unsigned char)(c)])
57c89867 85extern const char case_folded_upper[];
2556e737
DD
86#define cyg_toupper(c) (case_folded_upper[(unsigned char)(c)])
87
8db71e01 88#ifndef MALLOC_DEBUG
8dec7b03 89#define cfree newlib_cfree_dont_use
8db71e01 90#endif
8dec7b03 91
d0b178fe
DD
92#define WIN32_LEAN_AND_MEAN 1
93#define _WINGDI_H
94#define _WINUSER_H
95#define _WINNLS_H
96#define _WINVER_H
97#define _WINNETWK_H
98#define _WINSVC_H
1fd5e000 99#include <windows.h>
1c0c369b 100#include <wincrypt.h>
17db1105 101#include <lmcons.h>
d0b178fe
DD
102#undef _WINGDI_H
103#undef _WINUSER_H
104#undef _WINNLS_H
105#undef _WINVER_H
106#undef _WINNETWK_H
107#undef _WINSVC_H
108
ba946828
CV
109#include "wincap.h"
110
d0b178fe
DD
111/* The one function we use from winuser.h most of the time */
112extern "C" DWORD WINAPI GetLastError (void);
1fd5e000 113
ee1d77e4
CF
114enum codepage_type {ansi_cp, oem_cp};
115extern codepage_type current_codepage;
116
f279e522
CF
117UINT get_cp ();
118
119int __stdcall sys_wcstombs(char *, const WCHAR *, int)
120 __attribute__ ((regparm(3)));
121
122int __stdcall sys_mbstowcs(WCHAR *, const char *, int)
123 __attribute__ ((regparm(3)));
f449bfef 124
1fd5e000
CF
125/* Used to check if Cygwin DLL is dynamically loaded. */
126extern int dynamically_loaded;
127
f279e522 128extern int cygserver_running;
9fb628fc 129
3872e9a4
CF
130#define _MT_SAFE // DELTEME someday
131
1fd5e000 132#define TITLESIZE 1024
0c4d2abd 133
1fd5e000 134#include "debug.h"
1fd5e000
CF
135
136/* Events/mutexes */
1fd5e000
CF
137extern HANDLE title_mutex;
138
1fd5e000
CF
139/**************************** Convenience ******************************/
140
825b3882
CV
141/* Used to define status flag accessor methods */
142#define IMPLEMENT_STATUS_FLAG(type,flag) \
143 void flag (type val) { status.flag = (val); } \
144 type flag () const { return (type) status.flag; }
145
1fd5e000 146/* Used when treating / and \ as equivalent. */
85ba109d 147#define isdirsep(ch) \
1fd5e000
CF
148 ({ \
149 char __c = (ch); \
150 ((__c) == '/' || (__c) == '\\'); \
151 })
152
153/* Convert a signal to a signal mask */
2d1d1eb1 154#define SIGTOMASK(sig) (1 << ((sig) - signal_shift_subtract))
1fd5e000
CF
155extern unsigned int signal_shift_subtract;
156
a5a965ff 157#ifdef NEW_MACRO_VARARGS
2d1d1eb1 158# define api_fatal(...) __api_fatal (__VA_ARGS__)
a5a965ff
CF
159#else
160# define api_fatal(fmt, args...) __api_fatal ("%P: *** " fmt,## args)
161#endif
1fd5e000
CF
162
163#undef issep
164#define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
165
1fd5e000 166#define isabspath(p) \
42867d69 167 (isdirsep (*(p)) || (isalpha (*(p)) && (p)[1] == ':' && (!(p)[2] || isdirsep ((p)[2]))))
1fd5e000
CF
168
169/******************** Initialization/Termination **********************/
170
f0338f54 171class per_process;
1fd5e000 172/* cygwin .dll initialization */
82c8d7ef 173void dll_crt0 (per_process *) __asm__ ("_dll_crt0__FP11per_process");
44cac411 174extern "C" void __stdcall _dll_crt0 ();
1fd5e000
CF
175
176/* dynamically loaded dll initialization */
f0338f54 177extern "C" int dll_dllcrt0 (HMODULE, per_process *);
1fd5e000
CF
178
179/* dynamically loaded dll initialization for non-cygwin apps */
180extern "C" int dll_noncygwin_dllcrt0 (HMODULE, per_process *);
181
182/* exit the program */
3400b4fc
CF
183
184enum exit_states
185 {
186 ES_NOT_EXITING = 0,
187 ES_EVENTS_TERMINATE,
188 ES_THREADTERM,
189 ES_SIGNAL,
190 ES_CLOSEALL,
191 ES_SIGPROCTERMINATE,
192 ES_TITLE,
193 ES_HUP_PGRP,
194 ES_HUP_SID,
edc4f86a
CF
195 ES_TTY_TERMINATE,
196 ES_FINAL
3400b4fc
CF
197 };
198
199extern exit_states exit_state;
200void __stdcall do_exit (int) __attribute__ ((regparm (1), noreturn));
1fd5e000 201
1fd5e000
CF
202/* UID/GID */
203void uinfo_init (void);
204
a8d7ae61
CV
205#define ILLEGAL_UID16 ((__uid16_t)-1)
206#define ILLEGAL_UID ((__uid32_t)-1)
207#define ILLEGAL_GID16 ((__gid16_t)-1)
57196405 208#define ILLEGAL_GID ((__gid32_t)-1)
1727fba0 209#define ILLEGAL_SEEK ((_off64_t)-1)
de4e0d30 210
a8d7ae61
CV
211#define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
212#define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
213
1fd5e000
CF
214/* various events */
215void events_init (void);
216void events_terminate (void);
217
f6936c48 218void __stdcall close_all_files ();
1fd5e000 219
aafd8a54
CF
220/* Invisible window initialization/termination. */
221HWND __stdcall gethwnd (void);
db3137cc
CV
222/* Check if running in a visible window station. */
223extern bool has_visible_window_station (void);
1fd5e000
CF
224
225/* Globals that handle initialization of winsock in a child process. */
226extern HANDLE wsock32_handle;
afd5033d 227extern HANDLE ws2_32_handle;
1fd5e000
CF
228
229/* Globals that handle initialization of netapi in a child process. */
230extern HANDLE netapi32_handle;
231
232/* debug_on_trap support. see exceptions.cc:try_to_debug() */
233extern "C" void error_start_init (const char*);
8abeff1e 234extern "C" int try_to_debug (bool waitloop = 1);
1fd5e000 235
4c15b7ab
ED
236void set_file_api_mode (codepage_type);
237
e431827c 238extern bool cygwin_finished_initializing;
2eb392bd 239
1fd5e000
CF
240/**************************** Miscellaneous ******************************/
241
1fd5e000 242void __stdcall set_std_handle (int);
acb56175 243int __stdcall stat_dev (DWORD, int, unsigned long, struct __stat64 *);
1fd5e000 244
cc95baad 245__ino64_t __stdcall hash_path_name (__ino64_t hash, const char *name) __attribute__ ((regparm(2)));
166b2571 246void __stdcall nofinalslash (const char *src, char *dst) __attribute__ ((regparm(2)));
7224437c 247extern "C" char *__stdcall rootdir (const char *full_path, char *root_path) __attribute__ ((regparm(2)));
1fd5e000 248
1fd5e000 249/* String manipulation */
166b2571
CF
250extern "C" char *__stdcall strccpy (char *s1, const char **s2, char c);
251extern "C" int __stdcall strcasematch (const char *s1, const char *s2) __attribute__ ((regparm(2)));
252extern "C" int __stdcall strncasematch (const char *s1, const char *s2, size_t n) __attribute__ ((regparm(3)));
253extern "C" char *__stdcall strcasestr (const char *searchee, const char *lookfor) __attribute__ ((regparm(2)));
1fd5e000
CF
254
255/* Time related */
256void __stdcall totimeval (struct timeval *dst, FILETIME * src, int sub, int flag);
257long __stdcall to_time_t (FILETIME * ptr);
c4e6ff48
CV
258void __stdcall to_timestruc_t (FILETIME * ptr, timestruc_t * out);
259void __stdcall time_as_timestruc_t (timestruc_t * out);
1fd5e000 260
1fd5e000 261void __stdcall set_console_title (char *);
fb3dd716
CF
262void init_console_handler ();
263void init_global_security ();
1fd5e000 264
b0fa0e6e 265int __stdcall check_null_str (const char *name) __attribute__ ((regparm(1)));
7a4078ee
CF
266int __stdcall check_null_empty_str (const char *name) __attribute__ ((regparm(1)));
267int __stdcall check_null_empty_str_errno (const char *name) __attribute__ ((regparm(1)));
5a64d869 268int __stdcall check_null_str_errno (const char *name) __attribute__ ((regparm(1)));
b4f06520
CS
269int __stdcall __check_null_invalid_struct (void *s, unsigned sz) __attribute__ ((regparm(2)));
270int __stdcall __check_null_invalid_struct_errno (void *s, unsigned sz) __attribute__ ((regparm(2)));
d845665e 271int __stdcall __check_invalid_read_ptr (const void *s, unsigned sz) __attribute__ ((regparm(2)));
6fdd2131 272int __stdcall __check_invalid_read_ptr_errno (const void *s, unsigned sz) __attribute__ ((regparm(2)));
f9e19c09 273int __stdcall check_invalid_virtual_addr (const void *s, unsigned sz) __attribute__ ((regparm(2)));
7a4078ee
CF
274
275#define check_null_invalid_struct(s) \
f38ac9b7 276 __check_null_invalid_struct ((s), sizeof (*(s)))
7a4078ee
CF
277#define check_null_invalid_struct_errno(s) \
278 __check_null_invalid_struct_errno ((s), sizeof (*(s)))
9a4d574b
CF
279#define check_invalid_read_struct_errno(s) \
280 __check_invalid_read_ptr_errno ((s), sizeof (*(s)))
7a4078ee 281
ab7f9b93
CF
282struct iovec;
283ssize_t check_iovec_for_read (const struct iovec *, int) __attribute__ ((regparm(2)));
284ssize_t check_iovec_for_write (const struct iovec *, int) __attribute__ ((regparm(2)));
285
829425c9 286#define set_winsock_errno() __set_winsock_errno (__FUNCTION__, __LINE__)
c90e420d 287void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2)));
1fd5e000 288
0a047e8f
CF
289extern bool wsock_started;
290
f0338f54
CF
291/* Printf type functions */
292extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
c90e420d
CF
293extern "C" int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/;
294extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/;
77f4a250 295extern void multiple_cygwin_problem (const char *, unsigned, unsigned);
f0338f54 296
7ac61736
CF
297int symlink_worker (const char *, const char *, bool, bool)
298 __attribute__ ((regparm (3)));
299
fad5aef8 300class path_conv;
fad5aef8 301
e2a39e2e
CV
302int fcntl_worker (int fd, int cmd, void *arg);
303
9a4d574b 304extern "C" int low_priority_sleep (DWORD) __attribute__ ((regparm (1)));
13af9a14 305#define SLEEP_0_STAY_LOW INFINITE
32fb80db 306
6ef3b76b
CV
307size_t getshmlba (void);
308
1fd5e000
CF
309/**************************** Exports ******************************/
310
311extern "C" {
312int cygwin_select (int , fd_set *, fd_set *, fd_set *,
313 struct timeval *to);
314int cygwin_gethostname (char *__name, size_t __len);
315
53211514 316extern DWORD binmode;
1fd5e000
CF
317extern char _data_start__, _data_end__, _bss_start__, _bss_end__;
318extern void (*__CTOR_LIST__) (void);
319extern void (*__DTOR_LIST__) (void);
2a6fc028 320extern SYSTEM_INFO system_info;
1fd5e000
CF
321};
322
323/*************************** Unsorted ******************************/
324
1fd5e000
CF
325#define WM_ASYNCIO 0x8000 // WM_APP
326
1fd5e000 327
0cda2f46
CF
328#define STD_RBITS (S_IRUSR | S_IRGRP | S_IROTH)
329#define STD_WBITS (S_IWUSR)
330#define STD_XBITS (S_IXUSR | S_IXGRP | S_IXOTH)
291be307
CF
331#define NO_W ~(S_IWUSR | S_IWGRP | S_IWOTH)
332#define NO_R ~(S_IRUSR | S_IRGRP | S_IROTH)
333#define NO_X ~(S_IXUSR | S_IXGRP | S_IXOTH)
1fd5e000 334
1fd5e000
CF
335/* The title on program start. */
336extern char *old_title;
3872e9a4 337extern bool display_title;
1fd5e000 338
f0338f54
CF
339extern HANDLE hMainThread;
340extern HANDLE hMainProc;
341
57013c31 342extern bool cygwin_testing;
57013c31 343
179cae11
CF
344extern char almost_null[];
345
0476bae5 346#define winsock2_active (wsadata.wVersion >= 512)
0476bae5
CF
347extern struct WSAData wsadata;
348
4c8d72de 349#endif /* defined __cplusplus */
This page took 0.241884 seconds and 5 git commands to generate.