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