Merge branch 'vim-with-runtime' into feat/persistent-undo
[vim_extended.git] / src / os_unix.h
blob8c56511835e9dc557aecc72abe13ea24f8e56eac
1 /* vi:set ts=8 sts=4 sw=4:
3 * VIM - Vi IMproved by Bram Moolenaar
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 */
9 /*
10 * NextStep has a problem with configure, undefine a few things:
12 #ifdef NeXT
13 # ifdef HAVE_UTIME
14 # undef HAVE_UTIME
15 # endif
16 # ifdef HAVE_SYS_UTSNAME_H
17 # undef HAVE_SYS_UTSNAME_H
18 # endif
19 #endif
21 #include <stdio.h>
22 #include <ctype.h>
24 #ifdef VAXC
25 # include <types.h>
26 # include <stat.h>
27 #else
28 # include <sys/types.h>
29 # include <sys/stat.h>
30 #endif
32 #ifdef HAVE_STDLIB_H
33 # include <stdlib.h>
34 #endif
36 #ifdef __EMX__
37 # define HAVE_TOTAL_MEM
38 #endif
40 #if defined(__CYGWIN__) || defined(__CYGWIN32__)
41 # define WIN32UNIX /* Compiling for Win32 using Unix files. */
42 # define BINARY_FILE_IO
44 # define CASE_INSENSITIVE_FILENAME
45 # define USE_FNAME_CASE /* Fix filename case differences. */
46 #endif
48 /* On AIX 4.2 there is a conflicting prototype for ioctl() in stropts.h and
49 * unistd.h. This hack should fix that (suggested by Jeff George).
50 * But on AIX 4.3 it's alright (suggested by Jake Hamby). */
51 #if defined(FEAT_GUI) && defined(_AIX) && !defined(_AIX43) && !defined(_NO_PROTO)
52 # define _NO_PROTO
53 #endif
55 #ifdef HAVE_UNISTD_H
56 # include <unistd.h>
57 #endif
59 #ifdef HAVE_LIBC_H
60 # include <libc.h> /* for NeXT */
61 #endif
63 #ifdef HAVE_SYS_PARAM_H
64 # include <sys/param.h> /* defines BSD, if it's a BSD system */
65 #endif
68 * Sun defines FILE on SunOS 4.x.x, Solaris has a typedef for FILE
70 #if defined(sun) && !defined(FILE)
71 # define SOLARIS
72 #endif
75 * Using getcwd() is preferred, because it checks for a buffer overflow.
76 * Don't use getcwd() on systems do use system("sh -c pwd"). There is an
77 * autoconf check for this.
78 * Use getcwd() anyway if getwd() isn't present.
80 #if defined(HAVE_GETCWD) && !(defined(BAD_GETCWD) && defined(HAVE_GETWD))
81 # define USE_GETCWD
82 #endif
84 #ifndef __ARGS
85 /* The AIX VisualAge cc compiler defines __EXTENDED__ instead of __STDC__
86 * because it includes pre-ansi features. */
87 # if defined(__STDC__) || defined(__GNUC__) || defined(__EXTENDED__)
88 # define __ARGS(x) x
89 # else
90 # define __ARGS(x) ()
91 # endif
92 #endif
94 /* always use unlink() to remove files */
95 #ifndef PROTO
96 # ifdef VMS
97 # define mch_remove(x) delete((char *)(x))
98 # define vim_mkdir(x, y) mkdir((char *)(x), y)
99 # ifdef VAX
100 # else
101 # define mch_rmdir(x) rmdir((char *)(x))
102 # endif
103 # else
104 # define vim_mkdir(x, y) mkdir((char *)(x), y)
105 # define mch_rmdir(x) rmdir((char *)(x))
106 # define mch_remove(x) unlink((char *)(x))
107 # endif
108 #endif
110 /* The number of arguments to a signal handler is configured here. */
111 /* It used to be a long list of almost all systems. Any system that doesn't
112 * have an argument??? */
113 #define SIGHASARG
115 /* List 3 arg systems here. I guess __sgi, please test and correct me. jw. */
116 #if defined(__sgi) && defined(HAVE_SIGCONTEXT)
117 # define SIGHAS3ARGS
118 #endif
120 #ifdef SIGHASARG
121 # ifdef SIGHAS3ARGS
122 # define SIGPROTOARG (int, int, struct sigcontext *)
123 # define SIGDEFARG(s) (s, sig2, scont) int s, sig2; struct sigcontext *scont;
124 # define SIGDUMMYARG 0, 0, (struct sigcontext *)0
125 # else
126 # define SIGPROTOARG (int)
127 # define SIGDEFARG(s) (s) int s UNUSED;
128 # define SIGDUMMYARG 0
129 # endif
130 #else
131 # define SIGPROTOARG (void)
132 # define SIGDEFARG(s) ()
133 # define SIGDUMMYARG
134 #endif
136 #ifdef HAVE_DIRENT_H
137 # include <dirent.h>
138 # ifndef NAMLEN
139 # define NAMLEN(dirent) strlen((dirent)->d_name)
140 # endif
141 #else
142 # define dirent direct
143 # define NAMLEN(dirent) (dirent)->d_namlen
144 # if HAVE_SYS_NDIR_H
145 # include <sys/ndir.h>
146 # endif
147 # if HAVE_SYS_DIR_H
148 # include <sys/dir.h>
149 # endif
150 # if HAVE_NDIR_H
151 # include <ndir.h>
152 # endif
153 #endif
155 #if !defined(HAVE_SYS_TIME_H) || defined(TIME_WITH_SYS_TIME)
156 # include <time.h> /* on some systems time.h should not be
157 included together with sys/time.h */
158 #endif
159 #ifdef HAVE_SYS_TIME_H
160 # include <sys/time.h>
161 #endif
163 #include <signal.h>
165 #if defined(DIRSIZ) && !defined(MAXNAMLEN)
166 # define MAXNAMLEN DIRSIZ
167 #endif
169 #if defined(UFS_MAXNAMLEN) && !defined(MAXNAMLEN)
170 # define MAXNAMLEN UFS_MAXNAMLEN /* for dynix/ptx */
171 #endif
173 #if defined(NAME_MAX) && !defined(MAXNAMLEN)
174 # define MAXNAMLEN NAME_MAX /* for Linux before .99p3 */
175 #endif
178 * Note: if MAXNAMLEN has the wrong value, you will get error messages
179 * for not being able to open the swap file.
181 #if !defined(MAXNAMLEN)
182 # define MAXNAMLEN 512 /* for all other Unix */
183 #endif
185 #define BASENAMELEN (MAXNAMLEN - 5)
187 #ifdef HAVE_ERRNO_H
188 # include <errno.h>
189 #endif
191 #ifdef HAVE_PWD_H
192 # include <pwd.h>
193 #endif
195 #ifdef __COHERENT__
196 # undef __ARGS
197 #endif
199 #if (defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)) \
200 || (defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)) \
201 || defined(HAVE_SYSCTL) || defined(HAVE_SYSCONF)
202 # define HAVE_TOTAL_MEM
203 #endif
205 #ifdef VMS
206 # include <unixio.h>
207 # include <unixlib.h>
208 # include <signal.h>
209 # include <file.h>
210 # include <ssdef.h>
211 # include <descrip.h>
212 # include <libclidef.h>
213 # include <lnmdef.h>
214 # include <psldef.h>
215 # include <prvdef.h>
216 # include <dvidef.h>
217 # include <dcdef.h>
218 # include <stsdef.h>
219 # include <iodef.h>
220 # include <ttdef.h>
221 # include <tt2def.h>
222 # include <jpidef.h>
223 # include <rms.h>
224 # include <trmdef.h>
225 # include <string.h>
226 # include <starlet.h>
227 # include <socket.h>
228 # include <lib$routines.h>
230 # ifdef FEAT_GUI_GTK
231 # include "gui_gtk_vms.h"
232 # endif
234 typedef struct dsc$descriptor DESC;
235 #endif
238 * Unix system-dependent file names
240 #ifndef SYS_VIMRC_FILE
241 # define SYS_VIMRC_FILE "$VIM/vimrc"
242 #endif
243 #ifndef SYS_GVIMRC_FILE
244 # define SYS_GVIMRC_FILE "$VIM/gvimrc"
245 #endif
246 #ifndef DFLT_HELPFILE
247 # define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt"
248 #endif
249 #ifndef FILETYPE_FILE
250 # define FILETYPE_FILE "filetype.vim"
251 #endif
252 #ifndef FTPLUGIN_FILE
253 # define FTPLUGIN_FILE "ftplugin.vim"
254 #endif
255 #ifndef INDENT_FILE
256 # define INDENT_FILE "indent.vim"
257 #endif
258 #ifndef FTOFF_FILE
259 # define FTOFF_FILE "ftoff.vim"
260 #endif
261 #ifndef FTPLUGOF_FILE
262 # define FTPLUGOF_FILE "ftplugof.vim"
263 #endif
264 #ifndef INDOFF_FILE
265 # define INDOFF_FILE "indoff.vim"
266 #endif
267 #ifndef SYS_MENU_FILE
268 # define SYS_MENU_FILE "$VIMRUNTIME/menu.vim"
269 #endif
271 #ifndef USR_EXRC_FILE
272 # ifdef VMS
273 # define USR_EXRC_FILE "sys$login:.exrc"
274 # else
275 # define USR_EXRC_FILE "$HOME/.exrc"
276 # endif
277 #endif
279 #if !defined(USR_EXRC_FILE2) && defined(OS2)
280 # define USR_EXRC_FILE2 "$VIM/.exrc"
281 #endif
282 #if !defined(USR_EXRC_FILE2) && defined(VMS)
283 # define USR_EXRC_FILE2 "sys$login:_exrc"
284 #endif
286 #ifndef USR_VIMRC_FILE
287 # ifdef VMS
288 # define USR_VIMRC_FILE "sys$login:.vimrc"
289 # else
290 # define USR_VIMRC_FILE "$HOME/.vimrc"
291 # endif
292 #endif
294 #if !defined(USR_VIMRC_FILE2) && defined(OS2)
295 # define USR_VIMRC_FILE2 "$VIM/.vimrc"
296 #endif
297 #if !defined(USR_VIMRC_FILE2) && defined(VMS)
298 # define USR_VIMRC_FILE2 "sys$login:_vimrc"
299 #endif
301 #ifndef USR_GVIMRC_FILE
302 # ifdef VMS
303 # define USR_GVIMRC_FILE "sys$login:.gvimrc"
304 # else
305 # define USR_GVIMRC_FILE "$HOME/.gvimrc"
306 # endif
307 #endif
309 #ifdef VMS
310 # ifndef USR_GVIMRC_FILE2
311 # define USR_GVIMRC_FILE2 "sys$login:_gvimrc"
312 # endif
313 #endif
315 #ifndef EVIM_FILE
316 # define EVIM_FILE "$VIMRUNTIME/evim.vim"
317 #endif
319 #ifdef FEAT_VIMINFO
320 # ifndef VIMINFO_FILE
321 # ifdef VMS
322 # define VIMINFO_FILE "sys$login:.viminfo"
323 # else
324 # define VIMINFO_FILE "$HOME/.viminfo"
325 # endif
326 # endif
327 # if !defined(VIMINFO_FILE2) && defined(OS2)
328 # define VIMINFO_FILE2 "$VIM/.viminfo"
329 # endif
330 # if !defined(VIMINFO_FILE2) && defined(VMS)
331 # define VIMINFO_FILE2 "sys$login:_viminfo"
332 # endif
333 #endif
335 #ifndef EXRC_FILE
336 # define EXRC_FILE ".exrc"
337 #endif
339 #ifndef VIMRC_FILE
340 # define VIMRC_FILE ".vimrc"
341 #endif
343 #ifdef FEAT_GUI
344 # ifndef GVIMRC_FILE
345 # define GVIMRC_FILE ".gvimrc"
346 # endif
347 #endif
349 #ifndef SYNTAX_FNAME
350 # define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim"
351 #endif
353 #ifndef DFLT_BDIR
354 # ifdef OS2
355 # define DFLT_BDIR ".,c:/tmp,~/tmp,~/"
356 # else
357 # ifdef VMS
358 # define DFLT_BDIR "./,sys$login:,tmp:"
359 # else
360 # define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */
361 # endif
362 # endif
363 #endif
365 #ifndef DFLT_UDIR
366 # ifdef OS2
367 # define DFLT_UDIR "$HOME/vimfiles/undo"
368 # else
369 # ifdef VMS
370 # define DFLT_UDIR "$HOME/vimfiles/undo"
371 # else
372 # define DFLT_UDIR "$HOME/.vim/undo" /* default for 'undodir' */
373 # endif
374 # endif
375 #endif
377 #ifndef DFLT_DIR
378 # ifdef OS2
379 # define DFLT_DIR ".,~/tmp,c:/tmp,/tmp"
380 # else
381 # ifdef VMS
382 # define DFLT_DIR "./,sys$login:,tmp:"
383 # else
384 # define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */
385 # endif
386 # endif
387 #endif
389 #ifndef DFLT_VDIR
390 # ifdef OS2
391 # define DFLT_VDIR "$VIM/vimfiles/view"
392 # else
393 # ifdef VMS
394 # define DFLT_VDIR "sys$login:vimfiles/view"
395 # else
396 # define DFLT_VDIR "$HOME/.vim/view" /* default for 'viewdir' */
397 # endif
398 # endif
399 #endif
401 #define DFLT_ERRORFILE "errors.err"
403 #ifdef OS2
404 # define DFLT_RUNTIMEPATH "$HOME/vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/vimfiles/after"
405 #else
406 # ifdef VMS
407 # define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after"
408 # else
409 # ifdef RUNTIME_GLOBAL
410 # define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after"
411 # else
412 # define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after"
413 # endif
414 # endif
415 #endif
417 #ifdef OS2
419 * Try several directories to put the temp files.
421 # define TEMPDIRNAMES "$TMP", "$TEMP", "c:\\TMP", "c:\\TEMP", ""
422 # define TEMPNAMELEN 128
423 #else
424 # ifdef VMS
425 # ifndef VAX
426 # define VMS_TEMPNAM /* to fix default .LIS extension */
427 # endif
428 # define TEMPNAME "TMP:v?XXXXXX.txt"
429 # define TEMPNAMELEN 28
430 # else
431 # define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME"
432 # define TEMPNAMELEN 256
433 # endif
434 #endif
436 /* Special wildcards that need to be handled by the shell */
437 #define SPECIAL_WILDCHAR "`'{"
439 #ifndef HAVE_OPENDIR
440 # define NO_EXPANDPATH
441 #endif
444 * Unix has plenty of memory, use large buffers
446 #define CMDBUFFSIZE 1024 /* size of the command processing buffer */
448 /* Use the system path length if it makes sense. */
449 #if defined(PATH_MAX) && (PATH_MAX > 1000)
450 # define MAXPATHL PATH_MAX
451 #else
452 # define MAXPATHL 1024
453 #endif
455 #define CHECK_INODE /* used when checking if a swap file already
456 exists for a file */
457 #ifdef VMS /* Use less memory because of older systems */
458 # ifndef DFLT_MAXMEM
459 # define DFLT_MAXMEM (2*1024)
460 # endif
461 # ifndef DFLT_MAXMEMTOT
462 # define DFLT_MAXMEMTOT (5*1024)
463 # endif
464 #else
465 # ifndef DFLT_MAXMEM
466 # define DFLT_MAXMEM (5*1024) /* use up to 5 Mbyte for a buffer */
467 # endif
468 # ifndef DFLT_MAXMEMTOT
469 # define DFLT_MAXMEMTOT (10*1024) /* use up to 10 Mbyte for Vim */
470 # endif
471 #endif
473 /* memmove is not present on all systems, use memmove, bcopy, memcpy or our
474 * own version */
475 /* Some systems have (void *) arguments, some (char *). If we use (char *) it
476 * works for all */
477 #ifdef USEMEMMOVE
478 # define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len)
479 #else
480 # ifdef USEBCOPY
481 # define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len)
482 # else
483 # ifdef USEMEMCPY
484 # define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len)
485 # else
486 # define VIM_MEMMOVE /* found in misc2.c */
487 # endif
488 # endif
489 #endif
491 #ifndef PROTO
492 # ifdef HAVE_RENAME
493 # define mch_rename(src, dst) rename(src, dst)
494 # else
495 int mch_rename __ARGS((const char *src, const char *dest));
496 # endif
497 # ifndef VMS
498 # ifdef __MVS__
499 /* on OS390 Unix getenv() doesn't return a pointer to persistent
500 * storage -> use __getenv() */
501 # define mch_getenv(x) (char_u *)__getenv((char *)(x))
502 # else
503 # define mch_getenv(x) (char_u *)getenv((char *)(x))
504 # endif
505 # define mch_setenv(name, val, x) setenv(name, val, x)
506 # endif
507 #endif
509 #if !defined(S_ISDIR) && defined(S_IFDIR)
510 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
511 #endif
512 #if !defined(S_ISREG) && defined(S_IFREG)
513 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
514 #endif
515 #if !defined(S_ISBLK) && defined(S_IFBLK)
516 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
517 #endif
518 #if !defined(S_ISSOCK) && defined(S_IFSOCK)
519 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
520 #endif
521 #if !defined(S_ISFIFO) && defined(S_IFIFO)
522 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
523 #endif
524 #if !defined(S_ISCHR) && defined(S_IFCHR)
525 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
526 #endif
528 /* Note: Some systems need both string.h and strings.h (Savage). However,
529 * some systems can't handle both, only use string.h in that case. */
530 #ifdef HAVE_STRING_H
531 # include <string.h>
532 #endif
533 #if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H)
534 # include <strings.h>
535 #endif
537 #if defined(HAVE_SETJMP_H)
538 # include <setjmp.h>
539 # ifdef HAVE_SIGSETJMP
540 # define JMP_BUF sigjmp_buf
541 # define SETJMP(x) sigsetjmp((x), 1)
542 # define LONGJMP siglongjmp
543 # else
544 # define JMP_BUF jmp_buf
545 # define SETJMP(x) setjmp(x)
546 # define LONGJMP longjmp
547 # endif
548 #endif
550 #define HAVE_DUP /* have dup() */
551 #define HAVE_ST_MODE /* have stat.st_mode */
553 /* We have three kinds of ACL support. */
554 #define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL)