blob: 96d4c8cc6eff956a9bc6b02b7d85e85c749e242f [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 */
8
9/*
Nir Lichtman563e8ec2024-09-30 19:42:28 +020010 * Win32 machine-dependent things.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011 */
12
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010013#include "os_dos.h" // common MS-DOS and Win32 stuff
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010014// cproto fails on missing include files
K.Takata972db232022-02-04 10:45:38 +000015#ifndef PROTO
16# include <direct.h> // for _mkdir()
Bram Moolenaar071d4272004-06-13 20:20:40 +000017#endif
18
19#define BINARY_FILE_IO
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010020#define USE_EXE_NAME // use argv[0] for $VIM
Bram Moolenaar071d4272004-06-13 20:20:40 +000021#define USE_TERM_CONSOLE
22#ifndef HAVE_STRING_H
23# define HAVE_STRING_H
24#endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000025#ifndef HAVE_MATH_H
26# define HAVE_MATH_H
27#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000028#define HAVE_STRCSPN
Bram Moolenaar071d4272004-06-13 20:20:40 +000029#ifndef __GNUC__
30#define HAVE_STRICMP
31#define HAVE_STRNICMP
32#endif
33#ifndef HAVE_STRFTIME
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010034# define HAVE_STRFTIME // guessed
Bram Moolenaar071d4272004-06-13 20:20:40 +000035#endif
36#define HAVE_MEMSET
37#ifndef HAVE_LOCALE_H
38# define HAVE_LOCALE_H 1
39#endif
40#ifndef HAVE_FCNTL_H
41# define HAVE_FCNTL_H
42#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000043#define HAVE_QSORT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010044#define HAVE_ST_MODE // have stat.st_mode
Bram Moolenaar071d4272004-06-13 20:20:40 +000045
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010046#define FEAT_SHORTCUT // resolve shortcuts
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
K.Takatac351dc12022-01-24 11:24:08 +000048// Access Control List (actually security info).
49#define HAVE_ACL
Bram Moolenaar071d4272004-06-13 20:20:40 +000050
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010051#define USE_FNAME_CASE // adjust case of file names
Bram Moolenaara1cb1d12019-10-17 23:00:07 +020052#if !defined(FEAT_CLIPBOARD)
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010053# define FEAT_CLIPBOARD // include clipboard support
Bram Moolenaar071d4272004-06-13 20:20:40 +000054#endif
55#if defined(__DATE__) && defined(__TIME__)
56# define HAVE_DATE_TIME
57#endif
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010058#ifndef FEAT_GUI_MSWIN // GUI works different
59# define BREAKCHECK_SKIP 1 // call mch_breakcheck() each time, it's fast
Bram Moolenaar071d4272004-06-13 20:20:40 +000060#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000061
Bram Moolenaaree273972016-01-02 21:11:51 +010062#define HAVE_TOTAL_MEM
63
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010064#define HAVE_PUTENV // at least Bcc 5.2 and MSC have it
Bram Moolenaar071d4272004-06-13 20:20:40 +000065
Bram Moolenaarafde13b2019-04-28 19:46:49 +020066#if defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)
Dominique Pelleaf4a61a2021-12-27 17:21:41 +000067# define NO_CONSOLE // don't include console-only code
Bram Moolenaar071d4272004-06-13 20:20:40 +000068#endif
69
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010070// toupper() is not really broken, but it's very slow. Probably because of
71// using Unicode characters on Windows NT
Bram Moolenaar071d4272004-06-13 20:20:40 +000072#define BROKEN_TOUPPER
73
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010074#define FNAME_ILLEGAL "\"*?><|" // illegal characters in a file name
Bram Moolenaar071d4272004-06-13 20:20:40 +000075
Bram Moolenaar8e82c052018-08-21 19:47:48 +020076#include <signal.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000077#include <stdlib.h>
78#include <time.h>
Bram Moolenaar914703b2010-05-31 21:59:46 +020079#include <sys/types.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +000080
81#ifndef STRICT
82# define STRICT
83#endif
84#ifndef COBJMACROS
Bram Moolenaar9bf703d2019-11-30 19:44:38 +010085# define COBJMACROS // For OLE: Enable "friendlier" access to objects
Bram Moolenaar071d4272004-06-13 20:20:40 +000086#endif
Bram Moolenaar82881492012-11-20 16:53:39 +010087#ifndef PROTO
Ken Takatac6944912023-10-19 17:22:24 +020088// Must include winsock2.h before windows.h since it conflicts with winsock.h
89// (included in windows.h).
90# include <winsock2.h>
91# include <ws2tcpip.h>
Bram Moolenaar82881492012-11-20 16:53:39 +010092# include <windows.h>
Bram Moolenaare6a16e92022-10-17 14:51:36 +010093
94// Weird: rpcndr.h defines "small" to "char", which causes trouble
95#undef small
96
Bram Moolenaar9d488952013-07-21 17:53:58 +020097# ifndef SM_CXPADDEDBORDER
98# define SM_CXPADDEDBORDER 92
99# endif
Bram Moolenaar82881492012-11-20 16:53:39 +0100100#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101
ichizok378447f2023-05-11 22:25:42 +0100102typedef void (*sighandler_T)(int, int);
103
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104/*
105 * Win32 has plenty of memory, use large buffers
106 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100107#define CMDBUFFSIZE 1024 // size of the command processing buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100109// _MAX_PATH is only 260 (stdlib.h), but we want more for the 'path' option,
110// thus use a larger number.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111#define MAXPATHL 1024
112
113#ifndef BASENAMELEN
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100114# define BASENAMELEN (_MAX_PATH - 5) // length of base of file name
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115#endif
116
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100117#define TEMPNAMELEN _MAX_PATH // length of temp file name path
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118
119#ifndef DFLT_MAXMEM
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100120# define DFLT_MAXMEM (2*1024) // use up to 2 Mbyte for a buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121#endif
122
123#ifndef DFLT_MAXMEMTOT
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100124# define DFLT_MAXMEMTOT (5*1024) // use up to 5 Mbyte for Vim
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125#endif
126
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200127/*
128 * Reparse Point
129 */
130#ifndef FILE_ATTRIBUTE_REPARSE_POINT
131# define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
132#endif
133#ifndef IO_REPARSE_TAG_MOUNT_POINT
134# define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
135#endif
136#ifndef IO_REPARSE_TAG_SYMLINK
137# define IO_REPARSE_TAG_SYMLINK 0xA000000C
138#endif
LemonBoy40fd7e62022-05-05 20:18:16 +0100139#ifndef IO_REPARSE_TAG_APPEXECLINK
140# define IO_REPARSE_TAG_APPEXECLINK 0x8000001B
141#endif
142
143/*
144 * Definition of the reparse point buffer.
145 * This is usually defined in the DDK, copy the definition here to avoid
146 * adding it as a dependence only for a single structure.
147 */
148typedef struct _REPARSE_DATA_BUFFER {
149 ULONG ReparseTag;
150 USHORT ReparseDataLength;
151 USHORT Reserved;
152 union {
153 struct {
154 USHORT SubstituteNameOffset;
155 USHORT SubstituteNameLength;
156 USHORT PrintNameOffset;
157 USHORT PrintNameLength;
158 ULONG Flags;
159 WCHAR PathBuffer[1];
160 } SymbolicLinkReparseBuffer;
161 struct {
162 USHORT SubstituteNameOffset;
163 USHORT SubstituteNameLength;
164 USHORT PrintNameOffset;
165 USHORT PrintNameLength;
166 WCHAR PathBuffer[1];
167 } MountPointReparseBuffer;
168 struct {
169 UCHAR DataBuffer[1];
170 } GenericReparseBuffer;
171 struct
172 {
173 ULONG StringCount;
174 WCHAR StringList[1];
175 } AppExecLinkReparseBuffer;
176 } DUMMYUNIONNAME;
177} REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
Bram Moolenaar2ee95f72013-09-25 19:13:38 +0200178
K.Takatac351dc12022-01-24 11:24:08 +0000179#ifdef _MSC_VER
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100180 // Support for __try / __except. All versions of MSVC are
181 // expected to have this. Any other compilers that support it?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000182# define HAVE_TRY_EXCEPT 1
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100183# include <malloc.h> // for _resetstkoflw()
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184#endif
185
186/*
187 * Some simple debugging macros that look and behave a lot like their
188 * namesakes in MFC.
189 */
190
191#ifdef _DEBUG
192
K.Takatac351dc12022-01-24 11:24:08 +0000193# include <crtdbg.h>
194# define ASSERT(f) _ASSERT(f)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195
Bram Moolenaar071d4272004-06-13 20:20:40 +0000196# define TRACE Trace
197# define TRACE0(sz) Trace(_T("%s"), _T(sz))
198# define TRACE1(sz, p1) Trace(_T(sz), p1)
199# define TRACE2(sz, p1, p2) Trace(_T(sz), p1, p2)
200# define TRACE3(sz, p1, p2, p3) Trace(_T(sz), p1, p2, p3)
201# define TRACE4(sz, p1, p2, p3, p4) Trace(_T(sz), p1, p2, p3, p4)
202
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100203// In debug version, writes trace messages to debug stream
Bram Moolenaar071d4272004-06-13 20:20:40 +0000204void __cdecl
205Trace(char *pszFormat, ...);
206
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100207#else // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000208
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100209 // These macros should all compile away to nothing
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210# define ASSERT(f) ((void)0)
Bram Moolenaar35d7a2f2022-06-09 20:53:54 +0100211# define TRACE 1 ? (void)0 : (void)printf
Bram Moolenaar071d4272004-06-13 20:20:40 +0000212# define TRACE0(sz)
213# define TRACE1(sz, p1)
214# define TRACE2(sz, p1, p2)
215# define TRACE3(sz, p1, p2, p3)
216# define TRACE4(sz, p1, p2, p3, p4)
217
Bram Moolenaar9bf703d2019-11-30 19:44:38 +0100218#endif // !_DEBUG
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219
220
221#define ASSERT_POINTER(p, type) \
222 ASSERT(((p) != NULL) && IsValidAddress((p), sizeof(type), FALSE))
223
224#define ASSERT_NULL_OR_POINTER(p, type) \
225 ASSERT(((p) == NULL) || IsValidAddress((p), sizeof(type), FALSE))
226
Bram Moolenaar7c23d1d2017-02-01 13:14:16 +0100227#ifndef HAVE_SETENV
228# define HAVE_SETENV
229#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230#define mch_getenv(x) (char_u *)getenv((char *)(x))
Bram Moolenaareae1b912019-05-09 15:12:55 +0200231#define vim_mkdir(x, y) mch_mkdir(x)